postgresql

package
v2.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
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).

View Source
const PDriverName = "pgx"

PDriverName is driver name for psqldb connection

View Source
const PSqlServerPort = 5432

PSqlServerPort is the default server port for sql server

Variables

View Source
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

func DatabaseExists(ctx context.Context, db *sql.DB, dbName string) (bool, error)

DatabaseExists checks if a database exists

func DoesUserExist

func DoesUserExist(ctx context.Context, db *sql.DB, username string) (bool, error)

DoesUserExist checks if db contains user

func DropUser

func DropUser(ctx context.Context, db *sql.DB, user string) error

DropUser drops a user from db

func FindBadChars

func FindBadChars(stack string) error

FindBadChars find the bad chars in a postgresql user

func GetUserServerRoles

func GetUserServerRoles(ctx context.Context, db *sql.DB, user SQLUser) (set.Set[string], error)

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

func ReconcileUserServerRoles(ctx context.Context, db *sql.DB, user SQLUser, roles []string) error

ReconcileUserServerRoles revokes and grants server-level roles as needed so the roles for the user match those passed in.

func RoleExists

func RoleExists(ctx context.Context, db *sql.DB, rolname string) (bool, error)

RoleExists checks if db contains role

func UpdateUser

func UpdateUser(ctx context.Context, db *sql.DB, user SQLUser, password string) error

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

func GetUserRoleOptions(ctx context.Context, db *sql.DB, user SQLUser) (*RoleOptions, error)

GetUserRoleOptions gets the server-level RoleOptions the user has as a set.

type SQLRoleDelta

type SQLRoleDelta struct {
	AddedRoles   set.Set[string]
	DeletedRoles set.Set[string]
}

func DiffCurrentAndExpectedSQLRoles

func DiffCurrentAndExpectedSQLRoles(currentRoles set.Set[string], expectedRoles set.Set[string]) 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

func CreateUser

func CreateUser(ctx context.Context, db *sql.DB, username string, password string) (*SQLUser, error)

func FindUserIfExist

func FindUserIfExist(ctx context.Context, db *sql.DB, username string) (*SQLUser, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL