MCPcopy
hub / github.com/1Panel-dev/KubePi / apiResourceHandler

Function apiResourceHandler

internal/api/v1/v1.go:317–352  ·  view source on GitHub ↗
(party iris.Party)

Source from the content-addressed store, hash-verified

315}
316
317func apiResourceHandler(party iris.Party) iris.Handler {
318 return func(ctx *context.Context) {
319 //1. 确定所有的api资源有哪些
320 apiBuilder := party.(*router.APIBuilder)
321 routes := apiBuilder.GetRoutes()
322 resourceMap := map[string]*collections.StringSet{}
323 for i := range routes {
324 if strings.HasPrefix(routes[i].Path, "/kubepi/api/v1/") {
325 ss := strings.Split(routes[i].Path, "/")
326 if len(ss) >= 5 {
327 resourceName := ss[4]
328 //过滤session资源
329 if resourceWhiteList.In(resourceName) {
330 continue
331 }
332 if _, ok := resourceMap[resourceName]; !ok {
333 resourceMap[resourceName] = collections.NewStringSet()
334 }
335 resourceMap[resourceName].Add(getVerbByRoute(routes[i].Path, routes[i].Method))
336 }
337 }
338 }
339 displayMap := map[string][]string{}
340 for k := range resourceMap {
341 verbs := resourceMap[k]
342 if len(verbs.ToSlice()) > 0 {
343 displayMap[k] = verbs.ToSlice()
344 }
345 }
346 if ops, ok := displayMap["clusters"]; ok {
347 ops = append(ops, "authorization")
348 displayMap["clusters"] = ops
349 }
350 ctx.Values().Set("data", displayMap)
351 }
352}
353
354func roleAccessHandler() iris.Handler {
355 return func(ctx *context.Context) {

Callers 1

AddV1RouteFunction · 0.85

Calls 6

NewStringSetFunction · 0.92
getVerbByRouteFunction · 0.85
InMethod · 0.80
ToSliceMethod · 0.80
AddMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected