mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 16:13:47 +01:00
rough in controller proxy auth config building (#12)
This commit is contained in:
parent
cb3fef21d4
commit
c6c1a470d3
@ -67,7 +67,7 @@ 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()))
|
||||||
}
|
}
|
||||||
cfgId, err := self.createConfig(svcName, edge)
|
cfgId, err := self.createConfig(svcName, params, 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()))
|
||||||
@ -117,8 +117,20 @@ 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, params tunnel.TunnelParams, edge *rest_management_api_client.ZitiEdgeManagement) (cfgID string, err error) {
|
||||||
cfg := &model.ProxyConfig{AuthScheme: model.None}
|
authScheme, err := model.ParseAuthScheme(params.Body.AuthScheme)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
cfg := &model.ProxyConfig{
|
||||||
|
AuthScheme: authScheme,
|
||||||
|
}
|
||||||
|
if cfg.AuthScheme == model.Basic {
|
||||||
|
cfg.BasicAuth = &model.BasicAuth{}
|
||||||
|
for _, authUser := range params.Body.AuthUsers {
|
||||||
|
cfg.BasicAuth.Users = append(cfg.BasicAuth.Users, &model.AuthUser{Username: authUser.Username, Password: authUser.Password})
|
||||||
|
}
|
||||||
|
}
|
||||||
cfgCrt := &rest_model.ConfigCreate{
|
cfgCrt := &rest_model.ConfigCreate{
|
||||||
ConfigTypeID: &zrokProxyConfigId,
|
ConfigTypeID: &zrokProxyConfigId,
|
||||||
Data: cfg,
|
Data: cfg,
|
||||||
|
@ -1,17 +1,19 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
|
import "github.com/pkg/errors"
|
||||||
|
|
||||||
const ZrokProxyConfig = "zrok.proxy.v1"
|
const ZrokProxyConfig = "zrok.proxy.v1"
|
||||||
|
|
||||||
type AuthScheme string
|
type AuthScheme string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
None AuthScheme = "none"
|
None AuthScheme = "none"
|
||||||
Basic = "basic"
|
Basic AuthScheme = "basic"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProxyConfig struct {
|
type ProxyConfig struct {
|
||||||
AuthScheme AuthScheme `json:"auth_scheme"`
|
AuthScheme AuthScheme `json:"auth_scheme"`
|
||||||
BasicAuth BasicAuth `json:"basic_auth"`
|
BasicAuth *BasicAuth `json:"basic_auth"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BasicAuth struct {
|
type BasicAuth struct {
|
||||||
@ -22,3 +24,14 @@ type AuthUser struct {
|
|||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseAuthScheme(authScheme string) (AuthScheme, error) {
|
||||||
|
switch authScheme {
|
||||||
|
case string(None):
|
||||||
|
return None, nil
|
||||||
|
case string(Basic):
|
||||||
|
return Basic, nil
|
||||||
|
default:
|
||||||
|
return None, errors.Errorf("unknown auth scheme '%v'", authScheme)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user