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:
Bruno 2024-09-30 09:57:25 -03:00 committed by GitHub
parent ddbf0a05af
commit 6f92fd64ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 6 deletions

View File

@ -179,7 +179,8 @@ func (s *Service) GetToken(ctx context.Context) (gcom.TokenView, error) {
}
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) {
@ -300,7 +301,7 @@ func (s *Service) ValidateToken(ctx context.Context, cm cloudmigration.CloudMigr
defer span.End()
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

View File

@ -58,7 +58,7 @@ func Test_CreateGetAndDeleteToken(t *testing.T) {
assert.NoError(t, err)
_, err = s.GetToken(context.Background())
assert.ErrorIs(t, cloudmigration.ErrTokenNotFound, err)
assert.ErrorIs(t, err, cloudmigration.ErrTokenNotFound)
cm := cloudmigration.CloudMigrationSession{}
err = s.ValidateToken(context.Background(), cm)

View File

@ -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 {
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 {
return cloudmigration.ErrTokenNotFound
return fmt.Errorf("unable to decrypt token because token is empty: %w", cloudmigration.ErrTokenNotFound)
}
decoded, err := base64.StdEncoding.DecodeString(cm.AuthToken)
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)