auth

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearDatabase

func ClearDatabase()

ClearDatabase clears the internal database, leaving only the default users. This is primarily for use by tests.

func DropRole

func DropRole(name string)

DropRole removes the given role from the database. If the role does not exist, then this is a no-op.

func GenerateRandomOctetString

func GenerateRandomOctetString(length int) rfc5802.OctetString

GenerateRandomOctetString generates an OctetString filled with random bytes.

func RoleExists

func RoleExists(name string) bool

RoleExists returns whether the given role exists.

func SetRole

func SetRole(role Role)

SetRole sets the role matching the given name. This will add a role that does not yet exist, and overwrite an existing role.

Types

type MockDatabase

type MockDatabase struct {
	Roles map[string]Role
}

MockDatabase is a temporary database to hold role passwords.

type Role

type Role struct {
	Name                      string               // rolname
	IsSuperUser               bool                 // rolsuper
	InheritPrivileges         bool                 // rolinherit
	CanCreateRoles            bool                 // rolcreaterole
	CanCreateDB               bool                 // rolcreatedb
	CanLogin                  bool                 // rolcanlogin
	IsReplicationRole         bool                 // rolreplication
	CanBypassRowLevelSecurity bool                 // rolbypassrls
	ConnectionLimit           int32                // rolconnlimit
	Password                  *ScramSha256Password // rolpassword
	ValidUntil                *time.Time           // rolvaliduntil
}

Role represents a role/user.

func CreateDefaultRole

func CreateDefaultRole(name string) Role

CreateDefaultRole creates the given role object with all default values set.

func GetRole

func GetRole(name string) Role

GetRole returns the role with the given name. Use RoleExists to determine if the role exists, as this will return a role with the default values set if it does not exist.

type ScramSha256Password

type ScramSha256Password struct {
	Iterations uint32
	Salt       rfc5802.OctetString
	StoredKey  rfc5802.OctetString
	ServerKey  rfc5802.OctetString
}

ScramSha256Password is the struct form of an encrypted password.

func NewScramSha256Password

func NewScramSha256Password(rawPassword string) (*ScramSha256Password, error)

NewScramSha256Password creates a ScramSha256Password with a randomly-generated salt.

func (ScramSha256Password) AsPasswordString

func (password ScramSha256Password) AsPasswordString() string

AsPasswordString returns the password as defined in https://www.postgresql.org/docs/15/catalog-pg-authid.html

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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