mirror of
https://github.com/hanzozt/zt.git
synced 2026-10-30 15:04:55 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
110 lines
5.3 KiB
Go
110 lines
5.3 KiB
Go
/*
|
|
Copyright NetFoundry Inc.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package routes
|
|
|
|
import (
|
|
"github.com/go-openapi/runtime/middleware"
|
|
"github.com/go-openapi/strfmt"
|
|
"github.com/hanzozt/edge-api/rest_management_api_server/operations/auth_policy"
|
|
"github.com/hanzozt/foundation/v2/errorz"
|
|
"github.com/hanzozt/zt/v2/controller/env"
|
|
"github.com/hanzozt/zt/v2/controller/fields"
|
|
"github.com/hanzozt/zt/v2/controller/model"
|
|
"github.com/hanzozt/zt/v2/controller/permissions"
|
|
"github.com/hanzozt/zt/v2/controller/response"
|
|
)
|
|
|
|
func init() {
|
|
r := NewAuthPolicyRouter()
|
|
env.AddRouter(r)
|
|
}
|
|
|
|
type AuthPolicyRouter struct {
|
|
BasePath string
|
|
}
|
|
|
|
func NewAuthPolicyRouter() *AuthPolicyRouter {
|
|
return &AuthPolicyRouter{
|
|
BasePath: "/" + EntityNameAuthPolicy,
|
|
}
|
|
}
|
|
|
|
func (r *AuthPolicyRouter) Register(ae *env.AppEnv) {
|
|
ae.ManagementApi.AuthPolicyDeleteAuthPolicyHandler = auth_policy.DeleteAuthPolicyHandlerFunc(func(params auth_policy.DeleteAuthPolicyParams, _ interface{}) middleware.Responder {
|
|
ae.InitPermissionsContext(params.HTTPRequest, permissions.Management, "auth-policy", permissions.Delete)
|
|
return ae.IsAllowed(r.Delete, params.HTTPRequest, params.ID, "", permissions.DefaultManagementAccess())
|
|
})
|
|
|
|
ae.ManagementApi.AuthPolicyDetailAuthPolicyHandler = auth_policy.DetailAuthPolicyHandlerFunc(func(params auth_policy.DetailAuthPolicyParams, _ interface{}) middleware.Responder {
|
|
ae.InitPermissionsContext(params.HTTPRequest, permissions.Management, "auth-policy", permissions.Read)
|
|
return ae.IsAllowed(r.Detail, params.HTTPRequest, params.ID, "", permissions.DefaultManagementAccess())
|
|
})
|
|
|
|
ae.ManagementApi.AuthPolicyListAuthPoliciesHandler = auth_policy.ListAuthPoliciesHandlerFunc(func(params auth_policy.ListAuthPoliciesParams, _ interface{}) middleware.Responder {
|
|
ae.InitPermissionsContext(params.HTTPRequest, permissions.Management, "auth-policy", permissions.Read)
|
|
return ae.IsAllowed(r.List, params.HTTPRequest, "", "", permissions.DefaultManagementAccess())
|
|
})
|
|
|
|
ae.ManagementApi.AuthPolicyUpdateAuthPolicyHandler = auth_policy.UpdateAuthPolicyHandlerFunc(func(params auth_policy.UpdateAuthPolicyParams, _ interface{}) middleware.Responder {
|
|
ae.InitPermissionsContext(params.HTTPRequest, permissions.Management, "auth-policy", permissions.Update)
|
|
return ae.IsAllowed(func(ae *env.AppEnv, rc *response.RequestContext) { r.Update(ae, rc, params) }, params.HTTPRequest, params.ID, "", permissions.DefaultManagementAccess())
|
|
})
|
|
|
|
ae.ManagementApi.AuthPolicyCreateAuthPolicyHandler = auth_policy.CreateAuthPolicyHandlerFunc(func(params auth_policy.CreateAuthPolicyParams, _ interface{}) middleware.Responder {
|
|
ae.InitPermissionsContext(params.HTTPRequest, permissions.Management, "auth-policy", permissions.Create)
|
|
return ae.IsAllowed(func(ae *env.AppEnv, rc *response.RequestContext) { r.Create(ae, rc, params) }, params.HTTPRequest, "", "", permissions.DefaultManagementAccess())
|
|
})
|
|
|
|
ae.ManagementApi.AuthPolicyPatchAuthPolicyHandler = auth_policy.PatchAuthPolicyHandlerFunc(func(params auth_policy.PatchAuthPolicyParams, _ interface{}) middleware.Responder {
|
|
ae.InitPermissionsContext(params.HTTPRequest, permissions.Management, "auth-policy", permissions.Update)
|
|
return ae.IsAllowed(func(ae *env.AppEnv, rc *response.RequestContext) { r.Patch(ae, rc, params) }, params.HTTPRequest, params.ID, "", permissions.DefaultManagementAccess())
|
|
})
|
|
}
|
|
|
|
func (r *AuthPolicyRouter) List(ae *env.AppEnv, rc *response.RequestContext) {
|
|
ListWithHandler[*model.AuthPolicy](ae, rc, ae.Managers.AuthPolicy, MapAuthPolicyToRestEntity)
|
|
}
|
|
|
|
func (r *AuthPolicyRouter) Detail(ae *env.AppEnv, rc *response.RequestContext) {
|
|
DetailWithHandler[*model.AuthPolicy](ae, rc, ae.Managers.AuthPolicy, MapAuthPolicyToRestEntity)
|
|
}
|
|
|
|
func (r *AuthPolicyRouter) Create(ae *env.AppEnv, rc *response.RequestContext, params auth_policy.CreateAuthPolicyParams) {
|
|
Create(rc, rc, AuthPolicyLinkFactory, func() (string, error) {
|
|
return MapCreate(ae.Managers.AuthPolicy.Create, MapCreateAuthPolicyToModel(params.AuthPolicy), rc)
|
|
})
|
|
}
|
|
|
|
func (r *AuthPolicyRouter) Delete(ae *env.AppEnv, rc *response.RequestContext) {
|
|
DeleteWithHandler(rc, ae.Managers.AuthPolicy)
|
|
}
|
|
|
|
func (r *AuthPolicyRouter) Update(ae *env.AppEnv, rc *response.RequestContext, params auth_policy.UpdateAuthPolicyParams) {
|
|
Update(rc, func(id string) error {
|
|
if err := params.AuthPolicy.AuthPolicyCreate.Validate(strfmt.Default); err != nil {
|
|
return errorz.NewCouldNotValidate(err)
|
|
}
|
|
return ae.Managers.AuthPolicy.Update(MapUpdateAuthPolicyToModel(params.ID, params.AuthPolicy), nil, rc.NewChangeContext())
|
|
})
|
|
}
|
|
|
|
func (r *AuthPolicyRouter) Patch(ae *env.AppEnv, rc *response.RequestContext, params auth_policy.PatchAuthPolicyParams) {
|
|
Patch(rc, func(id string, fields fields.UpdatedFields) error {
|
|
return ae.Managers.AuthPolicy.Update(MapPatchAuthPolicyToModel(params.ID, params.AuthPolicy), fields.FilterMaps("tags"), rc.NewChangeContext())
|
|
})
|
|
}
|