zrok/controller/startup.go

61 lines
1.5 KiB
Go
Raw Normal View History

2022-08-15 20:25:50 +02:00
package controller
import (
"context"
2022-08-15 23:29:31 +02:00
"fmt"
2023-05-25 17:50:38 +02:00
"github.com/openziti/edge-api/rest_management_api_client"
"github.com/openziti/edge-api/rest_management_api_client/config"
2023-03-07 20:31:39 +01:00
"github.com/openziti/zrok/controller/zrokEdgeSdk"
"github.com/openziti/zrok/sdk"
2022-08-15 20:25:50 +02:00
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
2023-05-25 20:59:39 +02:00
"time"
2022-08-15 20:25:50 +02:00
)
2022-08-15 23:29:31 +02:00
var zrokProxyConfigId string
2022-08-15 21:06:57 +02:00
func controllerStartup() error {
if err := inspectZiti(); err != nil {
2022-08-15 20:25:50 +02:00
return err
}
return nil
}
func inspectZiti() error {
2022-08-15 20:25:50 +02:00
logrus.Infof("inspecting ziti controller configuration")
2023-03-07 20:31:39 +01:00
edge, err := zrokEdgeSdk.Client(cfg.Ziti)
2022-08-15 20:25:50 +02:00
if err != nil {
return errors.Wrap(err, "error getting ziti edge client")
}
2022-12-05 19:12:12 +01:00
if err := findZrokProxyConfigType(edge); err != nil {
2022-08-15 20:25:50 +02:00
return err
}
return nil
}
2022-12-05 19:12:12 +01:00
func findZrokProxyConfigType(edge *rest_management_api_client.ZitiEdgeManagement) error {
filter := fmt.Sprintf("name=\"%v\"", sdk.ZrokProxyConfig)
2022-08-15 20:25:50 +02:00
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
}
2022-12-05 19:12:12 +01:00
if len(listResp.Payload.Data) != 1 {
return errors.Errorf("expected 1 zrok proxy config type, found %d", len(listResp.Payload.Data))
}
logrus.Infof("found '%v' config type with id '%v'", sdk.ZrokProxyConfig, *(listResp.Payload.Data[0].ID))
2022-12-05 19:12:12 +01:00
zrokProxyConfigId = *(listResp.Payload.Data[0].ID)
2022-08-15 20:25:50 +02:00
return nil
}