@contrail/cli 3.8.0-alpha.a026035 → 3.8.0-alpha.ca28651
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +307 -80
- package/dist/auth/login.js +3 -1
- package/dist/auth/login.spec.js +22 -0
- package/dist/baseFlags.d.ts +4 -0
- package/dist/baseFlags.js +9 -1
- package/dist/basecommand.d.ts +7 -0
- package/dist/basecommand.js +17 -2
- package/dist/basecommand.spec.d.ts +1 -0
- package/dist/basecommand.spec.js +97 -0
- package/dist/commands/app/create.d.ts +1 -0
- package/dist/commands/app/delete.d.ts +1 -0
- package/dist/commands/app/extension/deploy.d.ts +1 -0
- package/dist/commands/app/extension/deployment/list.d.ts +1 -0
- package/dist/commands/app/getApiKey.d.ts +1 -0
- package/dist/commands/app/init.d.ts +1 -0
- package/dist/commands/app/install.d.ts +1 -0
- package/dist/commands/app/publish.d.ts +1 -0
- package/dist/commands/app/uninstall.d.ts +1 -0
- package/dist/commands/app/upgrade.d.ts +1 -0
- package/dist/commands/app/version/major.d.ts +1 -0
- package/dist/commands/app/version/minor.d.ts +1 -0
- package/dist/commands/app/version/patch.d.ts +1 -0
- package/dist/commands/app/version/premajor.d.ts +12 -0
- package/dist/commands/app/version/premajor.js +32 -0
- package/dist/commands/app/version/preminor.d.ts +12 -0
- package/dist/commands/app/version/preminor.js +32 -0
- package/dist/commands/app/version/prepatch.d.ts +12 -0
- package/dist/commands/app/version/prepatch.js +32 -0
- package/dist/commands/app/version/prerelease.d.ts +1 -0
- package/dist/commands/config/create.d.ts +3 -3
- package/dist/commands/config/create.js +2 -3
- package/dist/commands/config/describe.d.ts +3 -3
- package/dist/commands/config/describe.js +8 -7
- package/dist/commands/config/list.d.ts +3 -3
- package/dist/commands/config/list.js +10 -6
- package/dist/commands/config/set.d.ts +2 -3
- package/dist/commands/config/set.js +12 -9
- package/dist/commands/config/use.d.ts +3 -3
- package/dist/commands/config/use.js +5 -3
- package/dist/commands/entities/create.d.ts +1 -0
- package/dist/commands/entities/delete.d.ts +1 -0
- package/dist/commands/entities/get.d.ts +1 -0
- package/dist/commands/entities/update.d.ts +1 -0
- package/dist/commands/feature-flags/export.d.ts +1 -0
- package/dist/commands/feature-flags/import.d.ts +1 -0
- package/dist/commands/file/upload.d.ts +1 -0
- package/dist/commands/groups/export.d.ts +1 -0
- package/dist/commands/groups/import.d.ts +1 -0
- package/dist/commands/instance/export.d.ts +1 -0
- package/dist/commands/instance/import.d.ts +1 -0
- package/dist/commands/load/colors.d.ts +1 -0
- package/dist/commands/load/custom-entity.d.ts +1 -0
- package/dist/commands/load/line-sheet.d.ts +1 -0
- package/dist/commands/load/upload-and-load.d.ts +1 -0
- package/dist/commands/load-local/index.d.ts +1 -0
- package/dist/commands/login.d.ts +1 -0
- package/dist/commands/org-config/export.d.ts +1 -0
- package/dist/commands/org-config/import.d.ts +1 -0
- package/dist/commands/projects/export.d.ts +1 -0
- package/dist/commands/projects/list.d.ts +1 -0
- package/dist/commands/projects/load.d.ts +1 -0
- package/dist/commands/types/exportOptionSetHierarchies.d.ts +1 -0
- package/dist/commands/types/getAll.d.ts +1 -0
- package/dist/commands/types/getOptionSets.d.ts +1 -0
- package/dist/commands/types/loadAll.d.ts +1 -0
- package/dist/commands/types/mergeOptionSets.d.ts +1 -0
- package/dist/commands/types/mergeTypeProperties.d.ts +1 -0
- package/dist/commands/types/parseOptionSetsHierarchyLocalFile.d.ts +1 -0
- package/dist/commands/types/parseOptionSetsHierarchyValuesToKeysLocalFile.d.ts +1 -0
- package/dist/commands/types/parseOptionSetsLocalFiles.d.ts +1 -0
- package/dist/commands/types/parseOptionSetsToFolderStructure.d.ts +1 -0
- package/dist/commands/types/parseTypesFromFiles.d.ts +1 -0
- package/dist/commands/types/parseTypesFromLocalFiles.d.ts +1 -0
- package/dist/commands/types/parseTypesFromTemplateAndDataFromLocalFiles.d.ts +1 -0
- package/dist/commands/types/parseTypesFromTemplateFromLocalFiles.d.ts +1 -0
- package/dist/commands/types/uploadOptionSetHierarchies.d.ts +1 -0
- package/dist/commands/types/uploadOptionSets.d.ts +1 -0
- package/dist/commands/types/uploadOptionSetsHierarchyLocalFile.d.ts +1 -0
- package/dist/commands/types/uploadRuleSets.d.ts +1 -0
- package/dist/commands/types/uploadTypeOverrides.d.ts +1 -0
- package/dist/commands/types/uploadTypePolicies.d.ts +1 -0
- package/dist/commands/types/uploadTypePropertyPolicies.d.ts +1 -0
- package/dist/commands/types/uploadTypes.d.ts +1 -0
- package/dist/commands/users/export.d.ts +1 -0
- package/dist/commands/users/import.d.ts +1 -0
- package/dist/commands/webhooks/create.d.ts +1 -0
- package/dist/commands/webhooks/delete.d.ts +1 -0
- package/dist/commands/webhooks/getWebhookTrigger.d.ts +1 -0
- package/dist/commands/webhooks/list.d.ts +1 -0
- package/dist/commands/workflow-template-definitions/install.d.ts +1 -0
- package/dist/commands/workflow-template-definitions/list.d.ts +1 -0
- package/dist/commands/workflow-templates/delete.d.ts +1 -0
- package/dist/commands/workflow-templates/export.d.ts +1 -0
- package/dist/commands/workflow-templates/list.d.ts +1 -0
- package/dist/commands/workflow-templates/load.d.ts +1 -0
- package/dist/helpers/app/upgrade-version.d.ts +5 -1
- package/dist/helpers/app/upgrade-version.js +6 -2
- package/dist/helpers/app/upgrade-version.spec.js +11 -0
- package/dist/helpers/config/config.d.ts +11 -2
- package/dist/helpers/config/config.js +73 -40
- package/dist/helpers/config/config.spec.d.ts +1 -0
- package/dist/helpers/config/config.spec.js +104 -0
- package/dist/helpers/config/redact-tokens.d.ts +1 -0
- package/dist/helpers/config/redact-tokens.js +14 -0
- package/dist/helpers/config/redact-tokens.spec.d.ts +1 -0
- package/dist/helpers/config/redact-tokens.spec.js +24 -0
- package/dist/interfaces.d.ts +1 -0
- package/oclif.manifest.json +678 -12
- package/package.json +1 -1
|
@@ -3,6 +3,7 @@ export default class ImportUsers extends BaseCommand {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
7
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
9
|
};
|
|
@@ -4,6 +4,7 @@ export default class CreateWebhooks extends BaseCommand {
|
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
6
|
json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
9
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
10
|
};
|
|
@@ -4,6 +4,7 @@ export default class DeleteWebhooks extends BaseCommand {
|
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
6
|
json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
9
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
10
|
};
|
|
@@ -3,6 +3,7 @@ export default class GetWebhookTrigger extends BaseCommand {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
7
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
9
|
};
|
|
@@ -4,6 +4,7 @@ export default class ListWebhooks extends BaseCommand {
|
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
6
|
json: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
7
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
9
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
10
|
};
|
|
@@ -3,6 +3,7 @@ export default class InstallWorkflowTemplateDefinitions extends BaseCommand {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
7
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
9
|
};
|
|
@@ -3,6 +3,7 @@ export default class ListWorkflowTemplateDefinitions extends BaseCommand {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
7
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
9
|
};
|
|
@@ -3,6 +3,7 @@ export default class DeleteWorkflowTemplates extends BaseCommand {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
7
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
9
|
};
|
|
@@ -6,6 +6,7 @@ export default class ExportWorkflows extends BaseCommand {
|
|
|
6
6
|
static flags: {
|
|
7
7
|
outFile: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
8
|
overwrite: import("@oclif/core/lib/interfaces").BooleanFlag<boolean>;
|
|
9
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
9
10
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
10
11
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
11
12
|
};
|
|
@@ -3,6 +3,7 @@ export default class ListWorkflowTemplates extends BaseCommand {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
7
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
9
|
};
|
|
@@ -3,6 +3,7 @@ export default class LoadWorkflowTemplates extends BaseCommand {
|
|
|
3
3
|
static description: string;
|
|
4
4
|
static examples: string[];
|
|
5
5
|
static flags: {
|
|
6
|
+
config: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
6
7
|
alwaysConfirmEnv: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
7
8
|
logLevel: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
8
9
|
};
|
|
@@ -3,9 +3,13 @@ import semver from 'semver';
|
|
|
3
3
|
* Upgrades a semantic version based on a specified release type.
|
|
4
4
|
*
|
|
5
5
|
* @param {string} currentVersion - The current semantic version string.
|
|
6
|
-
* @param {semver.ReleaseType} type - The type of release ('major', 'minor', 'patch', '
|
|
6
|
+
* @param {semver.ReleaseType} type - The type of release ('major', 'minor', 'patch', 'premajor',
|
|
7
|
+
* 'preminor', 'prepatch', 'prerelease').
|
|
7
8
|
* 'prerelease' starts an alpha (1.2.3 becomes 1.2.4-alpha.0) or bumps the existing pre-release tag
|
|
8
9
|
* (1.2.4-alpha.0 becomes 1.2.4-alpha.1).
|
|
10
|
+
* 'premajor', 'preminor' and 'prepatch' always start the first alpha of the next major, minor or
|
|
11
|
+
* patch version (1.2.3 becomes 2.0.0-alpha.0, 1.3.0-alpha.0 or 1.2.4-alpha.0). The results match
|
|
12
|
+
* `npm version <type> --preid=alpha`.
|
|
9
13
|
* @returns {string} The upgraded semantic version.
|
|
10
14
|
* @throws {Error} If the provided currentVersion is not a valid semantic version.
|
|
11
15
|
*
|
|
@@ -7,9 +7,13 @@ const semver_1 = tslib_1.__importDefault(require("semver"));
|
|
|
7
7
|
* Upgrades a semantic version based on a specified release type.
|
|
8
8
|
*
|
|
9
9
|
* @param {string} currentVersion - The current semantic version string.
|
|
10
|
-
* @param {semver.ReleaseType} type - The type of release ('major', 'minor', 'patch', '
|
|
10
|
+
* @param {semver.ReleaseType} type - The type of release ('major', 'minor', 'patch', 'premajor',
|
|
11
|
+
* 'preminor', 'prepatch', 'prerelease').
|
|
11
12
|
* 'prerelease' starts an alpha (1.2.3 becomes 1.2.4-alpha.0) or bumps the existing pre-release tag
|
|
12
13
|
* (1.2.4-alpha.0 becomes 1.2.4-alpha.1).
|
|
14
|
+
* 'premajor', 'preminor' and 'prepatch' always start the first alpha of the next major, minor or
|
|
15
|
+
* patch version (1.2.3 becomes 2.0.0-alpha.0, 1.3.0-alpha.0 or 1.2.4-alpha.0). The results match
|
|
16
|
+
* `npm version <type> --preid=alpha`.
|
|
13
17
|
* @returns {string} The upgraded semantic version.
|
|
14
18
|
* @throws {Error} If the provided currentVersion is not a valid semantic version.
|
|
15
19
|
*
|
|
@@ -27,7 +31,7 @@ function upgradeVersion(currentVersion, type) {
|
|
|
27
31
|
if (!semver_1.default.valid(paddedVersion)) {
|
|
28
32
|
throw new Error('Invalid version string');
|
|
29
33
|
}
|
|
30
|
-
return semver_1.default.inc(paddedVersion, type, semver_1.default.prerelease(paddedVersion) ? undefined : 'alpha');
|
|
34
|
+
return semver_1.default.inc(paddedVersion, type, type === 'prerelease' && semver_1.default.prerelease(paddedVersion) ? undefined : 'alpha');
|
|
31
35
|
}
|
|
32
36
|
catch (e) {
|
|
33
37
|
throw new Error(`ERROR PARSING YAML: ${e}`);
|
|
@@ -34,6 +34,17 @@ describe('upgradeVersion', () => {
|
|
|
34
34
|
it('should keep the existing pre-release tag when it is not alpha', () => {
|
|
35
35
|
expect((0, upgrade_version_1.upgradeVersion)('1.4.0-beta.1', 'prerelease')).toBe('1.4.0-beta.2');
|
|
36
36
|
});
|
|
37
|
+
it.each([
|
|
38
|
+
['premajor', '1.2.3', '2.0.0-alpha.0'],
|
|
39
|
+
['preminor', '1.2.3', '1.3.0-alpha.0'],
|
|
40
|
+
['prepatch', '1.2.3', '1.2.4-alpha.0'],
|
|
41
|
+
['premajor', '1.2.4-alpha.1', '2.0.0-alpha.0'],
|
|
42
|
+
['preminor', '1.2.4-alpha.1', '1.3.0-alpha.0'],
|
|
43
|
+
['prepatch', '1.2.4-alpha.1', '1.2.5-alpha.0'],
|
|
44
|
+
['premajor', '2.0.0-beta.1', '3.0.0-alpha.0'],
|
|
45
|
+
])('should apply %s to %s the way npm version does', (type, current, expected) => {
|
|
46
|
+
expect((0, upgrade_version_1.upgradeVersion)(current, type)).toBe(expected);
|
|
47
|
+
});
|
|
37
48
|
it('should pad a short version before upgrading it', () => {
|
|
38
49
|
expect((0, upgrade_version_1.upgradeVersion)('1.2', 'patch')).toBe('1.2.1');
|
|
39
50
|
});
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export declare class ConfigSelectionError extends Error {
|
|
2
|
+
readonly code: 'CONFIG_NOT_SELECTED' | 'CONFIG_NOT_FOUND';
|
|
3
|
+
constructor(code: 'CONFIG_NOT_SELECTED' | 'CONFIG_NOT_FOUND', message: string);
|
|
4
|
+
}
|
|
1
5
|
export declare const ENVIRONMENTS: {
|
|
2
6
|
dev: string;
|
|
3
7
|
prod: string;
|
|
@@ -9,9 +13,14 @@ export declare function readVibeIQConfig(): Promise<any>;
|
|
|
9
13
|
export declare function writeVibeIQConfig(config: any): Promise<void>;
|
|
10
14
|
export declare function storeVibeIQConfig(incomingConfig: any): Promise<void>;
|
|
11
15
|
export declare function createConfig(fileName: any): Promise<void>;
|
|
12
|
-
export declare function
|
|
16
|
+
export declare function selectConfigForRun({ requestedName, nameInUse, }: {
|
|
17
|
+
requestedName: string | undefined;
|
|
18
|
+
nameInUse: string | undefined;
|
|
19
|
+
}): void;
|
|
20
|
+
export declare function fetchConfigNameForRun(): Promise<string>;
|
|
13
21
|
export declare function getConfig(): Promise<any>;
|
|
14
|
-
export declare function
|
|
22
|
+
export declare function clearStoredApiKey(): Promise<void>;
|
|
23
|
+
export declare function storeConfig(incomingConfig: any): Promise<void>;
|
|
15
24
|
export declare function getConfigFiles(): Promise<any>;
|
|
16
25
|
export declare function getConfigContent(fileName: string): Promise<any>;
|
|
17
26
|
export declare function validateEnvironments(envName?: string | null): Promise<any>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkTelemetry = exports.validateEnvironments = exports.getConfigContent = exports.getConfigFiles = exports.storeConfig = exports.getConfig = exports.
|
|
3
|
+
exports.checkTelemetry = exports.validateEnvironments = exports.getConfigContent = exports.getConfigFiles = exports.storeConfig = exports.clearStoredApiKey = exports.getConfig = exports.fetchConfigNameForRun = exports.selectConfigForRun = exports.createConfig = exports.storeVibeIQConfig = exports.writeVibeIQConfig = exports.readVibeIQConfig = exports.initializeVibeIQConfig = exports.findEnvironmentName = exports.ENVIRONMENTS = exports.ConfigSelectionError = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const node_fs_1 = require("node:fs");
|
|
6
6
|
const node_path_1 = require("node:path");
|
|
7
7
|
const node_os_1 = require("node:os");
|
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
|
8
9
|
const logger_1 = tslib_1.__importDefault(require("../../logger"));
|
|
9
10
|
const configFileName = 'config.json';
|
|
10
11
|
const defaultConfigFileName = 'default.json';
|
|
@@ -12,6 +13,18 @@ const userHomeDir = (0, node_os_1.homedir)();
|
|
|
12
13
|
const configDirectoryLocation = (0, node_path_1.join)(userHomeDir, '.vibeiq', 'configs');
|
|
13
14
|
const configFileLocation = (0, node_path_1.join)(configDirectoryLocation, configFileName);
|
|
14
15
|
const defaultConfigFileLocation = (0, node_path_1.join)(configDirectoryLocation, defaultConfigFileName);
|
|
16
|
+
class ConfigSelectionError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
constructor(code, message) {
|
|
19
|
+
super(message);
|
|
20
|
+
this.code = code;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.ConfigSelectionError = ConfigSelectionError;
|
|
24
|
+
let hasSelectedConfig = false;
|
|
25
|
+
let requestedConfigName;
|
|
26
|
+
let configNameInUse;
|
|
27
|
+
let configNameForRun;
|
|
15
28
|
exports.ENVIRONMENTS = {
|
|
16
29
|
dev: 'https://api.dev.vibeiq.com/dev/api',
|
|
17
30
|
prod: 'https://api.vibeiq.com/prod/api',
|
|
@@ -34,8 +47,8 @@ async function initializeVibeIQConfig() {
|
|
|
34
47
|
configInUse: (0, node_path_1.parse)(defaultConfigFileName).name,
|
|
35
48
|
logLevel: 'debug',
|
|
36
49
|
};
|
|
37
|
-
await
|
|
38
|
-
await
|
|
50
|
+
await writeFileAtomically(configFileLocation, JSON.stringify(config, null, 2));
|
|
51
|
+
await writeFileAtomically(defaultConfigFileLocation, '{}');
|
|
39
52
|
}
|
|
40
53
|
catch (error) {
|
|
41
54
|
logger_1.default.error(`could not initialize config file (${configFileLocation}).`);
|
|
@@ -64,7 +77,7 @@ async function readVibeIQConfig() {
|
|
|
64
77
|
exports.readVibeIQConfig = readVibeIQConfig;
|
|
65
78
|
async function writeVibeIQConfig(config) {
|
|
66
79
|
try {
|
|
67
|
-
await
|
|
80
|
+
await writeFileAtomically(configFileLocation, JSON.stringify(config, null, 2));
|
|
68
81
|
}
|
|
69
82
|
catch (error) {
|
|
70
83
|
logger_1.default.error(`Could not open config file (${configFileLocation}) for writing.`);
|
|
@@ -82,7 +95,7 @@ async function storeVibeIQConfig(incomingConfig) {
|
|
|
82
95
|
exports.storeVibeIQConfig = storeVibeIQConfig;
|
|
83
96
|
async function createConfig(fileName) {
|
|
84
97
|
try {
|
|
85
|
-
await
|
|
98
|
+
await writeFileAtomically((0, node_path_1.join)(configDirectoryLocation, `${fileName}.json`), '{}');
|
|
86
99
|
}
|
|
87
100
|
catch (error) {
|
|
88
101
|
logger_1.default.error('Could not create config file.');
|
|
@@ -90,59 +103,79 @@ async function createConfig(fileName) {
|
|
|
90
103
|
}
|
|
91
104
|
}
|
|
92
105
|
exports.createConfig = createConfig;
|
|
93
|
-
async function writeConfig(config, configName
|
|
106
|
+
async function writeConfig(config, configName) {
|
|
94
107
|
try {
|
|
95
|
-
|
|
96
|
-
if (!configName) {
|
|
97
|
-
const fileContent = await readVibeIQConfig();
|
|
98
|
-
configFileName = fileContent.configInUse;
|
|
99
|
-
}
|
|
100
|
-
await node_fs_1.promises.writeFile((0, node_path_1.join)(configDirectoryLocation, `${configFileName}.json`), JSON.stringify(config, null, 2));
|
|
108
|
+
await writeFileAtomically((0, node_path_1.join)(configDirectoryLocation, `${configName}.json`), JSON.stringify(config, null, 2));
|
|
101
109
|
}
|
|
102
110
|
catch (error) {
|
|
103
111
|
logger_1.default.error('Could not open config file for writing.');
|
|
104
112
|
throw error;
|
|
105
113
|
}
|
|
106
114
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
fileContent = (await node_fs_1.promises.readFile(configFileLocation)).toString();
|
|
115
|
+
function selectConfigForRun({ requestedName, nameInUse, }) {
|
|
116
|
+
hasSelectedConfig = true;
|
|
117
|
+
requestedConfigName = requestedName;
|
|
118
|
+
configNameInUse = nameInUse;
|
|
119
|
+
configNameForRun = undefined;
|
|
120
|
+
}
|
|
121
|
+
exports.selectConfigForRun = selectConfigForRun;
|
|
122
|
+
function fetchConfigNameForRun() {
|
|
123
|
+
if (!hasSelectedConfig) {
|
|
124
|
+
return Promise.reject(new Error('No config selected for this run. Call selectConfigForRun before reading a config.'));
|
|
118
125
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
126
|
+
configNameForRun ??= fetchConfigNameFromFlagOrPointer();
|
|
127
|
+
return configNameForRun;
|
|
128
|
+
}
|
|
129
|
+
exports.fetchConfigNameForRun = fetchConfigNameForRun;
|
|
130
|
+
async function fetchConfigNameFromFlagOrPointer() {
|
|
131
|
+
if (!requestedConfigName) {
|
|
132
|
+
if (!configNameInUse) {
|
|
133
|
+
throw new ConfigSelectionError('CONFIG_NOT_SELECTED', 'No config selected. Pass --config, set CONTRAIL_CLI_CONFIG, or run `contrail config use`.');
|
|
134
|
+
}
|
|
135
|
+
return configNameInUse;
|
|
122
136
|
}
|
|
123
|
-
|
|
124
|
-
|
|
137
|
+
const configNames = (await getConfigFiles()) ?? [];
|
|
138
|
+
if (!configNames.includes(requestedConfigName)) {
|
|
139
|
+
throw new ConfigSelectionError('CONFIG_NOT_FOUND', `No config named "${requestedConfigName}". Create it with \`contrail config create --name ${requestedConfigName}\`, or pass --config or set CONTRAIL_CLI_CONFIG to one of: ${configNames.join(', ')}`);
|
|
125
140
|
}
|
|
141
|
+
return requestedConfigName;
|
|
142
|
+
}
|
|
143
|
+
async function getConfig() {
|
|
144
|
+
return getConfigContent(await fetchConfigNameForRun());
|
|
126
145
|
}
|
|
127
146
|
exports.getConfig = getConfig;
|
|
128
|
-
async function
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
147
|
+
async function clearStoredApiKey() {
|
|
148
|
+
const configName = await fetchConfigNameForRun();
|
|
149
|
+
const config = await getConfigContent(configName);
|
|
150
|
+
if (config?.signInMethod !== 'apiKey') {
|
|
151
|
+
return;
|
|
132
152
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
153
|
+
delete config.apiUserToken;
|
|
154
|
+
delete config.apiRefreshToken;
|
|
155
|
+
delete config.signInMethod;
|
|
156
|
+
await writeConfig(config, configName);
|
|
157
|
+
}
|
|
158
|
+
exports.clearStoredApiKey = clearStoredApiKey;
|
|
159
|
+
async function storeConfig(incomingConfig) {
|
|
160
|
+
const configName = await fetchConfigNameForRun();
|
|
161
|
+
const config = {
|
|
162
|
+
...(await getConfigContent(configName)),
|
|
138
163
|
...incomingConfig,
|
|
139
164
|
};
|
|
140
|
-
if (!merge) {
|
|
141
|
-
config = incomingConfig;
|
|
142
|
-
}
|
|
143
165
|
await writeConfig(config, configName);
|
|
144
166
|
}
|
|
145
167
|
exports.storeConfig = storeConfig;
|
|
168
|
+
async function writeFileAtomically(path, content) {
|
|
169
|
+
const tempPath = `${path}.${(0, node_crypto_1.randomUUID)()}.tmp`;
|
|
170
|
+
try {
|
|
171
|
+
await node_fs_1.promises.writeFile(tempPath, content, { mode: 0o600 });
|
|
172
|
+
await node_fs_1.promises.rename(tempPath, path);
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
await node_fs_1.promises.rm(tempPath, { force: true });
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
146
179
|
async function getConfigFiles() {
|
|
147
180
|
try {
|
|
148
181
|
const dirContent = (await node_fs_1.promises.readdir(configDirectoryLocation, { withFileTypes: true }))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const fs_1 = require("fs");
|
|
4
|
+
const os_1 = require("os");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
let mockHome;
|
|
7
|
+
jest.mock('node:os', () => ({
|
|
8
|
+
...jest.requireActual('node:os'),
|
|
9
|
+
homedir: () => mockHome,
|
|
10
|
+
}));
|
|
11
|
+
jest.mock('../../logger', () => ({
|
|
12
|
+
__esModule: true,
|
|
13
|
+
default: { debug: jest.fn(), info: jest.fn(), warn: jest.fn(), error: jest.fn() },
|
|
14
|
+
}));
|
|
15
|
+
const DEV = { apiGateway: 'https://api.dev.vibeiq.com/dev/api', orgSlug: 'adam-zone-1' };
|
|
16
|
+
const PROD = { apiGateway: 'https://api.vibeiq.com/prod/api', orgSlug: 'adam-prod-1' };
|
|
17
|
+
describe('config selection', () => {
|
|
18
|
+
let configDir;
|
|
19
|
+
let config;
|
|
20
|
+
const writeJson = (name, content) => (0, fs_1.writeFileSync)((0, path_1.join)(configDir, `${name}.json`), JSON.stringify(content));
|
|
21
|
+
const readJson = (name) => JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(configDir, `${name}.json`)).toString());
|
|
22
|
+
const switchPointerTo = (name) => writeJson('config', { configInUse: name });
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
mockHome = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'contrail-cli-config-'));
|
|
25
|
+
configDir = (0, path_1.join)(mockHome, '.vibeiq', 'configs');
|
|
26
|
+
(0, fs_1.mkdirSync)(configDir, { recursive: true });
|
|
27
|
+
writeJson('dev', DEV);
|
|
28
|
+
writeJson('prod', PROD);
|
|
29
|
+
switchPointerTo('dev');
|
|
30
|
+
jest.isolateModules(() => {
|
|
31
|
+
config = require('./config');
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
afterEach(() => {
|
|
35
|
+
jest.restoreAllMocks();
|
|
36
|
+
(0, fs_1.rmSync)(mockHome, { recursive: true, force: true });
|
|
37
|
+
});
|
|
38
|
+
it('should use the config chosen with config use when none is named', async () => {
|
|
39
|
+
config.selectConfigForRun({ requestedName: undefined, nameInUse: 'dev' });
|
|
40
|
+
expect(await config.getConfig()).toEqual(DEV);
|
|
41
|
+
});
|
|
42
|
+
it('should fail when a config is read before one is selected for the run', async () => {
|
|
43
|
+
await expect(config.getConfig()).rejects.toThrow('No config selected for this run.');
|
|
44
|
+
});
|
|
45
|
+
it('should use the named config over the one chosen with config use', async () => {
|
|
46
|
+
config.selectConfigForRun({ requestedName: 'prod', nameInUse: 'dev' });
|
|
47
|
+
expect(await config.getConfig()).toEqual(PROD);
|
|
48
|
+
});
|
|
49
|
+
it('should keep reading and saving the config it started with after another terminal switches', async () => {
|
|
50
|
+
config.selectConfigForRun({ requestedName: undefined, nameInUse: 'dev' });
|
|
51
|
+
await config.getConfig();
|
|
52
|
+
switchPointerTo('prod');
|
|
53
|
+
await config.storeConfig({ apiUserToken: 'refreshed-dev-token' });
|
|
54
|
+
expect(await config.getConfig()).toEqual({ ...DEV, apiUserToken: 'refreshed-dev-token' });
|
|
55
|
+
expect(readJson('prod')).toEqual(PROD);
|
|
56
|
+
});
|
|
57
|
+
it('should fail when no config is named and none is chosen with config use', async () => {
|
|
58
|
+
config.selectConfigForRun({ requestedName: undefined, nameInUse: undefined });
|
|
59
|
+
await expect(config.getConfig()).rejects.toThrow('No config selected.');
|
|
60
|
+
});
|
|
61
|
+
it('should fail and list the configs when the named config does not exist', async () => {
|
|
62
|
+
config.selectConfigForRun({ requestedName: 'staging', nameInUse: 'dev' });
|
|
63
|
+
await expect(config.getConfig()).rejects.toThrow('No config named "staging". Create it with `contrail config create --name staging`, or pass --config or set CONTRAIL_CLI_CONFIG to one of: dev, prod');
|
|
64
|
+
});
|
|
65
|
+
it('should leave the previous config intact when a save dies partway', async () => {
|
|
66
|
+
config.selectConfigForRun({ requestedName: 'dev', nameInUse: 'dev' });
|
|
67
|
+
const realWriteFile = fs_1.promises.writeFile;
|
|
68
|
+
jest.spyOn(fs_1.promises, 'writeFile').mockImplementationOnce(async (path) => {
|
|
69
|
+
await realWriteFile(path, '{"apiGatew');
|
|
70
|
+
throw new Error('ENOSPC: no space left on device');
|
|
71
|
+
});
|
|
72
|
+
await expect(config.storeConfig({ apiUserToken: 'new-token' })).rejects.toThrow('ENOSPC');
|
|
73
|
+
expect(readJson('dev')).toEqual(DEV);
|
|
74
|
+
expect((0, fs_1.readdirSync)(configDir).filter((file) => file.endsWith('.tmp'))).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
it('should remove a stored API key and keep the org and environment', async () => {
|
|
77
|
+
writeJson('dev', {
|
|
78
|
+
...DEV,
|
|
79
|
+
apiUserToken: 'old-api-key',
|
|
80
|
+
apiRefreshToken: null,
|
|
81
|
+
signInMethod: 'apiKey',
|
|
82
|
+
});
|
|
83
|
+
config.selectConfigForRun({ requestedName: 'dev', nameInUse: 'dev' });
|
|
84
|
+
await config.clearStoredApiKey();
|
|
85
|
+
expect(readJson('dev')).toEqual(DEV);
|
|
86
|
+
});
|
|
87
|
+
it('should keep the tokens of a config that was not signed in with an API key', async () => {
|
|
88
|
+
const signedInWithSso = {
|
|
89
|
+
...DEV,
|
|
90
|
+
apiUserToken: 'access',
|
|
91
|
+
apiRefreshToken: 'refresh',
|
|
92
|
+
signInMethod: 'sso',
|
|
93
|
+
};
|
|
94
|
+
writeJson('dev', signedInWithSso);
|
|
95
|
+
config.selectConfigForRun({ requestedName: 'dev', nameInUse: 'dev' });
|
|
96
|
+
await config.clearStoredApiKey();
|
|
97
|
+
expect(readJson('dev')).toEqual(signedInWithSso);
|
|
98
|
+
});
|
|
99
|
+
it('should keep a saved config readable only by its owner', async () => {
|
|
100
|
+
config.selectConfigForRun({ requestedName: 'dev', nameInUse: 'dev' });
|
|
101
|
+
await config.storeConfig({ apiUserToken: 'new-token' });
|
|
102
|
+
expect((0, fs_1.statSync)((0, path_1.join)(configDir, 'dev.json')).mode & 0o777).toBe(0o600);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function redactTokens(config: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.redactTokens = void 0;
|
|
4
|
+
const TOKEN_FIELDS = ['apiUserToken', 'apiRefreshToken'];
|
|
5
|
+
function redactTokens(config) {
|
|
6
|
+
const redacted = { ...config };
|
|
7
|
+
for (const field of TOKEN_FIELDS) {
|
|
8
|
+
if (redacted[field]) {
|
|
9
|
+
redacted[field] = '[redacted]';
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return redacted;
|
|
13
|
+
}
|
|
14
|
+
exports.redactTokens = redactTokens;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const redact_tokens_1 = require("./redact-tokens");
|
|
4
|
+
describe('redactTokens', () => {
|
|
5
|
+
it('should hide the access and refresh tokens and keep the org and environment', () => {
|
|
6
|
+
expect((0, redact_tokens_1.redactTokens)({
|
|
7
|
+
apiGateway: 'https://api.dev.vibeiq.com/dev/api',
|
|
8
|
+
orgSlug: 'adam-zone-1',
|
|
9
|
+
apiUserToken: 'secret-access',
|
|
10
|
+
apiRefreshToken: 'secret-refresh',
|
|
11
|
+
})).toEqual({
|
|
12
|
+
apiGateway: 'https://api.dev.vibeiq.com/dev/api',
|
|
13
|
+
orgSlug: 'adam-zone-1',
|
|
14
|
+
apiUserToken: '[redacted]',
|
|
15
|
+
apiRefreshToken: '[redacted]',
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
it('should leave a config without tokens unchanged', () => {
|
|
19
|
+
expect((0, redact_tokens_1.redactTokens)({ orgSlug: 'adam-zone-1', apiRefreshToken: null })).toEqual({
|
|
20
|
+
orgSlug: 'adam-zone-1',
|
|
21
|
+
apiRefreshToken: null,
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
});
|
package/dist/interfaces.d.ts
CHANGED