zrok/controller/sharePrivate.go

41 lines
1.3 KiB
Go
Raw Normal View History

2022-11-22 21:31:02 +01:00
package controller
import (
2023-05-25 17:50:38 +02:00
"github.com/openziti/edge-api/rest_management_api_client"
"github.com/openziti/zrok/controller/zrokEdgeSdk"
"github.com/openziti/zrok/rest_server_zrok/operations/share"
"github.com/openziti/zrok/sdk"
2022-11-22 21:31:02 +01:00
)
type privateResourceAllocator struct{}
func newPrivateResourceAllocator() *privateResourceAllocator {
return &privateResourceAllocator{}
}
2023-01-04 20:42:58 +01:00
func (a *privateResourceAllocator) allocate(envZId, shrToken string, params share.ShareParams, edge *rest_management_api_client.ZitiEdgeManagement) (shrZId string, frontendEndpoints []string, err error) {
var authUsers []*sdk.AuthUser
2022-11-22 21:31:02 +01:00
for _, authUser := range params.Body.AuthUsers {
authUsers = append(authUsers, &sdk.AuthUser{authUser.Username, authUser.Password})
2022-11-22 21:31:02 +01:00
}
2023-01-04 20:21:23 +01:00
cfgZId, err := zrokEdgeSdk.CreateConfig(zrokProxyConfigId, envZId, shrToken, params.Body.AuthScheme, authUsers, edge)
2022-11-22 21:31:02 +01:00
if err != nil {
return "", nil, err
}
2023-01-04 20:42:58 +01:00
shrZId, err = zrokEdgeSdk.CreateShareService(envZId, shrToken, cfgZId, edge)
2022-11-22 21:31:02 +01:00
if err != nil {
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.CreateShareServiceEdgeRouterPolicy(envZId, shrToken, shrZId, edge); err != nil {
2022-11-22 21:31:02 +01:00
return "", nil, err
}
2023-01-04 20:42:58 +01:00
return shrZId, nil, nil
2022-11-22 21:31:02 +01:00
}