UNPKG

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