Skip to content

Commit

Permalink
quote schema names in case they use special characters and remove str…
Browse files Browse the repository at this point in the history
…ings.Builder (zalando#2782)
  • Loading branch information
FxKu authored Oct 17, 2024
1 parent f5e122e commit 002d0f9
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions pkg/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,18 +1390,18 @@ func (c *Cluster) initPreparedDatabaseRoles() error {
preparedSchemas = map[string]acidv1.PreparedSchema{"data": {DefaultRoles: util.True()}}
}

var searchPath strings.Builder
searchPath.WriteString(constants.DefaultSearchPath)
searchPathArr := []string{constants.DefaultSearchPath}
for preparedSchemaName := range preparedSchemas {
searchPath.WriteString(", " + preparedSchemaName)
searchPathArr = append(searchPathArr, fmt.Sprintf("%q", preparedSchemaName))
}
searchPath := strings.Join(searchPathArr, ", ")

// default roles per database
if err := c.initDefaultRoles(defaultRoles, "admin", preparedDbName, searchPath.String(), preparedDB.SecretNamespace); err != nil {
if err := c.initDefaultRoles(defaultRoles, "admin", preparedDbName, searchPath, preparedDB.SecretNamespace); err != nil {
return fmt.Errorf("could not initialize default roles for database %s: %v", preparedDbName, err)
}
if preparedDB.DefaultUsers {
if err := c.initDefaultRoles(defaultUsers, "admin", preparedDbName, searchPath.String(), preparedDB.SecretNamespace); err != nil {
if err := c.initDefaultRoles(defaultUsers, "admin", preparedDbName, searchPath, preparedDB.SecretNamespace); err != nil {
return fmt.Errorf("could not initialize default roles for database %s: %v", preparedDbName, err)
}
}
Expand All @@ -1412,14 +1412,16 @@ func (c *Cluster) initPreparedDatabaseRoles() error {
if err := c.initDefaultRoles(defaultRoles,
preparedDbName+constants.OwnerRoleNameSuffix,
preparedDbName+"_"+preparedSchemaName,
constants.DefaultSearchPath+", "+preparedSchemaName, preparedDB.SecretNamespace); err != nil {
fmt.Sprintf("%s, %q", constants.DefaultSearchPath, preparedSchemaName),
preparedDB.SecretNamespace); err != nil {
return fmt.Errorf("could not initialize default roles for database schema %s: %v", preparedSchemaName, err)
}
if preparedSchema.DefaultUsers {
if err := c.initDefaultRoles(defaultUsers,
preparedDbName+constants.OwnerRoleNameSuffix,
preparedDbName+"_"+preparedSchemaName,
constants.DefaultSearchPath+", "+preparedSchemaName, preparedDB.SecretNamespace); err != nil {
fmt.Sprintf("%s, %q", constants.DefaultSearchPath, preparedSchemaName),
preparedDB.SecretNamespace); err != nil {
return fmt.Errorf("could not initialize default users for database schema %s: %v", preparedSchemaName, err)
}
}
Expand Down

0 comments on commit 002d0f9

Please sign in to comment.