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(correlationId string) (*CredentialParams, error)

  • ctx: context.Context - operation context.
  • correlationId: string - (optional) transaction id used to trace execution through the 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