zrok/controller/share_public.go
2022-12-05 16:48:59 -05:00

44 lines
1.3 KiB
Go

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"
)
type publicResourceAllocator struct{}
func newPublicResourceAllocator() *publicResourceAllocator {
return &publicResourceAllocator{}
}
func (a *publicResourceAllocator) allocate(envZId, svcToken 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})
}
cfgId, err := createConfig(envZId, svcToken, params.Body.AuthScheme, authUsers, edge)
if err != nil {
return "", nil, err
}
svcZId, err = createShareService(envZId, svcToken, cfgId, edge)
if err != nil {
return "", nil, err
}
if err := createServicePolicyBind(envZId, svcToken, svcZId, edge); err != nil {
return "", nil, err
}
if err := createServicePolicyDial(envZId, svcToken, svcZId, edge); err != nil {
return "", nil, err
}
if err := createShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId, edge); err != nil {
return "", nil, err
}
return svcZId, []string{proxyUrl(svcToken)}, nil
}