Skip to content

Commit

Permalink
Ignore user not found errors on alter user password from postgres & m…
Browse files Browse the repository at this point in the history
…ysql integrations
  • Loading branch information
amitlicht committed Jun 30, 2024
1 parent 618e885 commit 0fc4cfa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/shared/databaseconfigurator/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (

const (
SQLCreateUserStatement SQLSprintfStatement = "CREATE USER %s IDENTIFIED BY %s"
SQLAlterUserPasswordStatement SQLSprintfStatement = "ALTER USER %s IDENTIFIED BY %s"
SQLAlterUserPasswordStatement SQLSprintfStatement = "ALTER USER IF EXISTS %s IDENTIFIED BY %s"
SQLDropUserQuery SQLSprintfStatement = "DROP USER %s"

SQLGrantPrivilegesOnDatabaseStatement SQLSprintfStatement = "GRANT %s ON %s.* TO '%s'"
Expand Down
3 changes: 3 additions & 0 deletions src/shared/databaseconfigurator/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,5 +503,8 @@ func (p *PostgresConfigurator) AlterUserPassword(ctx context.Context, username s
if err := p.sendBatch(ctx, &batch); err != nil {
return errors.Wrap(err)
}
if errors.Is(err, ErrUndefinedObject) {
logrus.WithField("username", username).Debug("User does not exist, skipping password update")
}
return nil
}
5 changes: 5 additions & 0 deletions src/shared/databaseconfigurator/postgres/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"net"
)

var ErrUndefinedObject = errors.New("undefined object")

func TranslatePostgresConnectionError(err error) (string, bool) {
if opErr := &(net.OpError{}); errors.As(err, &opErr) || errors.Is(err, context.DeadlineExceeded) {
return "Can't reach the server", true
Expand Down Expand Up @@ -49,6 +51,9 @@ func TranslatePostgresCommandsError(err error) error {
if pgErr.Code == "42P01" || pgErr.Code == "3F000" {
return errors.Wrap(fmt.Errorf("bad schema/table name: %s", pgErr.Message))
}
if pgErr.Code == "42704" {
return errors.Wrap(ErrUndefinedObject)
}
}
return errors.Wrap(err)
}

0 comments on commit 0fc4cfa

Please sign in to comment.