1 | import { ConfigParams } from 'pip-services3-commons-node';
|
2 | import { IReferences } from 'pip-services3-commons-node';
|
3 | import { CredentialParams } from './CredentialParams';
|
4 | /**
|
5 | * Helper class to retrieve component credentials.
|
6 | *
|
7 | * If credentials are configured to be retrieved from [[ICredentialStore]],
|
8 | * it automatically locates [[ICredentialStore]] in component references
|
9 | * and retrieve credentials from there using store_key parameter.
|
10 | *
|
11 | * ### Configuration parameters ###
|
12 | *
|
13 | * __credential:__
|
14 | * - store_key: (optional) a key to retrieve the credentials from [[ICredentialStore]]
|
15 | * - ... other credential parameters
|
16 | *
|
17 | * __credentials:__ alternative to credential
|
18 | * - [credential params 1]: first credential parameters
|
19 | * - ... credential parameters for key 1
|
20 | * - ...
|
21 | * - [credential params N]: Nth credential parameters
|
22 | * - ... credential parameters for key N
|
23 | *
|
24 | * ### References ###
|
25 | *
|
26 | * - <code>\*:credential-store:\*:\*:1.0</code> (optional) Credential stores to resolve credentials
|
27 | *
|
28 | * @see [[CredentialParams]]
|
29 | * @see [[ICredentialStore]]
|
30 | *
|
31 | * ### Example ###
|
32 | *
|
33 | * let config = ConfigParams.fromTuples(
|
34 | * "credential.user", "jdoe",
|
35 | * "credential.pass", "pass123"
|
36 | * );
|
37 | *
|
38 | * let credentialResolver = new CredentialResolver();
|
39 | * credentialResolver.configure(config);
|
40 | * credentialResolver.setReferences(references);
|
41 | *
|
42 | * credentialResolver.lookup("123", (err, credential) => {
|
43 | * // Now use credential...
|
44 | * });
|
45 | *
|
46 | */
|
47 | export declare class CredentialResolver {
|
48 | private readonly _credentials;
|
49 | private _references;
|
50 | /**
|
51 | * Creates a new instance of credentials resolver.
|
52 | *
|
53 | * @param config (optional) component configuration parameters
|
54 | * @param references (optional) component references
|
55 | */
|
56 | constructor(config?: ConfigParams, references?: IReferences);
|
57 | /**
|
58 | * Configures component by passing configuration parameters.
|
59 | *
|
60 | * @param config configuration parameters to be set.
|
61 | */
|
62 | configure(config: ConfigParams): void;
|
63 | /**
|
64 | * Sets references to dependent components.
|
65 | *
|
66 | * @param references references to locate the component dependencies.
|
67 | */
|
68 | setReferences(references: IReferences): void;
|
69 | /**
|
70 | * Gets all credentials configured in component configuration.
|
71 | *
|
72 | * Redirect to CredentialStores is not done at this point.
|
73 | * If you need fully fleshed credential use [[lookup]] method instead.
|
74 | *
|
75 | * @returns a list with credential parameters
|
76 | */
|
77 | getAll(): CredentialParams[];
|
78 | /**
|
79 | * Adds a new credential to component credentials
|
80 | *
|
81 | * @param credential new credential parameters to be added
|
82 | */
|
83 | add(credential: CredentialParams): void;
|
84 | private lookupInStores;
|
85 | /**
|
86 | * Looks up component credential parameters. If credentials are configured to be retrieved
|
87 | * from Credential store it finds a [[ICredentialStore]] and lookups credentials there.
|
88 | *
|
89 | * @param correlationId (optional) transaction id to trace execution through call chain.
|
90 | * @param callback callback function that receives resolved credential or error.
|
91 | */
|
92 | lookup(correlationId: string, callback: (err: any, result: CredentialParams) => void): void;
|
93 | }
|