pg

package
v1.1.1-0...-f35d416 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ProtectedRoles = map[string]bool{"aq_administrator_role": true,
		"enterprisedb":              true,
		"postgres":                  true,
		"pg_monitor":                true,
		"pg_read_all_settings":      true,
		"pg_read_all_stats":         true,
		"pg_stat_scan_tables":       true,
		"pg_signal_backend":         true,
		"pg_read_server_files":      true,
		"pg_write_server_files":     true,
		"pg_execute_server_program": true,
	}

	ProtectedDatabases = map[string]bool{"postgres": true,
		"template0": true,
		"template1": true,
	}
)
View Source
var (
	LoginOption, _ = NewRoleOption("LOGIN")
	LoginOptions   = RoleOptions{LoginOption.name: LoginOption}
)
View Source
var (
	// Present means the object should be created
	Present = State{statePresent}
	// Absent means the object should be removed
	Absent = State{stateAbsent}
)
View Source
var InvalidOption = errors.New("invalid role option")
View Source
var (
	ValidRoleOptions = map[string]string{
		"SUPERUSER":   "rolsuper",
		"CREATEROLE ": "rolcreaterole",
		"CREATEUSER":  "rolcreaterole",
		"INHERIT":     "rolinherit",
		"LOGIN":       "rolcanlogin",
		"REPLICATION": "rolreplication",
	}
)

Functions

func Initialize

func Initialize(logger *zap.SugaredLogger)

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func NewConn

func NewConn(connParams Dsn) (c *Conn)

func (*Conn) Connect

func (c *Conn) Connect() (err error)

func (*Conn) DSN

func (c *Conn) DSN() (dsn string)

func (*Conn) DbName

func (c *Conn) DbName() (dbName string)

func (*Conn) UserName

func (c *Conn) UserName() (userName string)

type Database

type Database struct {
	Owner      string     `yaml:"owner"`
	Extensions Extensions `yaml:"extensions"`
	State      State      `yaml:"state"`
	// contains filtered or unexported fields
}

func NewDatabase

func NewDatabase(handler *Handler, name string, owner string) (d *Database)

func (*Database) AddExtension

func (d *Database) AddExtension(name string, schema string, version string) (e *Extension, err error)

func (Database) Create

func (d Database) Create() (err error)

func (*Database) CreateOrDropExtensions

func (d *Database) CreateOrDropExtensions() (err error)

func (*Database) Drop

func (d *Database) Drop() (err error)

func (*Database) GetDbConnection

func (d *Database) GetDbConnection() (c *Conn)

func (*Database) SetDefaults

func (d *Database) SetDefaults()

SetDefaults is called to set all defaults for databases created from yaml

func (Database) SetReadOnlyGrants

func (d Database) SetReadOnlyGrants(readOnlyRoleName string) (err error)

type Databases

type Databases map[string]*Database

type Dsn

type Dsn map[string]string

type Extension

type Extension struct {
	Schema  string `yaml:"schema"`
	State   State  `yaml:"state"`
	Version string `yaml:"version"`
	// contains filtered or unexported fields
}

func NewExtension

func NewExtension(db *Database, name string, schema string, version string) (e *Extension, err error)

func (Extension) Create

func (e Extension) Create() (err error)

func (*Extension) Drop

func (e *Extension) Drop() (err error)

type Extensions

type Extensions map[string]*Extension

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewPgHandler

func NewPgHandler(connParams Dsn, options StrictOptions, databases Databases, slots []string) (ph *Handler)

func (*Handler) CreateOrDropDatabases

func (ph *Handler) CreateOrDropDatabases() (err error)

func (*Handler) CreateOrDropSlots

func (ph *Handler) CreateOrDropSlots() (err error)

func (*Handler) GetDb

func (ph *Handler) GetDb(dbName string) (d *Database)

func (*Handler) GetRole

func (ph *Handler) GetRole(roleName string) (d *Role, err error)

func (*Handler) GrantRole

func (ph *Handler) GrantRole(granteeName string, grantedName string) (err error)

func (*Handler) StrictifyDatabases

func (ph *Handler) StrictifyDatabases() (err error)

func (*Handler) StrictifyExtensions

func (ph *Handler) StrictifyExtensions() (err error)

func (*Handler) StrictifyRoles

func (ph *Handler) StrictifyRoles() (err error)

type ReplicationSlot

type ReplicationSlot struct {
	State State `yaml:"state"`
	// contains filtered or unexported fields
}

func NewSlot

func NewSlot(handler *Handler, name string) (rs *ReplicationSlot)

func (ReplicationSlot) Create

func (rs ReplicationSlot) Create() (err error)

func (ReplicationSlot) Drop

func (rs ReplicationSlot) Drop() (err error)

type ReplicationSlots

type ReplicationSlots map[string]ReplicationSlot

type Role

type Role struct {
	State State
	// contains filtered or unexported fields
}

func NewRole

func NewRole(handler *Handler, name string, options RoleOptions, state State) (r *Role, err error)

func (Role) Create

func (r Role) Create() (err error)

func (*Role) Drop

func (r *Role) Drop() (err error)

func (Role) GrantRole

func (r Role) GrantRole(grantedRole *Role) (err error)

func (Role) ResetExpiry

func (r Role) ResetExpiry() (err error)

func (Role) ResetPassword

func (r Role) ResetPassword() (err error)

func (Role) RevokeRole

func (r Role) RevokeRole(roleName string) (err error)

func (Role) SetExpiry

func (r Role) SetExpiry(expiry time.Time) (err error)

func (Role) SetPassword

func (r Role) SetPassword(password string) (err error)

type RoleOption

type RoleOption struct {
	// contains filtered or unexported fields
}

func NewRoleOption

func NewRoleOption(name string) (opt RoleOption, err error)

func (RoleOption) Inverse

func (opt RoleOption) Inverse() (invOpt RoleOption)

func (RoleOption) MarshalYAML

func (opt RoleOption) MarshalYAML() (interface{}, error)

MarshalYAML marshals the enum as a quoted json string

func (RoleOption) Sql

func (opt RoleOption) Sql() (sql string)

func (RoleOption) String

func (opt RoleOption) String() (name string)

func (*RoleOption) UnmarshalYAML

func (opt *RoleOption) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML converts a yaml string to the enum value

func (RoleOption) Valid

func (opt RoleOption) Valid() (isValid bool)

type RoleOptions

type RoleOptions map[string]RoleOption

func (RoleOptions) AddOption

func (ro RoleOptions) AddOption(opt RoleOption)

type Roles

type Roles map[string]Role

type State

type State struct {
	// contains filtered or unexported fields
}

State represents the state of a pg object (Present or Absent)

func (State) Bool

func (s State) Bool() bool

func (State) MarshalYAML

func (s State) MarshalYAML() (interface{}, error)

MarshalYAML marshals the enum as a quoted json string

func (State) String

func (s State) String() string

func (*State) UnmarshalYAML

func (s *State) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML converts a yaml string to the enum value

type StrictOptions

type StrictOptions struct {
	Users      bool `yaml:"users"`
	Databases  bool `yaml:"databases"`
	Extensions bool `yaml:"extensions"`
	Slots      bool `yaml:"replication_slots"`
}

Jump to

Keyboard shortcuts

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