mirror of
https://github.com/openziti/zrok.git
synced 2025-06-21 10:17:51 +02:00
get zids from local identity configs (#131)
This commit is contained in:
parent
e0a734be2e
commit
d238809481
@ -4,9 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/openziti-test-kitchen/zrok/model"
|
||||
"github.com/openziti-test-kitchen/zrok/zrokdir"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
"github.com/openziti/edge/rest_management_api_client/config"
|
||||
"github.com/openziti/edge/rest_model"
|
||||
"github.com/openziti/sdk-golang/ziti"
|
||||
config2 "github.com/openziti/sdk-golang/ziti/config"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
@ -15,6 +18,18 @@ import (
|
||||
func Bootstrap(inCfg *Config) error {
|
||||
cfg = inCfg
|
||||
|
||||
if ctrlZId, err := getIdentityId("ctrl"); err == nil {
|
||||
logrus.Infof("controller identity: %v", ctrlZId)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
if frontendZId, err := getIdentityId("frontend"); err == nil {
|
||||
logrus.Infof("frontend identity: %v", frontendZId)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
edge, err := edgeClient()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -59,3 +74,20 @@ func assertZrokProxyConfigType(edge *rest_management_api_client.ZitiEdgeManageme
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func getIdentityId(identityName string) (string, error) {
|
||||
zif, err := zrokdir.ZitiIdentityFile(identityName)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "error opening identity '%v' from zrokdir: %v", identityName)
|
||||
}
|
||||
zcfg, err := config2.NewFromFile(zif)
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "error loading ziti config from file '%v': %v", zif)
|
||||
}
|
||||
zctx := ziti.NewContextWithConfig(zcfg)
|
||||
id, err := zctx.GetCurrentIdentity()
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, "error getting current identity from '%v': %v", zif)
|
||||
}
|
||||
return id.Id, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user