Documentation
¶
Index ¶
- Constants
- func ConnectToDB(ctx context.Context, fullservername string, database string, port int, ...) (*sql.DB, error)
- func CreateRoleWithPermissions(ctx context.Context, db *sql.DB, roleName string, permissions ...string) error
- func DatabaseExists(ctx context.Context, db *sql.DB, dbName string) (bool, error)
- func DoesUserExist(ctx context.Context, db *sql.DB, username string) (bool, error)
- func DropUser(ctx context.Context, db *sql.DB, user string) error
- func FindBadChars(stack string) error
- func GetUserServerRoles(ctx context.Context, db *sql.DB, user SQLUser) (set.Set[string], error)
- func ReconcileUserRoleOptions(ctx context.Context, db *sql.DB, user SQLUser, desiredOptions RoleOptions) error
- func ReconcileUserServerRoles(ctx context.Context, db *sql.DB, user SQLUser, roles []string) error
- func RoleExists(ctx context.Context, db *sql.DB, roleName string) (bool, error)
- func UpdateUser(ctx context.Context, db *sql.DB, user SQLUser, password string) error
- type RoleOption
- type RoleOptions
- type SQLRoleDelta
- type SQLRoleOptionDelta
- type SQLUser
Constants ¶
const ( Login = RoleOption("LOGIN") CreateRole = RoleOption("CREATEROLE") CreateDB = RoleOption("CREATEDB") Replication = RoleOption("REPLICATION") NoLogin = RoleOption("NOLOGIN") NoCreateRole = RoleOption("NOCREATEROLE") NoCreateDB = RoleOption("NOCREATEDB") NoReplication = RoleOption("NOREPLICATION") )
see https://www.postgresql.org/docs/current/sql-createrole.html
const DefaultMaintanenceDatabase = "postgres"
DefaultMaintanenceDatabase is the name of the database in a postgresql server where users and roles are stored (and which we can always assume will exist).
const PDriverName = "pgx"
PDriverName is driver name for psqldb connection
const PSqlServerPort = 5432
PSqlServerPort is the default server port for sql server
Variables ¶
This section is empty.
Functions ¶
func ConnectToDB ¶
func ConnectToDB(ctx context.Context, fullservername string, database string, port int, user string, password string) (*sql.DB, error)
ConnectToDB connects to the PostgreSQL db using the given credentials
func CreateRoleWithPermissions ¶ added in v2.13.0
func CreateRoleWithPermissions(ctx context.Context, db *sql.DB, roleName string, permissions ...string) error
CreateRoleWithPermissions creates a role. Note that this is not currently used except for test
func DatabaseExists ¶
DatabaseExists checks if a database exists
func DoesUserExist ¶
DoesUserExist checks if db contains user
func FindBadChars ¶
FindBadChars checks for potentially dangerous character sequences in identifiers like usernames and role names. Note: This is still used for identifiers (usernames, role names) as an additional safety measure, but is no longer used for passwords since proper escaping via EscapeStringLiteral handles all characters safely.
func GetUserServerRoles ¶
GetUserServerRoles gets the server-level roles the user has as a set.
func ReconcileUserRoleOptions ¶
func ReconcileUserRoleOptions(ctx context.Context, db *sql.DB, user SQLUser, desiredOptions RoleOptions) error
ReconcileUserRoleOptions revokes and grants server-level role options as needed so the role options for the user match those passed in.
func ReconcileUserServerRoles ¶
ReconcileUserServerRoles revokes and grants server-level roles as needed so the roles for the user match those passed in.
func RoleExists ¶
RoleExists checks if db contains role
Types ¶
type RoleOption ¶
type RoleOption string
type RoleOptions ¶
type RoleOptions struct {
// WITH LOGIN or NOLOGIN
Login bool
// WITH CREATEROLE or NOCREATEROLE
CreateRole bool
CreateDb bool
// WITH REPLICATION or NOREPLICATION
Replication bool
}
RoleOptions PostgreSQL role options but without SuperUser or BypassRLS here, because they are only settable with an existing a superuser Azure Flexible server does not offer superuser access for customers
func GetUserRoleOptions ¶
GetUserRoleOptions gets the server-level RoleOptions the user has as a set.
type SQLRoleDelta ¶
type SQLRoleOptionDelta ¶
type SQLRoleOptionDelta struct {
ChangedRoleOptions set.Set[RoleOption]
}
func DiffCurrentAndExpectedSQLRoleOptions ¶
func DiffCurrentAndExpectedSQLRoleOptions(currentRoleOptions RoleOptions, expectedRoleOptions RoleOptions) SQLRoleOptionDelta
type SQLUser ¶
type SQLUser struct {
Name string
}
Use this type only for user, which are already checked