mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Service accounts: fix usage of errutil errors and convert more errors to errutil (#64299)
* fix usage of errutil errors and convert more errors to errutil * fix tests
This commit is contained in:
@@ -160,7 +160,7 @@ func (s *ServiceAccountsStoreImpl) deleteServiceAccount(sess *db.Session, orgId,
|
||||
return err
|
||||
}
|
||||
if !has {
|
||||
return serviceaccounts.ErrServiceAccountNotFound
|
||||
return serviceaccounts.ErrServiceAccountNotFound.Errorf("service account with id %d not found", serviceAccountId)
|
||||
}
|
||||
for _, sql := range ServiceAccountDeletions(s.sqlStore.GetDialect()) {
|
||||
_, err := sess.Exec(sql, user.ID)
|
||||
@@ -211,7 +211,7 @@ func (s *ServiceAccountsStoreImpl) RetrieveServiceAccount(ctx context.Context, o
|
||||
if ok, err := sess.Get(serviceAccount); err != nil {
|
||||
return err
|
||||
} else if !ok {
|
||||
return serviceaccounts.ErrServiceAccountNotFound
|
||||
return serviceaccounts.ErrServiceAccountNotFound.Errorf("service account with id %d not found", serviceAccountId)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -248,7 +248,7 @@ func (s *ServiceAccountsStoreImpl) RetrieveServiceAccountIdByName(ctx context.Co
|
||||
if ok, err := sess.Get(serviceAccount); err != nil {
|
||||
return err
|
||||
} else if !ok {
|
||||
return serviceaccounts.ErrServiceAccountNotFound
|
||||
return serviceaccounts.ErrServiceAccountNotFound.Errorf("service account with name %s not found", name)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -61,9 +61,9 @@ func (s *ServiceAccountsStoreImpl) AddServiceAccountToken(ctx context.Context, s
|
||||
if err := s.apiKeyService.AddAPIKey(ctx, addKeyCmd); err != nil {
|
||||
switch {
|
||||
case errors.Is(err, apikey.ErrDuplicate):
|
||||
return serviceaccounts.ErrDuplicateToken
|
||||
return serviceaccounts.ErrDuplicateToken.Errorf("service account token with name %s already exists in the organization", cmd.Name)
|
||||
case errors.Is(err, apikey.ErrInvalidExpiration):
|
||||
return serviceaccounts.ErrInvalidTokenExpiration
|
||||
return serviceaccounts.ErrInvalidTokenExpiration.Errorf("invalid service account token expiration value %d", cmd.SecondsToLive)
|
||||
}
|
||||
|
||||
return err
|
||||
@@ -84,7 +84,7 @@ func (s *ServiceAccountsStoreImpl) DeleteServiceAccountToken(ctx context.Context
|
||||
}
|
||||
affected, err := result.RowsAffected()
|
||||
if affected == 0 {
|
||||
return serviceaccounts.ErrServiceAccountTokenNotFound
|
||||
return serviceaccounts.ErrServiceAccountTokenNotFound.Errorf("service account token with id %d not found", tokenId)
|
||||
}
|
||||
|
||||
return err
|
||||
@@ -101,7 +101,7 @@ func (s *ServiceAccountsStoreImpl) RevokeServiceAccountToken(ctx context.Context
|
||||
}
|
||||
affected, err := result.RowsAffected()
|
||||
if affected == 0 {
|
||||
return serviceaccounts.ErrServiceAccountTokenNotFound
|
||||
return serviceaccounts.ErrServiceAccountTokenNotFound.Errorf("service account token with id %d not found for service account with id %d", tokenId, serviceAccountId)
|
||||
}
|
||||
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user