role

package
v0.0.0-...-7296e1c Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package role provides functions for managing PostgreSQL roles, including creating, updating, retrieving, and deleting roles.

Index

Constants

This section is empty.

Variables

View Source
var ErrRoleNotFound = fmt.Errorf("role not found")

ErrRoleNotFound is returned when a requested role does not exist in the database.

Functions

func Create

func Create(ctx context.Context, conn pg.Conn, role Role) error

Create adds a new PostgreSQL role to the database based on the provided Role struct. It returns an error if role already exists or the creation process fails

func Delete

func Delete(ctx context.Context, conn pg.Conn, roleName string) error

Delete removes a PostgreSQL role from the database.

func Update

func Update(ctx context.Context, conn pg.Conn, role Role) error

Update modifies an existing PostgreSQL role in the database. It updates the role's attributes based on the provided Role struct. If the role does not exist, an error is returned.

Types

type Role

type Role struct {
	// Name is the name of the role.
	Name string `json:"rolname"`
	// Superuser indicates whether the role has superuser privileges.
	Superuser bool `json:"rolsuper"`
	// Inherit indicates whether the role inherits privileges from its parent roles.
	Inherit bool `json:"rolinherit"`
	// CreateRole indicates whether the role can create other roles.
	CreateRole bool `json:"rolcreaterole"`
	// CreateDB indicates whether the role can create databases.
	CreateDB bool `json:"rolcreatedb"`
	// CanLogin indicates whether the role can log in (applicable to user roles).
	CanLogin bool `json:"rolcanlogin"`
	// Replication indicates whether the role can replicate data.
	Replication bool `json:"rolreplication"`
	// ConnLimit is the maximum number of concurrent connections allowed for the role.
	ConnLimit int `json:"rolconnlimit"`
	// Password is the password hash (masked for security).
	Password string `json:"rolpassword"`
	// ValidUntil is the password expiry date (nullable).
	ValidUntil pgtype.Timestamptz `json:"rolvaliduntil"`
	// BypassRLS indicates whether the role can bypass row-level security policies.
	BypassRLS bool `json:"rolbypassrls"`
	// Config is an array of configuration settings for the role.
	Config []string `json:"rolconfig"`
	// OID is the object identifier (OID) of the role.
	OID uint32 `json:"oid"`
}

Role represents a PostgreSQL role with its associated attributes and privileges.

func Get

func Get(ctx context.Context, conn pg.Conn, roleName string) (*Role, error)

Get returns the role identified by roleName, or ErrRoleNotFound if it doesn't exists

func List

func List(ctx context.Context, conn pg.Conn) ([]Role, error)

List retrieves all PostgreSQL roles from the database.

It queries the database using `SELECT * FROM pg_roles;` and returns a slice of Role, or any error encountered.

Jump to

Keyboard shortcuts

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