create config (#12)

This commit is contained in:
Michael Quigley 2022-08-15 15:06:57 -04:00
parent 9f71367d40
commit 6fcd952d68
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
3 changed files with 40 additions and 3 deletions

View File

@ -10,6 +10,8 @@ import (
"time" "time"
) )
var zrokAuthV1Id string
func controllerStartup(cfg *Config) error { func controllerStartup(cfg *Config) error {
if err := inspectZiti(cfg); err != nil { if err := inspectZiti(cfg); err != nil {
return err return err
@ -56,10 +58,12 @@ func ensureZrokAuthConfigType(edge *rest_management_api_client.ZitiEdgeManagemen
return err return err
} }
logrus.Infof("created 'zrok.auth.v1' config type with id '%v'", createResp.Payload.Data.ID) logrus.Infof("created 'zrok.auth.v1' config type with id '%v'", createResp.Payload.Data.ID)
zrokAuthV1Id = createResp.Payload.Data.ID
} else if len(listResp.Payload.Data) > 1 { } 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)) return errors.Errorf("found %d 'zrok.auth.v1' config types; expected 0 or 1", len(listResp.Payload.Data))
} else { } else {
logrus.Infof("found 'zrok.auth.v1' config type with id '%v'", *(listResp.Payload.Data[0].ID)) logrus.Infof("found 'zrok.auth.v1' config type with id '%v'", *(listResp.Payload.Data[0].ID))
zrokAuthV1Id = *(listResp.Payload.Data[0].ID)
} }
return nil return nil
} }

View File

@ -5,9 +5,11 @@ import (
"fmt" "fmt"
"github.com/go-openapi/runtime/middleware" "github.com/go-openapi/runtime/middleware"
"github.com/openziti-test-kitchen/zrok/controller/store" "github.com/openziti-test-kitchen/zrok/controller/store"
"github.com/openziti-test-kitchen/zrok/model"
"github.com/openziti-test-kitchen/zrok/rest_model_zrok" "github.com/openziti-test-kitchen/zrok/rest_model_zrok"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/tunnel" "github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/tunnel"
"github.com/openziti/edge/rest_management_api_client" "github.com/openziti/edge/rest_management_api_client"
"github.com/openziti/edge/rest_management_api_client/config"
"github.com/openziti/edge/rest_management_api_client/edge_router_policy" "github.com/openziti/edge/rest_management_api_client/edge_router_policy"
"github.com/openziti/edge/rest_management_api_client/service" "github.com/openziti/edge/rest_management_api_client/service"
"github.com/openziti/edge/rest_management_api_client/service_edge_router_policy" "github.com/openziti/edge/rest_management_api_client/service_edge_router_policy"
@ -65,7 +67,12 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
logrus.Error(err) logrus.Error(err)
return tunnel.NewTunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error())) return tunnel.NewTunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
} }
svcId, err := self.createService(svcName, edge) cfgId, err := self.createConfig(edge)
if err != nil {
logrus.Error(err)
return tunnel.NewTunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
}
svcId, err := self.createService(svcName, cfgId, edge)
if err != nil { if err != nil {
logrus.Error(err) logrus.Error(err)
return tunnel.NewTunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error())) return tunnel.NewTunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
@ -110,8 +117,29 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
}) })
} }
func (self *tunnelHandler) createService(name string, edge *rest_management_api_client.ZitiEdgeManagement) (serviceId string, err error) { func (self *tunnelHandler) createConfig(edge *rest_management_api_client.ZitiEdgeManagement) (cfgID string, err error) {
configs := make([]string, 0) cfg := &model.ZrokAuth{Hello: "World"}
name := "zrok.auth.v1"
cfgCrt := &rest_model.ConfigCreate{
ConfigTypeID: &zrokAuthV1Id,
Data: cfg,
Name: &name,
}
cfgReq := &config.CreateConfigParams{
Config: cfgCrt,
Context: context.Background(),
}
cfgReq.SetTimeout(30 * time.Second)
cfgResp, err := edge.Config.CreateConfig(cfgReq, nil)
if err != nil {
return "", err
}
logrus.Infof("created config '%v'", cfgResp.Payload.Data.ID)
return cfgResp.Payload.Data.ID, nil
}
func (self *tunnelHandler) createService(name, cfgId string, edge *rest_management_api_client.ZitiEdgeManagement) (serviceId string, err error) {
configs := []string{cfgId}
encryptionRequired := true encryptionRequired := true
svc := &rest_model.ServiceCreate{ svc := &rest_model.ServiceCreate{
Configs: configs, Configs: configs,

5
model/ZrokAuth.go Normal file
View File

@ -0,0 +1,5 @@
package model
type ZrokAuth struct {
Hello string
}