mirror of
https://github.com/openziti/zrok.git
synced 2025-06-19 17:27:54 +02:00
zrok proxy config v1 (#12)
This commit is contained in:
parent
d8d3e77788
commit
cd3d7d81f4
@ -2,6 +2,8 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/model"
|
||||||
"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/config"
|
||||||
"github.com/openziti/edge/rest_model"
|
"github.com/openziti/edge/rest_model"
|
||||||
@ -10,7 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var zrokAuthV1Id string
|
var zrokProxyConfigId string
|
||||||
|
|
||||||
func controllerStartup(cfg *Config) error {
|
func controllerStartup(cfg *Config) error {
|
||||||
if err := inspectZiti(cfg); err != nil {
|
if err := inspectZiti(cfg); err != nil {
|
||||||
@ -26,15 +28,15 @@ func inspectZiti(cfg *Config) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error getting ziti edge client")
|
return errors.Wrap(err, "error getting ziti edge client")
|
||||||
}
|
}
|
||||||
if err := ensureZrokAuthConfigType(edge); err != nil {
|
if err := ensureZrokProxyConfigType(edge); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ensureZrokAuthConfigType(edge *rest_management_api_client.ZitiEdgeManagement) error {
|
func ensureZrokProxyConfigType(edge *rest_management_api_client.ZitiEdgeManagement) error {
|
||||||
filter := "name=\"zrok.auth.v1\""
|
filter := fmt.Sprintf("name=\"%v\"", model.ZrokProxyConfig)
|
||||||
limit := int64(100)
|
limit := int64(100)
|
||||||
offset := int64(0)
|
offset := int64(0)
|
||||||
listReq := &config.ListConfigTypesParams{
|
listReq := &config.ListConfigTypesParams{
|
||||||
@ -49,7 +51,7 @@ func ensureZrokAuthConfigType(edge *rest_management_api_client.ZitiEdgeManagemen
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(listResp.Payload.Data) < 1 {
|
if len(listResp.Payload.Data) < 1 {
|
||||||
name := "zrok.auth.v1"
|
name := model.ZrokProxyConfig
|
||||||
ct := &rest_model.ConfigTypeCreate{Name: &name}
|
ct := &rest_model.ConfigTypeCreate{Name: &name}
|
||||||
createReq := &config.CreateConfigTypeParams{ConfigType: ct}
|
createReq := &config.CreateConfigTypeParams{ConfigType: ct}
|
||||||
createReq.SetTimeout(30 * time.Second)
|
createReq.SetTimeout(30 * time.Second)
|
||||||
@ -57,13 +59,13 @@ func ensureZrokAuthConfigType(edge *rest_management_api_client.ZitiEdgeManagemen
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logrus.Infof("created 'zrok.auth.v1' config type with id '%v'", createResp.Payload.Data.ID)
|
logrus.Infof("created '%v' config type with id '%v'", model.ZrokProxyConfig, createResp.Payload.Data.ID)
|
||||||
zrokAuthV1Id = createResp.Payload.Data.ID
|
zrokProxyConfigId = 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 '%v' config types; expected 0 or 1", len(listResp.Payload.Data), model.ZrokProxyConfig)
|
||||||
} else {
|
} else {
|
||||||
logrus.Infof("found 'zrok.auth.v1' config type with id '%v'", *(listResp.Payload.Data[0].ID))
|
logrus.Infof("found '%v' config type with id '%v'", model.ZrokProxyConfig, *(listResp.Payload.Data[0].ID))
|
||||||
zrokAuthV1Id = *(listResp.Payload.Data[0].ID)
|
zrokProxyConfigId = *(listResp.Payload.Data[0].ID)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -118,9 +118,9 @@ func (self *tunnelHandler) Handle(params tunnel.TunnelParams, principal *rest_mo
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *tunnelHandler) createConfig(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) (cfgID string, err error) {
|
func (self *tunnelHandler) createConfig(svcName string, edge *rest_management_api_client.ZitiEdgeManagement) (cfgID string, err error) {
|
||||||
cfg := &model.ZrokAuth{Hello: "World"}
|
cfg := &model.ProxyConfig{AuthScheme: model.None}
|
||||||
cfgCrt := &rest_model.ConfigCreate{
|
cfgCrt := &rest_model.ConfigCreate{
|
||||||
ConfigTypeID: &zrokAuthV1Id,
|
ConfigTypeID: &zrokProxyConfigId,
|
||||||
Data: cfg,
|
Data: cfg,
|
||||||
Name: &svcName,
|
Name: &svcName,
|
||||||
}
|
}
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
type ZrokAuth struct {
|
|
||||||
Hello string
|
|
||||||
}
|
|
14
model/config.go
Normal file
14
model/config.go
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
const ZrokProxyConfig = "zrok.proxy.v1"
|
||||||
|
|
||||||
|
type AuthScheme string
|
||||||
|
|
||||||
|
const (
|
||||||
|
None AuthScheme = "none"
|
||||||
|
Basic = "basic"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProxyConfig struct {
|
||||||
|
AuthScheme AuthScheme `json:"auth_scheme"`
|
||||||
|
}
|
@ -3,6 +3,7 @@ package proxy
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/openziti-test-kitchen/zrok/model"
|
||||||
"github.com/openziti-test-kitchen/zrok/util"
|
"github.com/openziti-test-kitchen/zrok/util"
|
||||||
"github.com/openziti/sdk-golang/ziti"
|
"github.com/openziti/sdk-golang/ziti"
|
||||||
"github.com/openziti/sdk-golang/ziti/config"
|
"github.com/openziti/sdk-golang/ziti/config"
|
||||||
@ -25,7 +26,7 @@ func Run(cfg *Config) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error loading config")
|
return errors.Wrap(err, "error loading config")
|
||||||
}
|
}
|
||||||
zCfg.ConfigTypes = []string{"zrok.auth.v1"}
|
zCfg.ConfigTypes = []string{model.ZrokProxyConfig}
|
||||||
zCtx := ziti.NewContextWithConfig(zCfg)
|
zCtx := ziti.NewContextWithConfig(zCfg)
|
||||||
zDialCtx := ZitiDialContext{Context: zCtx}
|
zDialCtx := ZitiDialContext{Context: zCtx}
|
||||||
zTransport := http.DefaultTransport.(*http.Transport).Clone()
|
zTransport := http.DefaultTransport.(*http.Transport).Clone()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user