Skip to content

Commit 22d94e1

Browse files
authored
Fixed bug where we triggered unnecessary connection attempts to externally managed databases (#594)
1 parent 0596085 commit 22d94e1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/shared/databaseconfigurator/postgres/postgres.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,22 @@ func (p *PostgresConfigurator) getAllowedDatabasesDiffForUser(ctx context.Contex
182182
}
183183

184184
func (p *PostgresConfigurator) revokeDatabasePermissions(ctx context.Context, username string, dbname string) error {
185+
if IsManagedDBName(dbname) {
186+
// If we know that this is managed DB, we don't want to try to connect to it, becasue we know that we will
187+
// fail, and this might raise an alert on the database (for example, if we will try to connect to
188+
// 'cloudsqladmin' database in managed Google cloud SQL)
189+
logrus.WithField("database", dbname).Debug("Skipping known managed database")
190+
return nil
191+
}
192+
185193
err := p.setConnection(ctx, dbname)
186-
if err != nil && (IsInvalidAuthorizationError(err) || IsManagedDBName(dbname)) {
194+
if err != nil && IsInvalidAuthorizationError(err) {
187195
// Probably an admin database that we're failing to connect to or something along those lines
188196
// (like 'cloudsqladmin' database in managed Google cloud SQL)
189197
logrus.WithField("database", dbname).Debug("Skipping invalid authorization error")
190198
return nil
191199
}
200+
192201
if err != nil {
193202
pgErr, ok := TranslatePostgresConnectionError(err)
194203
if ok {

0 commit comments

Comments
 (0)