MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / MyAPIKeysByApp

Method MyAPIKeysByApp

module/system-apikey/iml.go:44–82  ·  view source on GitHub ↗
(ctx context.Context, appId string)

Source from the content-addressed store, hash-verified

42}
43
44func (i *imlAPIKeyModule) MyAPIKeysByApp(ctx context.Context, appId string) ([]*system_apikey_dto.AuthorizationItem, error) {
45 appInfo, err := i.serviceService.Get(ctx, appId)
46 if err != nil {
47 return nil, err
48 }
49 auths, err := i.applicationAuthorizationService.ListByApp(ctx, appId)
50 if err != nil {
51 return nil, err
52 }
53 result := make(map[string]*system_apikey_dto.AuthorizationItem)
54 for _, a := range auths {
55 if a.Type != "apikey" {
56 continue
57 }
58
59 m := make(map[string]string)
60 json.Unmarshal([]byte(a.Config), &m)
61 if m["apikey"] == "" {
62 continue
63 }
64 if _, ok := result[appInfo.Id]; !ok {
65 result[appInfo.Id] = &system_apikey_dto.AuthorizationItem{
66 Id: appInfo.Id,
67 Name: appInfo.Name,
68 Apikeys: []system_apikey_dto.SimpleItem{},
69 }
70 }
71 result[appInfo.Id].Apikeys = append(result[appInfo.Id].Apikeys, system_apikey_dto.SimpleItem{
72 Id: a.UUID,
73 Name: a.Name,
74 Value: m["apikey"],
75 Expired: a.ExpireTime,
76 })
77
78 }
79 return utils.MapToSlice(result, func(k string, t *system_apikey_dto.AuthorizationItem) *system_apikey_dto.AuthorizationItem {
80 return t
81 }), nil
82}
83
84func (i *imlAPIKeyModule) MyAPIKeysByService(ctx context.Context, serviceId string) ([]*system_apikey_dto.AuthorizationItem, error) {
85 list, err := i.subscribeService.ListBySubscribeStatus(ctx, serviceId, subscribe.ApplyStatusSubscribe)

Callers

nothing calls this directly

Calls 2

GetMethod · 0.65
ListByAppMethod · 0.65

Tested by

no test coverage detected