| 42 | } |
| 43 | |
| 44 | func (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 | |
| 84 | func (i *imlAPIKeyModule) MyAPIKeysByService(ctx context.Context, serviceId string) ([]*system_apikey_dto.AuthorizationItem, error) { |
| 85 | list, err := i.subscribeService.ListBySubscribeStatus(ctx, serviceId, subscribe.ApplyStatusSubscribe) |