auth

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: Apache-2.0 Imports: 5 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoCredential = errors.New("no credential")

ErrNoCredential is the error that is returned when no credential is found.

View Source
var ErrNoCredentialStore = errors.New("no credential store")

ErrNoCredentialStore is the error that is returned when no credential store is found.

Functions

func PlainEncrypt added in v1.2.4

func PlainEncrypt(passwd any, args ...any) (any, error)

PlainEncrypt encrypts the query password.

Types

type Conn

type Conn interface {
	// RemoteAddr returns the remote network address, if known.
	RemoteAddr() net.Addr
}

Conn represents a connection interface.

type Credential

type Credential interface {
	Group() string
	// Username returns the username.
	Username() string
	// Password returns the password.
	Password() any
}

Credential represents a credential interface.

func NewCredential

func NewCredential(opts ...CredentialOptionFn) Credential

NewCredential returns a new credential with options.

type CredentialAuthenticator

type CredentialAuthenticator interface {
	// VerifyCredential verifies the client credential.
	VerifyCredential(conn Conn, q Query) (bool, error)
}

CredentialAuthenticator is the interface for authenticating a client using credential.

type CredentialOptionFn

type CredentialOptionFn func(*cred)

CredentialOptionFn represents an option for a credential.

func WithCredentialGroup

func WithCredentialGroup(group string) CredentialOptionFn

WithCredentialGroup returns an option to set the group.

func WithCredentialPassword

func WithCredentialPassword(password any) CredentialOptionFn

WithCredentialPassword returns an option to set the password.

func WithCredentialUsername

func WithCredentialUsername(username string) CredentialOptionFn

WithCredentialUsername returns an option to set the username.

type CredentialStore

type CredentialStore interface {
	// LookupCredential looks up a credential by the given query.
	//
	// Parameters:
	//   q - The query used to look up the credential.
	//
	// Returns:
	//   Credential - The credential associated with the query.
	//   bool - A boolean indicating whether the credential was found (true) or not (false).
	//   error - An error if there was an issue during the lookup process, or nil if the lookup was successful.
	//
	// If the credential is not found, the function returns an empty Credential, false, and nil error.
	// If an error occurs during the lookup process, the function returns an empty Credential, false, and the error.
	LookupCredential(q Query) (Credential, bool, error)
}

CredentialStore represents a credential store interface.

type CredentialStoreRegistrar added in v1.2.3

type CredentialStoreRegistrar interface {
	// SetCredentialStore sets the credential store.
	SetCredentialStore(credStore CredentialStore)
}

CredentialStoreRegistrar is the interface for setting the credential store.

type DefaultCredentialAuthenticator added in v1.2.5

type DefaultCredentialAuthenticator interface {
	CredentialAuthenticator
	CredentialStoreRegistrar
}

DefaultCredentialAuthenticator interface includes CredentialAuthenticator and CredentialStoreRegistrar interfaces.

func NewDefaultCredentialAuthenticator

func NewDefaultCredentialAuthenticator() DefaultCredentialAuthenticator

NewDefaultCredentialAuthenticator returns a new default credential authenticator.

type EncryptFunc added in v1.2.4

type EncryptFunc func(passwd any, args ...any) (any, error)

EncryptFunc represents an encrypt function.

type Manager

type Manager interface {
	// SetCredentialAuthenticator sets the credential authenticator.
	SetCredentialAuthenticator(auth CredentialAuthenticator)
	// SetCredentialStore sets the credential store.
	SetCredentialStore(credStore CredentialStore)
	// CredentialStore returns the credential store.
	CredentialStore() CredentialStore
	// VerifyCredential verifies the client credential.
	VerifyCredential(conn Conn, q Query) (bool, error)
}

Manager represents a auth manager interface.

func NewManager

func NewManager() Manager

NewManager returns a new auth manager instance.

type Query

type Query interface {
	// SetGroup sets the group.
	SetGroup(group string)
	// SetUsername sets the username.
	SetUsername(username string)
	// SetPassword sets the password.
	SetPassword(password any)
	// SetMechanism sets the mechanism.
	SetMechanism(mech string)
	// SetOptions sets the options.
	SetOptions(opts ...any)
	// SetArguments sets the arguments.
	SetArguments(args ...any)
	// SetEncryptFunc sets the encrypt function.
	SetEncryptFunc(encryptFunc EncryptFunc)
	// Group returns the group.
	Group() string
	// Username returns the username.
	Username() string
	// Password returns the password.
	Password() any
	// Mechanism returns the mechanism.
	Mechanism() string
	// Options returns the options.
	Options() []any
	// EncryptFunc returns the encrypt function.
	EncryptFunc() EncryptFunc
	// Arguments returns the arguments for the encrypt function.
	Arguments() []any
}

Query represents a query interface.

func NewQuery

func NewQuery(opts ...QueryOptionFn) (Query, error)

NewQuery returns a new query with options.

type QueryOption

type QueryOption any

QueryOption represents an option for a query.

type QueryOptionFn

type QueryOptionFn func(Query) error

QueryOptionFn represents an option function for a query.

func WithQueryArguments added in v1.2.4

func WithQueryArguments(args ...any) QueryOptionFn

WithQueryArguments returns an option to set the arguments for the encrypt function.

func WithQueryEncryptFunc added in v1.2.4

func WithQueryEncryptFunc(encryptFunc EncryptFunc) QueryOptionFn

WithQueryEncryptFunc returns an option to set the encrypt function.

func WithQueryGroup

func WithQueryGroup(group string) QueryOptionFn

WithQueryGroup returns an option to set the group.

func WithQueryMechanism

func WithQueryMechanism(mech string) QueryOptionFn

WithQueryMechanism returns an option to set the mechanism.

func WithQueryOptions added in v1.2.4

func WithQueryOptions(opt ...any) QueryOptionFn

WithQueryOptions returns an option to set the options.

func WithQueryPassword

func WithQueryPassword(password any) QueryOptionFn

WithQueryPassword returns an option to set the password.

func WithQueryUsername

func WithQueryUsername(username string) QueryOptionFn

WithQueryUsername returns an option to set the username.

Jump to

Keyboard shortcuts

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