CredentialResolver

Helper class used to retrieve component credentials.

Description

The CredentialResolver class is used to retrieve component credentials.

Important points

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

Configuration parameters

credential:

  • store_key: (optional) 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

Constructors

NewCredentialResolver

Creates a new instance of credentials resolver.

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

NewEmptyCredentialResolver

Creates a new instance of credentials resolver.

NewEmptyCredentialResolver() *CredentialResolver

Methods

Add

Adds a new credential to a credential component.

(c *CredentialResolver) Add(credential *CredentialParams)

Configure

Configures component by passing configuration parameters.

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

  • ctx: context.Context - operation context.
  • config: *config.ConfigParams - configuration parameters to be set.

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.

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

Lookup

Looks up component’s credential parameters. If credentials are configured to be retrieved from a credential store it finds a ICredentialStore` and lookups the credentials there.

(c *CredentialResolver) Lookup(ctx context.Context, Lookup(context IContext) (*CredentialParams, error)

  • ctx: context.Context - operation context.
  • context: IContext - (optional) a context to trace execution through a call chain.
  • returns: (*CredentialParams, error) - resolved credential parameters or nil if nothing was found.

SetReferences

Sets references to dependent components.

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

  • ctx: context.Context - operation context.
  • references: refer.IReferences - references to locate the component dependencies.

Examples

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

See also