1 |
|
2 |
|
3 |
|
4 | import * as childProcess from 'child_process';
|
5 | import * as nodeFs from 'fs';
|
6 | import { Nullable } from '@salesforce/ts-types';
|
7 | export type FsIfc = Pick<typeof nodeFs, 'statSync'>;
|
8 |
|
9 |
|
10 |
|
11 | export interface PasswordStore {
|
12 | |
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | getPassword(opts: ProgramOpts, fn: (error: Nullable<Error>, password?: string) => void, retryCount?: number): Promise<void>;
|
20 | |
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | setPassword(opts: ProgramOpts, fn: (error: Nullable<Error>, contents?: SecretContents) => void): Promise<void>;
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 | export declare class KeychainAccess implements PasswordStore {
|
32 | private osImpl;
|
33 | private fsIfc;
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | constructor(osImpl: OsImpl, fsIfc: FsIfc);
|
41 | /**
|
42 | * Validates the os level program is executable.
|
43 | */
|
44 | validateProgram(): Promise<void>;
|
45 | /**
|
46 | * Returns a password using the native program for credential management.
|
47 | *
|
48 | * @param opts Options for the credential lookup.
|
49 | * @param fn Callback function (err, password).
|
50 | * @param retryCount Used internally to track the number of retries for getting a password out of the keychain.
|
51 | */
|
52 | getPassword(opts: ProgramOpts, fn: (error: Nullable<Error>, password?: string) => void, retryCount?: number): Promise<void>;
|
53 | /**
|
54 | * Sets a password using the native program for credential management.
|
55 | *
|
56 | * @param opts Options for the credential lookup.
|
57 | * @param fn Callback function (err, ConfigContents).
|
58 | */
|
59 | setPassword(opts: ProgramOpts, fn: (error: Nullable<Error>, contents?: SecretContents) => void): Promise<void>;
|
60 | }
|
61 | interface ProgramOpts {
|
62 | account: string;
|
63 | service: string;
|
64 | password?: string;
|
65 | }
|
66 | interface OsImpl {
|
67 | getProgram(): string;
|
68 | getProgramOptions(opts: ProgramOpts): string[];
|
69 | getCommandFunc(opts: ProgramOpts, fn: (program: string, opts: string[]) => childProcess.ChildProcess): childProcess.ChildProcess;
|
70 | onGetCommandClose(code: number, stdout: string, stderr: string, opts: ProgramOpts, fn: (err: Nullable<Error>, result?: string) => void): Promise<void>;
|
71 | setProgramOptions(opts: ProgramOpts): string[];
|
72 | setCommandFunc(opts: ProgramOpts, fn: (program: string, opts: string[]) => childProcess.ChildProcess): childProcess.ChildProcess;
|
73 | onSetCommandClose(code: number, stdout: string, stderr: string, opts: ProgramOpts, fn: (err: Nullable<Error>) => void): Promise<void>;
|
74 | }
|
75 | declare enum SecretField {
|
76 | SERVICE = "service",
|
77 | ACCOUNT = "account",
|
78 | KEY = "key"
|
79 | }
|
80 | type SecretContents = {
|
81 | [SecretField.ACCOUNT]: string;
|
82 | [SecretField.KEY]?: string;
|
83 | [SecretField.SERVICE]: string;
|
84 | };
|
85 |
|
86 |
|
87 |
|
88 | export declare class GenericKeychainAccess implements PasswordStore {
|
89 | getPassword(opts: ProgramOpts, fn: (error: Nullable<Error>, password?: string) => void): Promise<void>;
|
90 | setPassword(opts: ProgramOpts, fn: (error: Nullable<Error>, contents?: SecretContents) => void): Promise<void>;
|
91 | protected isValidFileAccess(cb: (error: Nullable<NodeJS.ErrnoException>) => Promise<void>): Promise<void>;
|
92 | }
|
93 |
|
94 |
|
95 |
|
96 | export declare class GenericUnixKeychainAccess extends GenericKeychainAccess {
|
97 | protected isValidFileAccess(cb: (error: Nullable<Error>) => Promise<void>): Promise<void>;
|
98 | }
|
99 |
|
100 |
|
101 |
|
102 | export declare class GenericWindowsKeychainAccess extends GenericKeychainAccess {
|
103 | protected isValidFileAccess(cb: (error: Nullable<Error>) => Promise<void>): Promise<void>;
|
104 | }
|
105 |
|
106 |
|
107 |
|
108 | export declare const keyChainImpl: {
|
109 | generic_unix: GenericUnixKeychainAccess;
|
110 | generic_windows: GenericWindowsKeychainAccess;
|
111 | darwin: KeychainAccess;
|
112 | linux: KeychainAccess;
|
113 | validateProgram: (programPath: string, fsIfc: FsIfc, isExeIfc: (mode: number, gid: number, uid: number) => boolean) => Promise<void>;
|
114 | };
|
115 | export type KeyChain = GenericUnixKeychainAccess | GenericWindowsKeychainAccess | KeychainAccess;
|
116 | export {};
|