From 9f71367d40ab9fd2549c11dc7943cb8b7cab42cc Mon Sep 17 00:00:00 2001 From: Michael Quigley Date: Mon, 15 Aug 2022 14:36:17 -0400 Subject: [PATCH] ensure zrok.auth.v1 config type is present at controller startup --- controller/startup.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/controller/startup.go b/controller/startup.go index 58eb501a..a555d099 100644 --- a/controller/startup.go +++ b/controller/startup.go @@ -4,6 +4,7 @@ import ( "context" "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/pkg/errors" "github.com/sirupsen/logrus" "time" @@ -45,6 +46,20 @@ func ensureZrokAuthConfigType(edge *rest_management_api_client.ZitiEdgeManagemen if err != nil { return err } - logrus.Infof("found %d zrok.auth.v1 config types", len(listResp.Payload.Data)) + if len(listResp.Payload.Data) < 1 { + name := "zrok.auth.v1" + ct := &rest_model.ConfigTypeCreate{Name: &name} + createReq := &config.CreateConfigTypeParams{ConfigType: ct} + createReq.SetTimeout(30 * time.Second) + createResp, err := edge.Config.CreateConfigType(createReq, nil) + if err != nil { + return err + } + logrus.Infof("created 'zrok.auth.v1' config type with id '%v'", createResp.Payload.Data.ID) + } else if len(listResp.Payload.Data) > 1 { + return errors.Errorf("found %d 'zrok.auth.v1' config types; expected 0 or 1", len(listResp.Payload.Data)) + } else { + logrus.Infof("found 'zrok.auth.v1' config type with id '%v'", *(listResp.Payload.Data[0].ID)) + } return nil }