(ctx context.Context)
| 159 | } |
| 160 | |
| 161 | func (i *imlAPIKeyModule) MyAPIKeys(ctx context.Context) ([]*system_apikey_dto.SimpleItem, error) { |
| 162 | members, err := i.teamMemberService.Members(ctx, nil, nil) |
| 163 | if err != nil { |
| 164 | return nil, err |
| 165 | } |
| 166 | if len(members) == 0 { |
| 167 | return nil, nil |
| 168 | } |
| 169 | teamIds := utils.SliceToSlice(members, func(m *team_member.Member) string { |
| 170 | return m.Come |
| 171 | }) |
| 172 | apps, err := i.serviceService.AppListByTeam(ctx, teamIds...) |
| 173 | if err != nil { |
| 174 | return nil, err |
| 175 | } |
| 176 | appIds := utils.SliceToSlice(apps, func(a *service.Service) string { |
| 177 | return a.Id |
| 178 | }) |
| 179 | auths, err := i.applicationAuthorizationService.ListByApp(ctx, appIds...) |
| 180 | if err != nil { |
| 181 | return nil, err |
| 182 | } |
| 183 | result := make([]*system_apikey_dto.SimpleItem, 0, len(auths)) |
| 184 | for _, a := range auths { |
| 185 | if a.Type != "apikey" { |
| 186 | continue |
| 187 | } |
| 188 | m := make(map[string]string) |
| 189 | json.Unmarshal([]byte(a.Config), &m) |
| 190 | if m["apikey"] == "" { |
| 191 | continue |
| 192 | } |
| 193 | result = append(result, &system_apikey_dto.SimpleItem{ |
| 194 | Id: a.UUID, |
| 195 | Name: a.Name, |
| 196 | Value: m["apikey"], |
| 197 | Expired: a.ExpireTime, |
| 198 | }) |
| 199 | |
| 200 | } |
| 201 | return result, nil |
| 202 | |
| 203 | } |
| 204 | |
| 205 | func (i *imlAPIKeyModule) Create(ctx context.Context, input *system_apikey_dto.Create) error { |
| 206 | if input.Id == "" { |
nothing calls this directly
no test coverage detected