auth

package
Version: v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2023 License: MIT Imports: 3 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewDefaultCredentialStoreFactory

func NewDefaultCredentialStoreFactory() *build.Factory

Create a new instance of the factory. Returns *build.Factory

Types

type CredentialParams

type CredentialParams struct {
	config.ConfigParams
}

Contains credentials to authenticate against external services. They are used together with connection parameters, but usually stored in a separate store, protected from unauthorized access.

Configuration parameters

store_key: key to retrieve parameters from credential store
username: user name
user: alternative to username
password: user password
pass: alternative to password
access_id: application access id
client_id: alternative to access_id
access_key: application secret key
client_key: alternative to access_key
secret_key: alternative to access_key

In addition to standard parameters CredentialParams may contain any number of custom parameters

see ConfigParams

see ConnectionParams

see CredentialResolver

see ICredentialStore

Example

credential := NewCredentialParamsFromTuples(
    "user", "jdoe",
    "pass", "pass123",
    "pin", "321"
);

username := credential.Username();             // Result: "jdoe"
password := credential.Password();             // Result: "pass123"

func NewCredentialParams

func NewCredentialParams(values map[string]string) *CredentialParams

Creates a new credential parameters and fills it with values. Parameters:

  • values map[string]string an object to be converted into key-value pairs to initialize these credentials.

Returns *CredentialParams

func NewCredentialParamsFromConfig

func NewCredentialParamsFromConfig(config *config.ConfigParams) *CredentialParams

Retrieves a single CredentialParams from configuration parameters from "credential" section. If "credentials" section is present instead, then is returns only the first credential element. Parameters:

  • config *config.ConfigParams ConfigParams, containing a section named "credential(s)".

Returns []*CredentialParams the generated CredentialParams object.

func NewCredentialParamsFromMaps

func NewCredentialParamsFromMaps(maps ...map[string]string) *CredentialParams

Static method for creating a CredentialParams using the maps passed as parameters. Parameters:

  • maps ...map[string]string the maps passed to this method to create a StringValueMap with.

Returns *CredentialParams the CredentialParams created.

func NewCredentialParamsFromString

func NewCredentialParamsFromString(line string) *CredentialParams

Creates a new CredentialParams object filled with key-value pairs serialized as a string. Parameters:

  • line string a string with serialized key-value pairs as "key1=value1;key2=value2;..." Example: "Key1=123;Key2=ABC;Key3=2016-09-16T00:00:00.00Z"

Returns *CredentialParams a new CredentialParams object.

func NewCredentialParamsFromTuples

func NewCredentialParamsFromTuples(tuples ...interface{}) *CredentialParams

Creates a new CredentialParams object filled with provided key-value pairs called tuples. Tuples parameters contain a sequence of key1, value1, key2, value2, ... pairs. Parameters:

  • tuples ...interface{} the tuples to fill a new CredentialParams object.

Returns *CredentialParams a new CredentialParams object.

func NewCredentialParamsFromTuplesArray

func NewCredentialParamsFromTuplesArray(tuples []interface{}) *CredentialParams

Static method for creating a CredentialParams from an array of tuples. Parameters:

  • tuples []interface{} the key-value tuples array to initialize the new StringValueMap with.

Returns CredentialParams the CredentialParams created and filled by the 'tuples' array provided.

func NewCredentialParamsFromValue

func NewCredentialParamsFromValue(value interface{}) *CredentialParams

Method that creates a ConfigParams object based on the values that are stored in the 'value' object's properties. Parameters:

  • value interface{} configuration parameters in the form of an object with properties.

Returns *ConfigParams generated ConfigParams.

func NewEmptyCredentialParams

func NewEmptyCredentialParams() *CredentialParams

Creates a new credential parameters and fills it with values. Returns *CredentialParams

func NewManyCredentialParamsFromConfig

func NewManyCredentialParamsFromConfig(config *config.ConfigParams) []*CredentialParams

Retrieves all CredentialParams from configuration parameters from "credentials" section. If "credential" section is present instead, than it returns a list with only one CredentialParams. Parameters:

  • config *config.ConfigParams a configuration parameters to retrieve credentials

Returns []*CredentialParams a list of retrieved CredentialParams

func (*CredentialParams) AccessId

func (c *CredentialParams) AccessId() string

Gets the application access id. The value can be stored in parameters "access_id" pr "client_id" Returns string the application access id.

func (*CredentialParams) AccessKey

func (c *CredentialParams) AccessKey() string

Gets the application secret key. The value can be stored in parameters "access_key", "client_key" or "secret_key". Returns string the application secret key.

func (*CredentialParams) Password

func (c *CredentialParams) Password() string

Get the user password. The value can be stored in parameters "password" or "pass". Returns string the user password.

func (*CredentialParams) SetAccessId

func (c *CredentialParams) SetAccessId(value string)

Sets the application access id. Parameters:

  • value: string a new application access id.

func (*CredentialParams) SetAccessKey

func (c *CredentialParams) SetAccessKey(value string)

Sets the application secret key. Parameters

  • value string a new application secret key.

func (*CredentialParams) SetPassword

func (c *CredentialParams) SetPassword(value string)

Sets the user password. Parameters:

  • value string a new user password.

func (*CredentialParams) SetStoreKey

func (c *CredentialParams) SetStoreKey(value string)

Sets the key to retrieve these parameters from CredentialStore. Parameters:

  • value string a new key to retrieve credentials.

func (*CredentialParams) SetUsername

func (c *CredentialParams) SetUsername(value string)

Sets the user name. Parameters:

  • value string a new user name.

func (*CredentialParams) StoreKey

func (c *CredentialParams) StoreKey() string

Gets the key to retrieve these credentials from CredentialStore. If this key is null, than all parameters are already present. Returns string the store key to retrieve credentials.

func (*CredentialParams) UseCredentialStore

func (c *CredentialParams) UseCredentialStore() bool

Checks if these credential parameters shall be retrieved from CredentialStore. The credential parameters are redirected to CredentialStore when store_key parameter is set. Returns bool true if credentials shall be retrieved from CredentialStore

func (*CredentialParams) Username

func (c *CredentialParams) Username() string

Gets the user name. The value can be stored in parameters "username" or "user". Returns string the user name.

type CredentialResolver

type CredentialResolver struct {
	// contains filtered or unexported fields
}

Helper class to retrieve component credentials.

If credentials are configured to be retrieved from ICredentialStore, it automatically locates ICredentialStore in component references and retrieve credentials from there using store_key parameter.

Configuration parameters

credential:

  store_key: (optional) a key to retrieve the credentials from ICredentialStore
    ... other credential parameters
  credentials: alternative to credential

    [credential params 1]: first credential parameters
    ... credential parameters for key 1
    ...
    [credential params N]: Nth credential parameters
    ... credential parameters for key N

References *:credential-store:*:*:1.0 (optional) Credential stores to resolve credentials see CredentialParams

see ICredentialStore

Example

config := NewConfigParamsFromTuples(
    "credential.user", "jdoe",
    "credential.pass",  "pass123"
);

credentialResolver := NewCredentialResolver();
credentialResolver.Configure(config);
credentialResolver.SetReferences(references);

credentialResolver.Lookup("123", (err, credential) => {
    // Now use credential...
});

func NewCredentialResolver

func NewCredentialResolver(config *config.ConfigParams,
	references refer.IReferences) *CredentialResolver

Creates a new instance of credentials resolver. Parameters:

  • config *config.ConfigParams component configuration parameters
  • references refer.IReferences component references

Returns *CredentialResolver

func NewEmptyCredentialResolver

func NewEmptyCredentialResolver() *CredentialResolver

Creates a new instance of credentials resolver. Returns *CredentialResolver

func (*CredentialResolver) Add

func (c *CredentialResolver) Add(credential *CredentialParams)

Adds a new credential to component credentials Parameters:

  • credential *CredentialParams new credential parameters to be added

func (*CredentialResolver) Configure

func (c *CredentialResolver) Configure(config *config.ConfigParams)

Configures component by passing configuration parameters. Parameters:

  • config *config.ConfigParams configuration parameters to be set.

func (*CredentialResolver) GetAll

func (c *CredentialResolver) GetAll() []*CredentialParams

Gets all credentials configured in component configuration. Redirect to CredentialStores is not done at this point. If you need fully fleshed credential use lookup method instead. Returns []*CredentialParams a list with credential parameters

func (*CredentialResolver) Lookup

func (c *CredentialResolver) Lookup(correlationId string) (*CredentialParams, error)

Looks up component credential parameters. If credentials are configured to be retrieved from Credential store it finds a ICredentialStore and lookups credentials there. Parameters:

  • correlationId string

(optional) transaction id to trace execution through call chain. Returns *CredentialParams? error

func (*CredentialResolver) SetReferences

func (c *CredentialResolver) SetReferences(references refer.IReferences)

Sets references to dependent components. Parameters:

  • references refer.IReferences references to locate the component dependencies.

type ICredentialStore

type ICredentialStore interface {
	// Stores credential parameters into the store.
	Store(correlationId string, key string, credential *CredentialParams) error
	// Lookups credential parameters by its key.
	Lookup(correlationId string, key string) (*CredentialParams, error)
}

Interface for credential stores which are used to store and lookup credentials to authenticate against external services.

type MemoryCredentialStore

type MemoryCredentialStore struct {
	// contains filtered or unexported fields
}

Credential store that keeps credentials in memory.

Configuration parameters

[credential key 1]:
... credential parameters for key 1
[credential key 2]:
... credential parameters for key N
...

see ICredentialStore

see CredentialParams

Example

config := NewConfigParamsFromTuples(
    "key1.user", "jdoe",
    "key1.pass", "pass123",
    "key2.user", "bsmith",
    "key2.pass", "mypass"
);

credentialStore := NewEmptyMemoryCredentialStore();
credentialStore.ReadCredentials(config);
res, err := credentialStore.Lookup("123", "key1");

func NewEmptyMemoryCredentialStore

func NewEmptyMemoryCredentialStore() *MemoryCredentialStore

Creates a new instance of the credential store. Returns *MemoryCredentialStore

func NewMemoryCredentialStore

func NewMemoryCredentialStore(config *config.ConfigParams) *MemoryCredentialStore

Creates a new instance of the credential store. Parameters:

  • config *config.ConfigParams configuration with credential parameters.

Returns *MemoryCredentialStore

func (*MemoryCredentialStore) Configure

func (c *MemoryCredentialStore) Configure(config *config.ConfigParams)

Configures component by passing configuration parameters. Parameters:

  • config *config.ConfigParams

configuration parameters to be set.

func (*MemoryCredentialStore) Lookup

func (c *MemoryCredentialStore) Lookup(correlationId string,
	key string) (result *CredentialParams, err error)

Lookups credential parameters by its key. Parameters:

  • correlationId string transaction id to trace execution through call chain.
  • key string a key to uniquely identify the credential parameters.

Return result *CredentialParams, err error result of lookup and error message

func (*MemoryCredentialStore) ReadCredentials

func (c *MemoryCredentialStore) ReadCredentials(config *config.ConfigParams)

Reads credentials from configuration parameters. Each section represents an individual CredentialParams Parameters:

  • config *config.ConfigParams configuration parameters to be read

func (*MemoryCredentialStore) Store

func (c *MemoryCredentialStore) Store(correlationId string, key string,
	credential *CredentialParams) error

Stores credential parameters into the store. Parameters:

  • correlationId string transaction id to trace execution through call chain.
  • key string a key to uniquely identify the credential parameters.
  • credential *CredentialParams a credential parameters to be stored.

Return error

Jump to

Keyboard shortcuts

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