231 lines
6.3 KiB
Go
231 lines
6.3 KiB
Go
package routes
|
|
|
|
import (
|
|
"isp-system-service/controller"
|
|
"isp-system-service/docs"
|
|
|
|
"github.com/txix-open/isp-kit/cluster"
|
|
"github.com/txix-open/isp-kit/common_endpoints"
|
|
"github.com/txix-open/isp-kit/grpc"
|
|
"github.com/txix-open/isp-kit/grpc/endpoint"
|
|
)
|
|
|
|
type Controllers struct {
|
|
AccessList controller.AccessList
|
|
Application controller.Application
|
|
AppGroup controller.AppGroup
|
|
Token controller.Token
|
|
Secure controller.Secure
|
|
}
|
|
|
|
func EndpointDescriptors() []cluster.EndpointDescriptor {
|
|
return endpointDescriptors(Controllers{})
|
|
}
|
|
|
|
func Handler(wrapper endpoint.Wrapper, c Controllers) *grpc.Mux {
|
|
muxer := grpc.NewMux()
|
|
for _, descriptor := range endpointDescriptors(c) {
|
|
muxer.Handle(descriptor.Path, wrapper.Endpoint(descriptor.Handler))
|
|
}
|
|
return muxer
|
|
}
|
|
|
|
func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
|
return concatEndpoints(
|
|
secureCluster(c),
|
|
accessListCluster(c),
|
|
applicationCluster(c),
|
|
tokenCluster(c),
|
|
applicationGroupCluster(c),
|
|
commonEndpoints(),
|
|
)
|
|
}
|
|
|
|
func secureCluster(c Controllers) []cluster.EndpointDescriptor {
|
|
return []cluster.EndpointDescriptor{
|
|
{
|
|
Path: "system/secure/authenticate",
|
|
Inner: true,
|
|
Handler: c.Secure.Authenticate,
|
|
},
|
|
{
|
|
Path: "system/secure/authorize",
|
|
Inner: true,
|
|
Handler: c.Secure.Authorize,
|
|
},
|
|
}
|
|
}
|
|
|
|
func accessListCluster(c Controllers) []cluster.EndpointDescriptor {
|
|
return []cluster.EndpointDescriptor{
|
|
{
|
|
Path: "system/access_list/get_by_id",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("app_access_view"),
|
|
Handler: c.AccessList.GetById,
|
|
},
|
|
{
|
|
Path: "system/access_list/set_one",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("app_access_edit"),
|
|
Handler: c.AccessList.SetOne,
|
|
},
|
|
{
|
|
Path: "system/access_list/set_list",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("app_access_edit"),
|
|
Handler: c.AccessList.SetList,
|
|
},
|
|
{
|
|
Path: "system/access_list/delete_list",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("app_access_edit"),
|
|
Handler: c.AccessList.DeleteList,
|
|
},
|
|
{
|
|
Path: "system/access_list/delete_list_with_methods",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("app_access_edit"),
|
|
Handler: c.AccessList.DeleteListWithMethods,
|
|
},
|
|
}
|
|
}
|
|
|
|
func applicationCluster(c Controllers) []cluster.EndpointDescriptor {
|
|
return []cluster.EndpointDescriptor{
|
|
{
|
|
Path: "system/application/get_applications",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_view"),
|
|
Handler: c.Application.GetByIdList,
|
|
},
|
|
{
|
|
Path: "system/application/get_by_app_group",
|
|
Extra: cluster.RequireAdminPermission("application_group_view"),
|
|
Inner: true,
|
|
Handler: c.Application.GetByAppGroup,
|
|
},
|
|
{
|
|
Path: "system/application/create_update_application",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_app_edit"),
|
|
Handler: c.Application.CreateUpdate,
|
|
},
|
|
{
|
|
Path: "system/application/get_application_by_id",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_view"),
|
|
Handler: c.Application.GetById,
|
|
},
|
|
{
|
|
Path: "system/application/get_application_by_token",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_view"),
|
|
Handler: c.Application.GetByToken,
|
|
},
|
|
{
|
|
Path: "system/application/delete_applications",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_app_delete"),
|
|
Handler: c.Application.Delete,
|
|
},
|
|
{
|
|
Path: "system/application/next_id",
|
|
Inner: true,
|
|
Handler: c.Application.NextId,
|
|
},
|
|
{
|
|
Path: "system/application/get_all",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_view"),
|
|
Handler: c.Application.GetAll,
|
|
},
|
|
{
|
|
Path: "system/application/create_application",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_app_add"),
|
|
Handler: c.Application.Create,
|
|
}, {
|
|
Path: "system/application/update_application",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_app_edit"),
|
|
Handler: c.Application.Update,
|
|
},
|
|
}
|
|
}
|
|
|
|
func tokenCluster(c Controllers) []cluster.EndpointDescriptor {
|
|
return []cluster.EndpointDescriptor{
|
|
{
|
|
Path: "system/token/create_token",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_token_add"),
|
|
Handler: c.Token.Create,
|
|
},
|
|
{
|
|
Path: "system/token/revoke_tokens",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_token_delete"),
|
|
Handler: c.Token.Revoke,
|
|
},
|
|
{
|
|
Path: "system/token/revoke_tokens_for_app",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_token_delete"),
|
|
Handler: c.Token.RevokeForApp,
|
|
},
|
|
{
|
|
Path: "system/token/get_tokens_by_app_id",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_token_view"),
|
|
Handler: c.Token.GetByAppId,
|
|
},
|
|
}
|
|
}
|
|
|
|
func applicationGroupCluster(c Controllers) []cluster.EndpointDescriptor {
|
|
return []cluster.EndpointDescriptor{
|
|
{
|
|
Path: "system/application_group/create",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_add"),
|
|
Handler: c.AppGroup.Create,
|
|
}, {
|
|
Path: "system/application_group/update",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_edit"),
|
|
Handler: c.AppGroup.Update,
|
|
}, {
|
|
Path: "system/application_group/delete_list",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_delete"),
|
|
Handler: c.AppGroup.DeleteList,
|
|
}, {
|
|
Path: "system/application_group/get_by_id_list",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_view"),
|
|
Handler: c.AppGroup.GetByIdList,
|
|
}, {
|
|
Path: "system/application_group/get_all",
|
|
Inner: true,
|
|
Extra: cluster.RequireAdminPermission("application_group_view"),
|
|
Handler: c.AppGroup.GetAll,
|
|
},
|
|
}
|
|
}
|
|
|
|
func commonEndpoints() []cluster.EndpointDescriptor {
|
|
return common_endpoints.CommonEndpoints(
|
|
"system",
|
|
common_endpoints.WithSwaggerEndpoint(docs.SwaggerJson),
|
|
)
|
|
}
|
|
|
|
func concatEndpoints(endpoints ...[]cluster.EndpointDescriptor) []cluster.EndpointDescriptor {
|
|
var result []cluster.EndpointDescriptor
|
|
for _, c := range endpoints {
|
|
result = append(result, c...)
|
|
}
|
|
return result
|
|
}
|