mirror of
https://github.com/openziti/zrok.git
synced 2024-11-08 01:04:08 +01:00
40 lines
1.2 KiB
Go
40 lines
1.2 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 privateResourceAllocator struct{}
|
|
|
|
func newPrivateResourceAllocator() *privateResourceAllocator {
|
|
return &privateResourceAllocator{}
|
|
}
|
|
|
|
func (a *privateResourceAllocator) 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})
|
|
}
|
|
cfgId, err := createConfig(envZId, svcName, params.Body.AuthScheme, authUsers, edge)
|
|
if err != nil {
|
|
return "", nil, err
|
|
}
|
|
|
|
svcZId, err = createService(envZId, svcName, cfgId, edge)
|
|
if err != nil {
|
|
return "", nil, err
|
|
}
|
|
|
|
if err := createServicePolicyBind(envZId, svcName, svcZId, edge); err != nil {
|
|
return "", nil, err
|
|
}
|
|
|
|
if err := createServiceEdgeRouterPolicy(envZId, svcName, svcZId, edge); err != nil {
|
|
return "", nil, err
|
|
}
|
|
|
|
return svcZId, []string{proxyUrl(svcName)}, nil
|
|
}
|