Skip to content

Commit 90c8428

Browse files
Merge pull request #12 from corbaltcode/lbk/use-revoke-and-grant
use verbs "revoke" and "grant"
2 parents fa65d54 + 03732a2 commit 90c8428

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

migrations/user.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func EnsureUsersWithRoles(db *sqlx.DB, users []PostgreSQLUser, authType UserAuth
5656
return fmt.Errorf("Failed to create user %q: %w", user.Username, err)
5757
}
5858

59-
// Drop all existing roles
60-
dropRolesSQL := fmt.Sprintf(`
59+
// Revoke all existing roles
60+
revokeRolesSQL := fmt.Sprintf(`
6161
DO $$
6262
DECLARE
6363
r RECORD;
@@ -71,16 +71,16 @@ func EnsureUsersWithRoles(db *sqlx.DB, users []PostgreSQLUser, authType UserAuth
7171
END LOOP;
7272
END
7373
$$;`, pq.QuoteLiteral(user.Username), pq.QuoteIdentifier(user.Username))
74-
_, err = tx.Exec(dropRolesSQL)
74+
_, err = tx.Exec(revokeRolesSQL)
7575
if err != nil {
76-
return fmt.Errorf("Failed to drop roles for user %q: %w", user.Username, err)
76+
return fmt.Errorf("Failed to revoke roles for user %q: %w", user.Username, err)
7777
}
7878

7979
// There could be privileges on a variety of different objects.
8080
// See https://www.postgresql.org/docs/current/sql-revoke.html
8181
// But we will just worry about roles.
8282

83-
// Add roles
83+
// Grant roles
8484
roles := user.GrantRoles
8585
if authType == UserAuthenticationTypeIAM {
8686
roles = append(roles, "rds_iam")
@@ -89,7 +89,7 @@ func EnsureUsersWithRoles(db *sqlx.DB, users []PostgreSQLUser, authType UserAuth
8989
grantSQL := fmt.Sprintf("GRANT %s TO %s", pq.QuoteIdentifier(role), pq.QuoteIdentifier(user.Username))
9090
_, err = tx.Exec(grantSQL)
9191
if err != nil {
92-
return fmt.Errorf("Failed to give role %q to user %q: %w", role, user.Username, err)
92+
return fmt.Errorf("Failed to grant role %q to user %q: %w", role, user.Username, err)
9393
}
9494
}
9595

0 commit comments

Comments
 (0)