Documentation ¶
Index ¶
- Constants
- Variables
- func ConnectToDB(ctx context.Context, fullservername string, database string, port int, ...) (*sql.DB, 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, rolname 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 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 ¶
var ( 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
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 DatabaseExists ¶
DatabaseExists checks if a database exists
func DoesUserExist ¶
DoesUserExist checks if db contains user
func FindBadChars ¶
FindBadChars find the bad chars in a postgresql user
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 // WITH CREATEDB or NOCREATEDB 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