auth

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2022 License: MIT Imports: 5 Imported by: 19

Documentation

Index

Constants

View Source
const (
	CredentialsParamSectionKey string = "credentials"
	CredentialParamSectionKey  string = "credential"
	CredentialParamStoreKey    string = "store_key"
	CredentialParamUsername    string = "username"
	CredentialParamUser        string = "user"
	CredentialParamPassword    string = "password"
	CredentialParamPass        string = "pass"
	CredentialParamAccessId    string = "access_id"
	CredentialParamClientId    string = "client_id"
	CredentialParamAccessKey   string = "access_key"
	CredentialParamClientKey   string = "client_key"
	CredentialParamSecretKey   string = "secret_key"
)

Variables

View Source
var MemoryCredentialStoreDescriptor = refer.NewDescriptor(
	"pip-services",
	"credential-store",
	"memory",
	"*",
	"1.0",
)

MemoryCredentialStoreDescriptor Creates ICredentialStore components by their descriptors.

Functions

func NewDefaultCredentialStoreFactory

func NewDefaultCredentialStoreFactory() *build.Factory

NewDefaultCredentialStoreFactory create a new instance of the factory.

Returns: *build.Factory

Types

type CredentialParams

type CredentialParams struct {
	*config.ConfigParams
}

CredentialParams 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 config.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

NewCredentialParams 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

NewCredentialParamsFromConfig кetrieves 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, containing a section named "credential(s)".
Returns []*CredentialParams the generated CredentialParams object.

func NewCredentialParamsFromMaps

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

NewCredentialParamsFromMaps 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

NewCredentialParamsFromString 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 ...any) *CredentialParams

NewCredentialParamsFromTuples 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 ...any the tuples to fill a new CredentialParams object.
Returns: *CredentialParams a new CredentialParams object.

func NewCredentialParamsFromTuplesArray

func NewCredentialParamsFromTuplesArray(tuples []any) *CredentialParams

NewCredentialParamsFromTuplesArray static method for creating a CredentialParams from an array of tuples.

Parameters:
	- tuples []any 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 any) *CredentialParams

NewCredentialParamsFromValue method that creates a ConfigParams object based on the values that are stored in the 'value' object's properties.

Parameters:
	- value any configuration parameters in the form of an object with properties.
Returns: *ConfigParams generated ConfigParams.

func NewEmptyCredentialParams

func NewEmptyCredentialParams() *CredentialParams

NewEmptyCredentialParams creates a new credential parameters and fills it with values.

Returns: *CredentialParams

func NewManyCredentialParamsFromConfig

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

NewManyCredentialParamsFromConfig retrieves all CredentialParams from configuration parameters from "credentials" section. If "credential" section is present instead, then 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

AccessId 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

AccessKey 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

Password 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)

SetAccessId sets the application access id.

Parameters: value: string a new application access id.

func (*CredentialParams) SetAccessKey

func (c *CredentialParams) SetAccessKey(value string)

SetAccessKey sets the application secret key.

Parameters: value string a new application secret key.

func (*CredentialParams) SetPassword

func (c *CredentialParams) SetPassword(value string)

SetPassword sets the user password.

Parameters: value string a new user password.

func (*CredentialParams) SetStoreKey

func (c *CredentialParams) SetStoreKey(value string)

SetStoreKey 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)

SetUsername sets the user name.

Parameters: value string a new user name.

func (*CredentialParams) StoreKey

func (c *CredentialParams) StoreKey() string

StoreKey gets the key to retrieve these credentials from CredentialStore. If this key is null, then all parameters are already present.

Returns: string the store key to retrieve credentials.

func (*CredentialParams) UseCredentialStore

func (c *CredentialParams) UseCredentialStore() bool

UseCredentialStore сhecks 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

Username 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
}

CredentialResolver 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(context.Background(), config);
	credentialResolver.SetReferences(context.Background(), references);

	cred, err := credentialResolver.Lookup(context.Background(), "123");
	// Now use credential...

func NewCredentialResolver

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

NewCredentialResolver creates a new instance of credentials resolver.

Parameters:
	- ctx context.Context
	- config *config.ConfigParams component configuration parameters
	- references refer.IReferences component references
Returns: *CredentialResolver

func NewEmptyCredentialResolver

func NewEmptyCredentialResolver() *CredentialResolver

NewEmptyCredentialResolver creates a new instance of credentials resolver.

Returns: *CredentialResolver

func (*CredentialResolver) Add

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

Add a new credential to component credentials

Parameters:
	- credential *CredentialParams new credential parameters to be added

func (*CredentialResolver) Configure

func (c *CredentialResolver) Configure(ctx context.Context, config *config.ConfigParams)

Configure configures component by passing configuration parameters.

Parameters:
	- config *config.ConfigParams configuration parameters to be set.

func (*CredentialResolver) GetAll

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

GetAll 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(ctx context.Context, correlationId string) (*CredentialParams, error)

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

Parameters:
	- ctx context.Context
	- correlationId string (optional) transaction id to trace execution through call chain.
Returns: *CredentialParams? error

func (*CredentialResolver) SetReferences

func (c *CredentialResolver) SetReferences(ctx context.Context, references refer.IReferences)

SetReferences sets references to dependent components.

Parameters:
	- references refer.IReferences references to locate the component dependencies.

type ICredentialStore

type ICredentialStore interface {
	// Store stores credential parameters into the store.
	Store(ctx context.Context, correlationId string, key string, credential *CredentialParams) error

	// Lookup lookups credential parameters by its key.
	Lookup(ctx context.Context, correlationId string, key string) (*CredentialParams, error)
}

ICredentialStore 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
}

MemoryCredentialStore 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(context.Backgroudn(), "123", "key1");

func NewEmptyMemoryCredentialStore

func NewEmptyMemoryCredentialStore() *MemoryCredentialStore

NewEmptyMemoryCredentialStore creates a new instance of the credential store.

Returns: *MemoryCredentialStore

func NewMemoryCredentialStore

func NewMemoryCredentialStore(ctx context.Context, config *config.ConfigParams) *MemoryCredentialStore

NewMemoryCredentialStore creates a new instance of the credential store.

Parameters:
	- ctx context.Context
	- config *config.ConfigParams configuration with credential parameters.
Returns: *MemoryCredentialStore

func (*MemoryCredentialStore) Configure

func (c *MemoryCredentialStore) Configure(ctx context.Context, config *config.ConfigParams)

Configure configures component by passing configuration parameters.

Parameters:
	- config *config.ConfigParams configuration parameters to be set.

func (*MemoryCredentialStore) Lookup

func (c *MemoryCredentialStore) Lookup(ctx context.Context, correlationId string,
	key string) (result *CredentialParams, err error)

Lookup credential parameters by its key.

Parameters:
	- ctx context.Context.
	- correlationId string transaction id to trace execution through call chain.
	- key string a key to uniquely identify the credential parameters.
Returns: result *CredentialParams, err error result of lookup and error message

func (*MemoryCredentialStore) ReadCredentials

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

ReadCredentials 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(ctx context.Context, correlationId string, key string,
	credential *CredentialParams) error

Store credential parameters into the store.

Parameters:
	- ctx context.Context.
	- 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.
Returns: error

Jump to

Keyboard shortcuts

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