mirror of
https://github.com/openziti/zrok.git
synced 2025-08-14 18:18:30 +02:00
api improvements
This commit is contained in:
39
controller/util.go
Normal file
39
controller/util.go
Normal file
@ -0,0 +1,39 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"crypto/x509"
|
||||
"encoding/hex"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
"github.com/openziti/edge/rest_util"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func edgeClient() (*rest_management_api_client.ZitiEdgeManagement, error) {
|
||||
ctrlAddress := "https://linux:1280"
|
||||
caCerts, err := rest_util.GetControllerWellKnownCas(ctrlAddress)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
caPool := x509.NewCertPool()
|
||||
for _, ca := range caCerts {
|
||||
caPool.AddCert(ca)
|
||||
}
|
||||
return rest_util.NewEdgeManagementClientWithUpdb("admin", "admin", ctrlAddress, caPool)
|
||||
}
|
||||
|
||||
func generateApiToken() (string, error) {
|
||||
bytes := make([]byte, 64)
|
||||
if _, err := rand.Read(bytes); err != nil {
|
||||
return "", errors.Wrap(err, "error generating random api token")
|
||||
}
|
||||
return hex.EncodeToString(bytes), nil
|
||||
}
|
||||
|
||||
func randomId() (string, error) {
|
||||
bytes := make([]byte, 8)
|
||||
if _, err := rand.Read(bytes); err != nil {
|
||||
return "", errors.Wrap(err, "error generating random identity id")
|
||||
}
|
||||
return hex.EncodeToString(bytes), nil
|
||||
}
|
Reference in New Issue
Block a user