MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / MyAPIKeysByService

Method MyAPIKeysByService

module/system-apikey/iml.go:84–159  ·  view source on GitHub ↗
(ctx context.Context, serviceId string)

Source from the content-addressed store, hash-verified

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)
86 if err != nil {
87 return nil, err
88 }
89 if len(list) < 1 {
90 return nil, fmt.Errorf("no subscriber found")
91 }
92 appMap := utils.SliceToMapO(list, func(a *subscribe.Subscribe) (string, struct{}) {
93 return a.Application, struct{}{}
94 })
95 members, err := i.teamMemberService.Members(ctx, nil, nil)
96 if err != nil {
97 return nil, err
98 }
99 if len(members) == 0 {
100 return nil, nil
101 }
102 teamIds := utils.SliceToSlice(members, func(m *team_member.Member) string {
103 return m.Come
104 })
105 apps, err := i.serviceService.AppListByTeam(ctx, teamIds...)
106 if err != nil {
107 return nil, err
108 }
109 appInfoMap := make(map[string]*service.Service)
110 appIds := make([]string, 0, len(apps))
111 for _, a := range apps {
112 if _, ok := appMap[a.Id]; !ok {
113 continue
114 }
115 appInfoMap[a.Id] = a
116 appIds = append(appIds, a.Id)
117 }
118
119 if len(appIds) < 1 {
120 return nil, fmt.Errorf("no app found")
121 }
122 auths, err := i.applicationAuthorizationService.ListByApp(ctx, appIds...)
123 if err != nil {
124 return nil, err
125 }
126 result := make(map[string]*system_apikey_dto.AuthorizationItem)
127 for _, a := range auths {
128 if a.Type != "apikey" {
129 continue
130 }
131
132 appInfo, ok := appInfoMap[a.Application]
133 if !ok {
134 continue
135 }
136 m := make(map[string]string)
137 json.Unmarshal([]byte(a.Config), &m)
138 if m["apikey"] == "" {
139 continue
140 }
141 if _, ok := result[appInfo.Id]; !ok {

Callers

nothing calls this directly

Calls 4

ListBySubscribeStatusMethod · 0.65
MembersMethod · 0.65
AppListByTeamMethod · 0.65
ListByAppMethod · 0.65

Tested by

no test coverage detected