2022-11-22 21:31:02 +01:00
|
|
|
package controller
|
|
|
|
|
|
|
|
import (
|
2022-12-14 19:58:41 +01:00
|
|
|
"github.com/openziti-test-kitchen/zrok/controller/zrok_edge_sdk"
|
2022-11-22 21:31:02 +01:00
|
|
|
"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{}
|
|
|
|
}
|
|
|
|
|
2022-11-30 18:10:00 +01:00
|
|
|
func (a *privateResourceAllocator) allocate(envZId, svcToken string, params service.ShareParams, edge *rest_management_api_client.ZitiEdgeManagement) (svcZId string, frontendEndpoints []string, err error) {
|
2022-11-22 21:31:02 +01:00
|
|
|
var authUsers []*model.AuthUser
|
|
|
|
for _, authUser := range params.Body.AuthUsers {
|
|
|
|
authUsers = append(authUsers, &model.AuthUser{authUser.Username, authUser.Password})
|
|
|
|
}
|
2022-11-30 18:10:00 +01:00
|
|
|
cfgId, err := createConfig(envZId, svcToken, params.Body.AuthScheme, authUsers, edge)
|
2022-11-22 21:31:02 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
|
2022-12-05 22:10:38 +01:00
|
|
|
svcZId, err = createShareService(envZId, svcToken, cfgId, edge)
|
2022-11-22 21:31:02 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
|
2022-11-30 18:10:00 +01:00
|
|
|
if err := createServicePolicyBind(envZId, svcToken, svcZId, edge); err != nil {
|
2022-11-22 21:31:02 +01:00
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
|
2022-12-14 19:58:41 +01:00
|
|
|
if err := zrok_edge_sdk.CreateShareServiceEdgeRouterPolicy(envZId, svcToken, svcZId, edge); err != nil {
|
2022-11-22 21:31:02 +01:00
|
|
|
return "", nil, err
|
|
|
|
}
|
|
|
|
|
2022-12-06 17:48:59 +01:00
|
|
|
return svcZId, nil, nil
|
2022-11-22 21:31:02 +01:00
|
|
|
}
|