mirror of
https://github.com/openziti/zrok.git
synced 2025-02-02 03:20:26 +01:00
controller startup/setup (#12)
This commit is contained in:
parent
1f36af7cf5
commit
6652163d75
@ -29,6 +29,10 @@ func Run(cfg *Config) error {
|
||||
api.TunnelTunnelHandler = newTunnelHandler(cfg)
|
||||
api.TunnelUntunnelHandler = newUntunnelHandler(cfg)
|
||||
|
||||
if err := controllerStartup(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if v, err := store.Open(cfg.Store); err == nil {
|
||||
str = v
|
||||
} else {
|
||||
|
50
controller/startup.go
Normal file
50
controller/startup.go
Normal file
@ -0,0 +1,50 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/openziti/edge/rest_management_api_client"
|
||||
"github.com/openziti/edge/rest_management_api_client/config"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"time"
|
||||
)
|
||||
|
||||
func controllerStartup(cfg *Config) error {
|
||||
if err := inspectZiti(cfg); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func inspectZiti(cfg *Config) error {
|
||||
logrus.Infof("inspecting ziti controller configuration")
|
||||
|
||||
edge, err := edgeClient(cfg.Ziti)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error getting ziti edge client")
|
||||
}
|
||||
if err := ensureZrokAuthConfigType(edge); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func ensureZrokAuthConfigType(edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||
filter := "name=\"zrok.auth.v1\""
|
||||
limit := int64(100)
|
||||
offset := int64(0)
|
||||
listReq := &config.ListConfigTypesParams{
|
||||
Filter: &filter,
|
||||
Limit: &limit,
|
||||
Offset: &offset,
|
||||
Context: context.Background(),
|
||||
}
|
||||
listReq.SetTimeout(30 * time.Second)
|
||||
listResp, err := edge.Config.ListConfigTypes(listReq, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
logrus.Infof("found %d zrok.auth.v1 config types", len(listResp.Payload.Data))
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user