mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Cloud migrations: add more context to errors (#93814)
* Cloud migrations: add more context to errors * calls to assert.ErrorIs was passing arguments in the wrong order
This commit is contained in:
parent
ddbf0a05af
commit
6f92fd64ce
@ -179,7 +179,8 @@ func (s *Service) GetToken(ctx context.Context) (gcom.TokenView, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
logger.Info("cloud migration token not found")
|
logger.Info("cloud migration token not found")
|
||||||
return gcom.TokenView{}, cloudmigration.ErrTokenNotFound
|
return gcom.TokenView{}, fmt.Errorf("fetching cloud migration token: instance=%+v accessPolicyName=%s accessTokenName=%s %w",
|
||||||
|
instance, accessPolicyName, accessTokenName, cloudmigration.ErrTokenNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) CreateToken(ctx context.Context) (cloudmigration.CreateAccessTokenResponse, error) {
|
func (s *Service) CreateToken(ctx context.Context) (cloudmigration.CreateAccessTokenResponse, error) {
|
||||||
@ -300,7 +301,7 @@ func (s *Service) ValidateToken(ctx context.Context, cm cloudmigration.CloudMigr
|
|||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
if err := s.gmsClient.ValidateKey(ctx, cm); err != nil {
|
if err := s.gmsClient.ValidateKey(ctx, cm); err != nil {
|
||||||
return fmt.Errorf("validating key: %w", err)
|
return fmt.Errorf("validating token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -58,7 +58,7 @@ func Test_CreateGetAndDeleteToken(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
_, err = s.GetToken(context.Background())
|
_, err = s.GetToken(context.Background())
|
||||||
assert.ErrorIs(t, cloudmigration.ErrTokenNotFound, err)
|
assert.ErrorIs(t, err, cloudmigration.ErrTokenNotFound)
|
||||||
|
|
||||||
cm := cloudmigration.CloudMigrationSession{}
|
cm := cloudmigration.CloudMigrationSession{}
|
||||||
err = s.ValidateToken(context.Background(), cm)
|
err = s.ValidateToken(context.Background(), cm)
|
||||||
|
@ -432,16 +432,16 @@ func (ss *sqlStore) encryptToken(ctx context.Context, cm *cloudmigration.CloudMi
|
|||||||
|
|
||||||
func (ss *sqlStore) decryptToken(ctx context.Context, cm *cloudmigration.CloudMigrationSession) error {
|
func (ss *sqlStore) decryptToken(ctx context.Context, cm *cloudmigration.CloudMigrationSession) error {
|
||||||
if cm == nil {
|
if cm == nil {
|
||||||
return cloudmigration.ErrMigrationNotFound
|
return fmt.Errorf("unable to decypt token because migration session was not found: %w", cloudmigration.ErrMigrationNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(cm.AuthToken) == 0 {
|
if len(cm.AuthToken) == 0 {
|
||||||
return cloudmigration.ErrTokenNotFound
|
return fmt.Errorf("unable to decrypt token because token is empty: %w", cloudmigration.ErrTokenNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
decoded, err := base64.StdEncoding.DecodeString(cm.AuthToken)
|
decoded, err := base64.StdEncoding.DecodeString(cm.AuthToken)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("token could not be decoded")
|
return fmt.Errorf("unable to base64 decode token: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
t, err := ss.secretsService.Decrypt(ctx, decoded)
|
t, err := ss.secretsService.Decrypt(ctx, decoded)
|
||||||
|
Loading…
Reference in New Issue
Block a user