UNPKG

2.79 kBTypeScriptView Raw
1import { ConfigParams } from 'pip-services3-commons-node';
2import { IReconfigurable } from 'pip-services3-commons-node';
3import { CredentialParams } from './CredentialParams';
4import { ICredentialStore } from './ICredentialStore';
5/**
6 * Credential store that keeps credentials in memory.
7 *
8 * ### Configuration parameters ###
9 *
10 * - [credential key 1]:
11 * - ... credential parameters for key 1
12 * - [credential key 2]:
13 * - ... credential parameters for key N
14 * - ...
15 *
16 * @see [[ICredentialStore]]
17 * @see [[CredentialParams]]
18 *
19 * ### Example ###
20 *
21 * let config = ConfigParams.fromTuples(
22 * "key1.user", "jdoe",
23 * "key1.pass", "pass123",
24 * "key2.user", "bsmith",
25 * "key2.pass", "mypass"
26 * );
27 *
28 * let credentialStore = new MemoryCredentialStore();
29 * credentialStore.readCredentials(config);
30 *
31 * credentialStore.lookup("123", "key1", (err, credential) => {
32 * // Result: user=jdoe;pass=pass123
33 * });
34 */
35export declare class MemoryCredentialStore implements ICredentialStore, IReconfigurable {
36 private _items;
37 /**
38 * Creates a new instance of the credential store.
39 *
40 * @param config (optional) configuration with credential parameters.
41 */
42 constructor(config?: ConfigParams);
43 /**
44 * Configures component by passing configuration parameters.
45 *
46 * @param config configuration parameters to be set.
47 */
48 configure(config: ConfigParams): void;
49 /**
50 * Reads credentials from configuration parameters.
51 * Each section represents an individual CredentialParams
52 *
53 * @param config configuration parameters to be read
54 */
55 readCredentials(config: ConfigParams): void;
56 /**
57 * Stores credential parameters into the store.
58 *
59 * @param correlationId (optional) transaction id to trace execution through call chain.
60 * @param key a key to uniquely identify the credential parameters.
61 * @param credential a credential parameters to be stored.
62 * @param callback callback function that receives an error or null for success.
63 */
64 store(correlationId: string, key: string, credential: CredentialParams, callback: (err: any) => void): void;
65 /**
66 * Lookups credential parameters by its key.
67 *
68 * @param correlationId (optional) transaction id to trace execution through call chain.
69 * @param key a key to uniquely identify the credential parameters.
70 * @param callback callback function that receives found credential parameters or error.
71 */
72 lookup(correlationId: string, key: string, callback: (err: any, result: CredentialParams) => void): void;
73}