UNPKG

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