dbclient

package
v1.10.3 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PostgresType       = "postgres"
	RDSReplicationRole = "rds_replication"
	GCPReplicationRole = "alloydbreplica"
	RDSSuperUserRole   = "rds_superuser"
)

Variables

This section is empty.

Functions

func New

func New(cfg Config) (*client, error)

func PostgresConnectionString

func PostgresConnectionString(host, port, user, password, dbname, sslmode string) string

func PostgresURI

func PostgresURI(host, port, user, password, dbname, sslmode string) string

PostgresURI returns a URI for a postgres connection

Types

type Clienter added in v1.0.6

type Clienter interface {
	Creater
	Updater
	Remover
	Exister
	DBCloser

	GetDB() *sql.DB
	Ping() error
	SanitizeDSN() string

	ManageReplicationRole(username string, enableReplicationRole bool) error
	ManageSuperUserRole(username string, enableSuperUser bool) error
	ManageCreateRole(username string, enableCreateRole bool) error
	ManageSystemFunctions(dbName string, functions map[string]string) error

	GetUserRoles(username string) ([]string, error)
}

type Config

type Config struct {
	// Cloud is `aws` or `gcp`
	Cloud  string
	Log    logr.Logger
	DBType string // type of DB, only postgres
	// connection string to connect to DB ie. postgres://username:password@1.2.3.4:5432/mydb?sslmode=verify-full
	// FQDN to connect to database including username and password if not using an IAM enabled user
	DSN string
	// UseIAM bool
	UseIAM bool // attempt to connect with IAM user provided in DSN
}

type Creater added in v1.0.6

type Creater interface {
	CreateDatabase(dbName string) (bool, error)
	//Creates a user in the the database
	CreateUser(username, role, userPassword string) (bool, error)
	//Creates a role in the specified DB and SCHEMA - with access to this specific SCHEMA only
	CreateRole(dbName, rolename, schema string) (bool, error)
	CreateAdminRole(dbName, rolename, schema string) (bool, error)
	CreateRegularRole(dbName, rolename, schema string) (bool, error)
	CreateReadOnlyRole(dbName, rolename, schema string) (bool, error)
	CreateDefaultExtensions(dbName string) error
	CreateSpecialExtensions(dbName string, role string) error
	CreateSchema(schemaName string) (bool, error)
}

type CredentialsProviderFunc

type CredentialsProviderFunc aws.CredentialsProviderFunc

type DBClient

type DBClient interface {
	Clienter
	CreateDataBase(name string) (bool, error)
}

DBClient is retired interface, use Client

type DBCloser

type DBCloser interface {
	Close() error
}

type Exister added in v1.0.6

type Exister interface {
	// Checks if a schema exists in the database
	SchemaExists(schemaName string) (bool, error)
	// Checks if a usedr exists in the database
	UserExists(userName string) (bool, error)
	// Checks if a role exists in the database
	RoleExists(roleName string) (bool, error)
}

type Remover added in v1.0.6

type Remover interface {
	DeleteUser(dbName, username, reassignToUser string) error
	RevokeAccessToRole(username, rolename string) error
}

type Updater added in v1.0.6

type Updater interface {
	RenameUser(oldUsername string, newUsername string) error
	UpdateUser(oldUsername, newUsername, rolename, password string) error
	UpdatePassword(username string, userPassword string) error
	AssignRoleToUser(username, rolename string) error
}

Jump to

Keyboard shortcuts

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