cred

package
v1.0.75 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEnvVarNotFound = errors.New("environment variable not set")

Functions

func DeleteEnv

func DeleteEnv(credLabel, key string) error

DeleteEnv removes an environment variable based on label and key.

func DeleteKeyRing

func DeleteKeyRing(credLabel, key string) error

DeleteKeyRing removes a key from the OS keyring, ignoring not found errors.

func FromEnv

func FromEnv(credLabel, key string) (string, error)

FromEnv retrieves a value from an environment variable based on label and key.

func FromKeyRing

func FromKeyRing(credLabel, key string) (string, error)

FromKeyRing retrieves a value from the OS keyring by label and key.

func ToEnv

func ToEnv(credLabel, key, value string) error

ToEnv sets an environment variable value based on label and key.

func ToKeyRing

func ToKeyRing(credLabel, key, value string) error

ToKeyRing stores a key-value pair in the OS keyring under the given label.

Types

type Identity

type Identity struct {
	User   string
	Secret string
}

Identity stores a pair of user - secret

type IdentityManager

type IdentityManager interface {
	IdentityReader
	IdentityWriter
}

IdentityManager generic API for reading/writing credentials

func NewManager

func NewManager(credLabel string, mode Mode) IdentityManager

NewManager creates a new identity manager with the specified label and Mode

type IdentityPayload

type IdentityPayload struct {
	User   *string
	Secret *string
}

IdentityPayload stores a pair of user - secret where any could be missing

type IdentityProvider

type IdentityProvider interface {
	CredLabel() string
	Get(key string) (string, error)
	Set(key, value string) error
	Delete(key string) error
}

IdentityProvider generic API for identity storage

func NewEnvProvider

func NewEnvProvider(credLabel string) IdentityProvider

NewEnvProvider creates a new environment variable based identity provider

func NewKeyProvider

func NewKeyProvider(credLabel string) IdentityProvider

NewKeyProvider creates a new key provider with the specified label.

type IdentityReader

type IdentityReader interface {
	CredLabel() string
	Get() (Identity, error)
	GetUser() (string, error)
	GetSecret() (string, error)
}

IdentityReader generic API for reading credentials

type IdentityWriter

type IdentityWriter interface {
	CredLabel() string
	SetAll(identity Identity) error
	Set(payload IdentityPayload) error
	SetUser(user string) error
	SetSecret(secret string) error
	Delete() error
}

IdentityWriter generic API for writing credentials

type Mode

type Mode byte

Mode the mode in which a IdentityManager can function

const (
	KeyRing Mode = iota // IdentityManager will use the OS keyring
	Env                 // IdentityManager will use the environment through environment variables
)

Jump to

Keyboard shortcuts

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