zrok/controller/share_public.go

44 lines
1.3 KiB
Go
Raw Normal View History

package controller
import (
"github.com/openziti-test-kitchen/zrok/model"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/service"
"github.com/openziti/edge/rest_management_api_client"
)
2022-11-22 21:31:02 +01:00
type publicResourceAllocator struct{}
2022-11-22 17:35:25 +01:00
func newPublicResourceAllocator() *publicResourceAllocator {
return &publicResourceAllocator{}
}
2022-11-22 21:31:02 +01:00
func (a *publicResourceAllocator) allocate(envZId, svcName string, params service.ShareParams, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, frontendEndpoints []string, err error) {
var authUsers []*model.AuthUser
for _, authUser := range params.Body.AuthUsers {
authUsers = append(authUsers, &model.AuthUser{authUser.Username, authUser.Password})
}
2022-11-22 21:31:02 +01:00
cfgId, err := createConfig(envZId, svcName, params.Body.AuthScheme, authUsers, edge)
if err != nil {
2022-11-22 21:31:02 +01:00
return "", nil, err
}
2022-11-22 21:31:02 +01:00
svcZId, err = createService(envZId, svcName, cfgId, edge)
if err != nil {
2022-11-22 21:31:02 +01:00
return "", nil, err
}
2022-11-22 21:31:02 +01:00
if err := createServicePolicyBind(envZId, svcName, svcZId, edge); err != nil {
return "", nil, err
}
2022-11-22 21:31:02 +01:00
if err := createServicePolicyDial(envZId, svcName, svcZId, edge); err != nil {
return "", nil, err
}
2022-11-22 21:31:02 +01:00
if err := createServiceEdgeRouterPolicy(envZId, svcName, svcZId, edge); err != nil {
return "", nil, err
}
2022-11-22 21:31:02 +01:00
return svcZId, []string{proxyUrl(svcName)}, nil
}