mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove Result field from serviceaccounts, ualert (#62476)
* Chore: Remove Result field from serviceaccounts * Chore: Remove Result field from ualert
This commit is contained in:
@@ -47,7 +47,7 @@ type service interface {
|
||||
MigrateApiKey(ctx context.Context, orgID int64, keyId int64) error
|
||||
RevertApiKey(ctx context.Context, saId int64, keyId int64) error
|
||||
// Service account tokens
|
||||
AddServiceAccountToken(ctx context.Context, serviceAccountID int64, cmd *serviceaccounts.AddServiceAccountTokenCommand) error
|
||||
AddServiceAccountToken(ctx context.Context, serviceAccountID int64, cmd *serviceaccounts.AddServiceAccountTokenCommand) (*apikey.APIKey, error)
|
||||
DeleteServiceAccountToken(ctx context.Context, orgID, serviceAccountID, tokenID int64) error
|
||||
}
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ var _ service = new(fakeService)
|
||||
type fakeService struct {
|
||||
service
|
||||
ExpectedErr error
|
||||
ExpectedApiKey *apikey.APIKey
|
||||
ExpectedAPIKey *apikey.APIKey
|
||||
ExpectedServiceAccountTokens []apikey.APIKey
|
||||
ExpectedServiceAccount *serviceaccounts.ServiceAccountDTO
|
||||
ExpectedServiceAccountProfile *serviceaccounts.ServiceAccountProfileDTO
|
||||
@@ -286,9 +286,8 @@ func (f *fakeService) UpdateServiceAccount(ctx context.Context, orgID, id int64,
|
||||
return f.ExpectedServiceAccountProfile, f.ExpectedErr
|
||||
}
|
||||
|
||||
func (f *fakeService) AddServiceAccountToken(ctx context.Context, id int64, cmd *serviceaccounts.AddServiceAccountTokenCommand) error {
|
||||
cmd.Result = f.ExpectedApiKey
|
||||
return f.ExpectedErr
|
||||
func (f *fakeService) AddServiceAccountToken(ctx context.Context, id int64, cmd *serviceaccounts.AddServiceAccountTokenCommand) (*apikey.APIKey, error) {
|
||||
return f.ExpectedAPIKey, f.ExpectedErr
|
||||
}
|
||||
|
||||
func (f *fakeService) DeleteServiceAccountToken(ctx context.Context, orgID, id, tokenID int64) error {
|
||||
|
||||
@@ -175,7 +175,8 @@ func (api *ServiceAccountsAPI) CreateToken(c *contextmodel.ReqContext) response.
|
||||
|
||||
cmd.Key = newKeyInfo.HashedKey
|
||||
|
||||
if err := api.service.AddServiceAccountToken(c.Req.Context(), saID, &cmd); err != nil {
|
||||
apiKey, err := api.service.AddServiceAccountToken(c.Req.Context(), saID, &cmd)
|
||||
if err != nil {
|
||||
if errors.Is(err, database.ErrInvalidTokenExpiration) {
|
||||
return response.Error(http.StatusBadRequest, err.Error(), nil)
|
||||
}
|
||||
@@ -186,8 +187,8 @@ func (api *ServiceAccountsAPI) CreateToken(c *contextmodel.ReqContext) response.
|
||||
}
|
||||
|
||||
result := &dtos.NewApiKeyResult{
|
||||
ID: cmd.Result.Id,
|
||||
Name: cmd.Result.Name,
|
||||
ID: apiKey.Id,
|
||||
Name: apiKey.Name,
|
||||
Key: newKeyInfo.ClientSecret,
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ func TestServiceAccountsAPI_CreateToken(t *testing.T) {
|
||||
permissions []accesscontrol.Permission
|
||||
tokenTTL int64
|
||||
expectedErr error
|
||||
expectedApiKey *apikey.APIKey
|
||||
expectedAPIKey *apikey.APIKey
|
||||
expectedCode int
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ func TestServiceAccountsAPI_CreateToken(t *testing.T) {
|
||||
body: `{"name": "test"}`,
|
||||
tokenTTL: -1,
|
||||
permissions: []accesscontrol.Permission{{Action: serviceaccounts.ActionWrite, Scope: "serviceaccounts:id:1"}},
|
||||
expectedApiKey: &apikey.APIKey{},
|
||||
expectedAPIKey: &apikey.APIKey{},
|
||||
expectedCode: http.StatusOK,
|
||||
},
|
||||
{
|
||||
@@ -111,7 +111,7 @@ func TestServiceAccountsAPI_CreateToken(t *testing.T) {
|
||||
a.cfg.ApiKeyMaxSecondsToLive = tt.tokenTTL
|
||||
a.service = &fakeService{
|
||||
ExpectedErr: tt.expectedErr,
|
||||
ExpectedApiKey: tt.expectedApiKey,
|
||||
ExpectedAPIKey: tt.expectedAPIKey,
|
||||
}
|
||||
})
|
||||
req := server.NewRequest(http.MethodPost, fmt.Sprintf("/api/serviceaccounts/%d/tokens", tt.id), strings.NewReader(tt.body))
|
||||
|
||||
Reference in New Issue
Block a user