(ctx context.Context, req *schema.AddAPIKeyReq)
| 89 | } |
| 90 | |
| 91 | func (s *APIKeyService) AddAPIKey(ctx context.Context, req *schema.AddAPIKeyReq) (resp *schema.AddAPIKeyResp, err error) { |
| 92 | ak := "sk_" + strings.ReplaceAll(token.GenerateToken(), "-", "") |
| 93 | apiKey := entity.APIKey{ |
| 94 | Description: req.Description, |
| 95 | AccessKey: ak, |
| 96 | Scope: req.Scope, |
| 97 | LastUsedAt: time.Now(), |
| 98 | UserID: req.UserID, |
| 99 | } |
| 100 | err = s.apiKeyRepo.AddAPIKey(ctx, apiKey) |
| 101 | if err != nil { |
| 102 | return nil, err |
| 103 | } |
| 104 | resp = &schema.AddAPIKeyResp{ |
| 105 | AccessKey: apiKey.AccessKey, |
| 106 | } |
| 107 | return resp, nil |
| 108 | } |
| 109 | |
| 110 | func (s *APIKeyService) DeleteAPIKey(ctx context.Context, req *schema.DeleteAPIKeyReq) (err error) { |
| 111 | err = s.apiKeyRepo.DeleteAPIKey(ctx, req.ID) |
nothing calls this directly
no test coverage detected