zrok/controller/sharePublic.go

49 lines
1.8 KiB
Go
Raw Normal View History

package controller
import (
2022-12-14 20:40:45 +01:00
"github.com/openziti-test-kitchen/zrok/controller/zrokEdgeSdk"
"github.com/openziti-test-kitchen/zrok/model"
"github.com/openziti-test-kitchen/zrok/rest_server_zrok/operations/share"
"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{}
}
2023-01-04 20:42:58 +01:00
func (a *publicResourceAllocator) allocate(envZId, shrToken string, frontendZIds, frontendTemplates []string, params share.ShareParams, edge *rest_management_api_client.ZitiEdgeManagement) (shrZId 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})
}
2023-01-04 20:42:58 +01:00
cfgId, err := zrokEdgeSdk.CreateConfig(zrokProxyConfigId, envZId, shrToken, params.Body.AuthScheme, authUsers, edge)
if err != nil {
2022-11-22 21:31:02 +01:00
return "", nil, err
}
2023-01-04 20:42:58 +01:00
shrZId, err = zrokEdgeSdk.CreateShareService(envZId, shrToken, cfgId, edge)
if err != nil {
2022-11-22 21:31:02 +01:00
return "", nil, err
}
2023-01-04 20:42:58 +01:00
if err := zrokEdgeSdk.CreateServicePolicyBind(envZId+"-"+shrZId+"-bind", shrZId, envZId, zrokEdgeSdk.ZrokShareTags(shrToken).SubTags, edge); err != nil {
2022-11-22 21:31:02 +01:00
return "", nil, err
}
2023-01-04 20:42:58 +01:00
if err := zrokEdgeSdk.CreateServicePolicyDial(envZId+"-"+shrZId+"-dial", shrZId, frontendZIds, zrokEdgeSdk.ZrokShareTags(shrToken).SubTags, edge); err != nil {
2022-11-22 21:31:02 +01:00
return "", nil, err
}
2023-01-04 20:42:58 +01:00
if err := zrokEdgeSdk.CreateShareServiceEdgeRouterPolicy(envZId, shrToken, shrZId, edge); err != nil {
2022-11-22 21:31:02 +01:00
return "", nil, err
}
for _, frontendTemplate := range frontendTemplates {
2023-01-04 20:42:58 +01:00
frontendEndpoints = append(frontendEndpoints, proxyUrl(shrToken, frontendTemplate))
}
2023-01-04 20:42:58 +01:00
return shrZId, frontendEndpoints, nil
}