pg

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NullProvider

func NullProvider() credential.CredentialProvider

NullProvider returns a provider for when there are no credentials, such as when no passphrase is configured. A value without placeholders is returned unchanged, and a value with placeholders is an error.

Types

type Manager

type Manager struct {
	pg.PoolConn
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, pool pg.PoolConn, opts ...Opt) (_ *Manager, err error)

New creates a new manager object

func (*Manager) CreateCredential

func (self *Manager) CreateCredential(ctx context.Context, req schema.CredentialCreate) (_ *schema.Credential, err error)

CreateCredential encrypts the credentials with the latest passphrase and stores them, replacing any credentials with the same key. It returns the public credential shape, excluding the passphrase version and encrypted payload.

func (*Manager) DeleteCredential

func (self *Manager) DeleteCredential(ctx context.Context, key schema.CredentialKey) (_ *schema.Credential, err error)

DeleteCredential deletes the credential for the key, and returns the key and the time it was last stored

func (*Manager) DescribeCredential

func (self *Manager) DescribeCredential(ctx context.Context, key schema.CredentialKey, description string) (_ *schema.Credential, err error)

DescribeCredential sets the description of a credential, or removes it, when it's empty, without changing when it was updated, and returns the credential. Returns pg.ErrNotFound, as auth.ErrNotFound, when there's no credential for the key.

func (*Manager) GetCredential

func (self *Manager) GetCredential(ctx context.Context, key schema.CredentialKey, passphrase string) (_ json.RawMessage, err error)

GetCredential retrieves a credential by key, and decrypts it if the passphrase is the one it was encrypted with. Returns the credential as JSON, or ErrForbidden if the passphrase is not the credential's passphrase.

func (*Manager) GetCredentialMeta

func (self *Manager) GetCredentialMeta(ctx context.Context, key schema.CredentialKey) (_ *schema.Credential, err error)

GetCredentialMeta returns the key of a credential, and the time it was stored, without reading or decrypting the credential, so it does not need a passphrase. Returns auth.ErrNotFound, which also matches pg.ErrNotFound, if there is no credential for the key.

func (*Manager) GetCredentialProvider

func (self *Manager) GetCredentialProvider() credential.CredentialProvider

GetCredentialProvider returns a provider which substitutes credentials for placeholders. Credentials are decrypted without a passphrase, so the provider is for internal server-side use only, and must not be exposed via any public API or HTTP handler. With WithEnv, a credential which isn't stored is read from the environment, and without a passphrase, every credential is.

func (*Manager) GetCredentialWithoutPassphrase

func (self *Manager) GetCredentialWithoutPassphrase(ctx context.Context, key schema.CredentialKey) (_ json.RawMessage, err error)

GetCredentialWithoutPassphrase retrieves and decrypts a credential using the stored passphrase version. It is intended for internal server-side use only and must not be exposed via any public API or HTTP handler.

func (*Manager) ListCredentials

func (self *Manager) ListCredentials(ctx context.Context, req schema.CredentialListRequest) (_ *schema.CredentialList, err error)

ListCredentials returns a page of credentials in key order, without their encrypted payloads. When Rotate is set, only the credentials which need rotating to the latest passphrase version are returned, or when it is false, only those which don't.

func (*Manager) RotateCredential

func (self *Manager) RotateCredential(ctx context.Context, key schema.CredentialKey) (_ *schema.Credential, err error)

RotateCredential re-encrypts a credential with the latest passphrase version, without changing its value. Returns ErrNotModified if the credential already uses the latest version, or ErrConflict if the credential was changed or deleted while it was being rotated.

type Opt

type Opt func(*opt) error

Opt is a functional option for credential manager configuration.

func WithChannel

func WithChannel(channel string) Opt

WithChannel notifies the channel of each change of a credential, by its key, without its value, with a trigger, which go-pg's pgbroadcaster publishes, such as to a web UI, whatever makes the change. Without it, there's no trigger.

func WithEnv

func WithEnv() Opt

WithEnv reads a credential from the environment when it isn't stored in the database, so $KEY is expanded from the environment variable KEY. The environment is read-only, so credentials are still stored in the database.

func WithPassphrase

func WithPassphrase(version uint64, passphrase string) Opt

WithPassphrase registers an in-memory storage passphrase for a certificate passphrase version. Versions are uint64 and passphrases must be non-empty.

func WithSchema

func WithSchema(schema string) Opt

WithSchema sets the database schema used for storing credentials.

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the tracer used for tracing operations.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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