postgresql

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GrantDbAndSchemaPrivileges added in v0.4.1

func GrantDbAndSchemaPrivileges(db *sql.DB, user Role, database Database) error

GrantDbAndSchemaPrivileges grants user privileges to create schema and connect to the database/public schema

func GrantDefaultPrivileges added in v0.4.1

func GrantDefaultPrivileges(info *DbInfo, db *sql.DB, user Role, database Database) error

GrantDefaultPrivileges configures default privileges for any objects created by the user

This ensures that any objects created by user in the future will be accessible to the database owner role
Since grantRole adds role membership to database owner role, this effectively gives any new users access to objects

Types

type Database

type Database struct {
	Name               string
	Owner              string
	Template           string
	Encoding           string
	Collation          string
	LcCtype            string
	TablespaceName     string
	ConnectionLimit    int
	IsTemplate         bool
	DisableConnections bool
}

func (Database) Create

func (d Database) Create(db *sql.DB, info DbInfo) error

func (Database) Drop

func (d Database) Drop(db *sql.DB) error

func (Database) Ensure added in v0.1.2

func (d Database) Ensure(db *sql.DB, info DbInfo) error

func (Database) Exists added in v0.1.0

func (d Database) Exists(db *sql.DB) (bool, error)

func (*Database) Read added in v0.1.0

func (d *Database) Read(db *sql.DB) error

func (Database) Update

func (d Database) Update(db *sql.DB) error

type DbInfo

type DbInfo struct {
	DbVersion         semver.Version
	SupportedFeatures Features
	IsSuperuser       bool
	CurrentUser       string
}

func CalcDbConnectionInfo

func CalcDbConnectionInfo(db *sql.DB) (*DbInfo, error)

type FeatureName

type FeatureName uint
const (
	FeatureCreateRoleWith FeatureName = iota
	FeatureDBAllowConnections
	FeatureDBIsTemplate
	FeatureFallbackApplicationName
	FeatureRLS
	FeatureSchemaCreateIfNotExist
	FeatureReplication
	FeatureExtension
	FeaturePrivileges
	FeatureForceDropDatabase
	FeaturePid
)

type Features

type Features map[FeatureName]bool

func CalcSupportedFeatures

func CalcSupportedFeatures(dbVersion semver.Version) Features

func (Features) IsSupported

func (f Features) IsSupported(name FeatureName) bool

type NoopRevoker added in v0.1.1

type NoopRevoker struct {
}

func (NoopRevoker) Revoke added in v0.1.1

func (t NoopRevoker) Revoke(db *sql.DB) error

type Revoker added in v0.1.1

type Revoker interface {
	Revoke(db *sql.DB) error
}

type Role

type Role struct {
	Name     string
	Password string
}

func (Role) Create

func (r Role) Create(db *sql.DB) error

func (Role) Ensure added in v0.1.2

func (r Role) Ensure(db *sql.DB) error

func (Role) Exists added in v0.1.0

func (r Role) Exists(db *sql.DB) (bool, error)

func (Role) Read added in v0.1.0

func (r Role) Read(db *sql.DB) error

type RoleGrant added in v0.1.2

type RoleGrant struct {
	// Member receives all the permissions for Target
	Member string

	// Target is the role that gains an additional Member
	Target string

	// WithAdminOption permits Member to grant it to others
	WithAdminOption bool
}

RoleGrant adds Member to the Target role

func (RoleGrant) Create added in v0.1.2

func (g RoleGrant) Create(db *sql.DB) error

func (RoleGrant) Ensure added in v0.1.2

func (g RoleGrant) Ensure(db *sql.DB) error

func (RoleGrant) Exists added in v0.1.2

func (g RoleGrant) Exists(db *sql.DB) (bool, error)

func (RoleGrant) Read added in v0.1.2

func (g RoleGrant) Read(db *sql.DB) error

type TempGrant

type TempGrant struct {
	Tx          *sql.Tx
	Role        string
	CurrentUser string
}

func GrantRoleMembership added in v0.1.1

func GrantRoleMembership(db *sql.DB, role string, currentUser string) (*TempGrant, error)

GrantRoleMembership grants role membership of the target 'role' to the 'currentUser' This is used to perform commands if user is not a superuser For instance, when using AWS RDS, user is not given superuser It returns false if the grant is not needed because the user is already a member of this role.

func (TempGrant) Revoke

func (t TempGrant) Revoke(db *sql.DB) error

Revoke revokes the role *role* from the user *member*. It returns false if the revoke is not needed because the user is not a member of this role.

Jump to

Keyboard shortcuts

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