(ctx context.Context, eid, userID int64, role int64, name, description string, libraryID *int64)
| 49 | } |
| 50 | |
| 51 | func (s *APIKeyService) CreateAPIKey(ctx context.Context, eid, userID int64, role int64, name, description string, libraryID *int64) (*model.APIKey, string, error) { |
| 52 | spaceID, err := s.resolveAPIKeyScope(eid, userID, role, libraryID) |
| 53 | if err != nil { |
| 54 | return nil, "", err |
| 55 | } |
| 56 | |
| 57 | keyValue := model.GenerateAPIKey(eid, userID) |
| 58 | apiKey := &model.APIKey{ |
| 59 | Key: keyValue, |
| 60 | Name: name, |
| 61 | Description: description, |
| 62 | Eid: eid, |
| 63 | CreatorID: userID, |
| 64 | LibraryID: libraryID, |
| 65 | SpaceID: spaceID, |
| 66 | Status: model.APIKeyStatusActive, |
| 67 | } |
| 68 | |
| 69 | if err := apiKey.Save(); err != nil { |
| 70 | return nil, "", err |
| 71 | } |
| 72 | |
| 73 | return apiKey, keyValue, nil |
| 74 | } |
| 75 | |
| 76 | func (s *APIKeyService) ListAPIKeys(ctx context.Context, eid, userID int64, role int64, keyType string, libraryID *int64) ([]model.APIKey, error) { |
| 77 | if libraryID != nil { |
no test coverage detected