@coalescesoftware/coa 1.0.99 → 1.0.102
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/bin/CLIProfile.js +37 -13
- package/bin/index.js +24 -20
- package/package.json +2 -2
package/bin/CLIProfile.js
CHANGED
|
@@ -19,20 +19,37 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.GetCLIConfig = exports.ICLIProfileExample = void 0;
|
|
22
|
+
exports.GetCLIConfig = exports.ICLIProfileExample = exports.GetDefaultLocationForCoaConfigFile = void 0;
|
|
23
23
|
/* eslint-disable multiline-comment-style */
|
|
24
24
|
const Shared = __importStar(require("@coalescesoftware/shared"));
|
|
25
|
+
const immer = __importStar(require("immer"));
|
|
25
26
|
const os = require('os');
|
|
26
27
|
const path = require('path');
|
|
27
28
|
const ini = require('ini');
|
|
28
29
|
const fs = require('fs');
|
|
30
|
+
const RemoveCredentialsFromCLIProfile = (cliProfile) => {
|
|
31
|
+
return immer.produce(cliProfile, (draft) => {
|
|
32
|
+
if (draft.snowflakePassword)
|
|
33
|
+
draft.snowflakePassword = '<REDACTED>';
|
|
34
|
+
if (draft.snowflakeAccount)
|
|
35
|
+
draft.snowflakeAccount = '<REDACTED>';
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const RemoveCredentialsFromCLIProfiles = (cliProfiles) => {
|
|
39
|
+
return immer.produce(cliProfiles, (draftState) => {
|
|
40
|
+
Object.keys(draftState).forEach((cliProfileName) => {
|
|
41
|
+
draftState[cliProfileName] = RemoveCredentialsFromCLIProfile(cliProfiles[cliProfileName]);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
};
|
|
29
45
|
const CLILogger = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI_INTERNAL);
|
|
30
|
-
const
|
|
46
|
+
const GetDefaultLocationForCoaConfigFile = () => {
|
|
31
47
|
const homedir = os.homedir();
|
|
32
48
|
const coaConfigLocation = path.join(homedir, ".coa/config");
|
|
33
49
|
CLILogger.info("using default location", coaConfigLocation);
|
|
34
50
|
return coaConfigLocation;
|
|
35
51
|
};
|
|
52
|
+
exports.GetDefaultLocationForCoaConfigFile = GetDefaultLocationForCoaConfigFile;
|
|
36
53
|
//voodoo typescript magic in order to get runtime and compiletime ICLIProfile code
|
|
37
54
|
//https://stackoverflow.com/questions/45670705/iterate-over-interface-properties-in-typescript
|
|
38
55
|
exports.ICLIProfileExample = {
|
|
@@ -45,9 +62,12 @@ exports.ICLIProfileExample = {
|
|
|
45
62
|
snowflakeRole: "Snowflake Role",
|
|
46
63
|
snowflakeUsername: "Snowflake Username",
|
|
47
64
|
snowflakeWarehouse: "Snowflake Warehouse",
|
|
48
|
-
token: "Coalesce Token"
|
|
65
|
+
token: "Coalesce Token",
|
|
66
|
+
jobID: "Coalesce JobID",
|
|
67
|
+
include: "Coalesce Node Selector",
|
|
68
|
+
exclude: "Coalesce Node Selector"
|
|
49
69
|
};
|
|
50
|
-
const
|
|
70
|
+
const ReadCLIProfiles = (filePath) => {
|
|
51
71
|
return fs.promises.readFile(filePath, 'utf-8').then((file) => {
|
|
52
72
|
return ini.parse(file);
|
|
53
73
|
}).catch((err) => {
|
|
@@ -55,10 +75,9 @@ const readCLIProfiles = (filePath) => {
|
|
|
55
75
|
throw new Error("unable to read cli profile");
|
|
56
76
|
});
|
|
57
77
|
};
|
|
58
|
-
const
|
|
78
|
+
const GetFinalCLIProfile = (commandLineOverrides, configFileLocation) => {
|
|
59
79
|
let profileToUseOverride = commandLineOverrides.profile ? commandLineOverrides.profile : null;
|
|
60
|
-
|
|
61
|
-
return readCLIProfiles(defaultPath).then((cliProfiles) => {
|
|
80
|
+
return ReadCLIProfiles(configFileLocation).then((cliProfiles) => {
|
|
62
81
|
return cliProfiles;
|
|
63
82
|
}).catch((err) => {
|
|
64
83
|
//unable to read cli profiles
|
|
@@ -74,7 +93,7 @@ const getFinalCLIProfile = (commandLineOverrides) => {
|
|
|
74
93
|
const profileToUse = profileToUseOverride || //cli override
|
|
75
94
|
(!!defaultCLIProfile && defaultCLIProfile.profile) //default profile exists
|
|
76
95
|
|| "";
|
|
77
|
-
CLILogger.info("using profile", profileToUse, "cliProfiles", JSON.stringify(cliProfiles));
|
|
96
|
+
CLILogger.info("using profile", profileToUse, "cliProfiles", JSON.stringify(RemoveCredentialsFromCLIProfiles(cliProfiles)));
|
|
78
97
|
if (profileToUse) {
|
|
79
98
|
if (!(profileToUse in cliProfiles)) {
|
|
80
99
|
throw new Error(`unable to find profile ${profileToUse}`);
|
|
@@ -86,13 +105,16 @@ const getFinalCLIProfile = (commandLineOverrides) => {
|
|
|
86
105
|
return finalCLIProfile;
|
|
87
106
|
});
|
|
88
107
|
};
|
|
89
|
-
const GetCLIConfig = (commandLineOverrides) => {
|
|
90
|
-
return
|
|
91
|
-
CLILogger.info("got final cli profile", JSON.stringify(cliProfile));
|
|
92
|
-
|
|
108
|
+
const GetCLIConfig = (commandLineOverrides, configFileLocation) => {
|
|
109
|
+
return GetFinalCLIProfile(commandLineOverrides, configFileLocation).then((cliProfile) => {
|
|
110
|
+
CLILogger.info("got final cli profile configFileLocation:", configFileLocation, JSON.stringify(RemoveCredentialsFromCLIProfile(cliProfile)));
|
|
111
|
+
const cliConfig = {
|
|
93
112
|
token: cliProfile.token,
|
|
94
113
|
runDetails: {
|
|
95
|
-
environmentID: cliProfile.environmentID
|
|
114
|
+
environmentID: cliProfile.environmentID,
|
|
115
|
+
jobID: cliProfile.jobID,
|
|
116
|
+
includeNodesSelector: cliProfile.include,
|
|
117
|
+
excludeNodesSelector: cliProfile.exclude
|
|
96
118
|
},
|
|
97
119
|
userCredentials: {
|
|
98
120
|
snowflakeAccount: cliProfile.snowflakeAccount,
|
|
@@ -104,6 +126,8 @@ const GetCLIConfig = (commandLineOverrides) => {
|
|
|
104
126
|
snowflakeWarehouse: cliProfile.snowflakeWarehouse
|
|
105
127
|
}
|
|
106
128
|
};
|
|
129
|
+
Shared.Common.CleanupUndefinedValuesFromObject(cliConfig);
|
|
130
|
+
return cliConfig;
|
|
107
131
|
});
|
|
108
132
|
};
|
|
109
133
|
exports.GetCLIConfig = GetCLIConfig;
|
package/bin/index.js
CHANGED
|
@@ -39,7 +39,8 @@ const LogCLIInternal = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI_I
|
|
|
39
39
|
const program = new commander_1.Command();
|
|
40
40
|
program.version(require("../package.json").version, "-v, --version");
|
|
41
41
|
program.option("-b, --debug", "Output extra debugging", false);
|
|
42
|
-
|
|
42
|
+
program.option("--config <coa-config-location>", "coa config file location", CLIProfile.GetDefaultLocationForCoaConfigFile());
|
|
43
|
+
const AddOverridesToCommand = (command) => {
|
|
43
44
|
Object.keys(CLIProfile.ICLIProfileExample).forEach((key) => {
|
|
44
45
|
command.option(`--${key} <value>`, CLIProfile.ICLIProfileExample[key], "");
|
|
45
46
|
});
|
|
@@ -47,14 +48,13 @@ const addOverridesToCommand = (command) => {
|
|
|
47
48
|
};
|
|
48
49
|
//computeCLIOverrides returns an object that has a value if any of them have been specified at the command line
|
|
49
50
|
//this is used as the final override when getting a CLIConfig
|
|
50
|
-
const
|
|
51
|
+
const ComputeCLIOverrides = (command) => {
|
|
51
52
|
let overrides = {};
|
|
52
53
|
Object.keys(CLIProfile.ICLIProfileExample).forEach((key) => {
|
|
53
54
|
const source = command.getOptionValueSource(key);
|
|
54
|
-
if (source ==
|
|
55
|
+
if (source == "cli") {
|
|
55
56
|
overrides[key] = command.getOptionValue(key);
|
|
56
57
|
}
|
|
57
|
-
return overrides;
|
|
58
58
|
});
|
|
59
59
|
return overrides;
|
|
60
60
|
};
|
|
@@ -68,12 +68,12 @@ program.command("none", { hidden: true, isDefault: true })
|
|
|
68
68
|
/**
|
|
69
69
|
* Plan command is responsible for reading files and creating a Coalesce Deployment Plan
|
|
70
70
|
*/
|
|
71
|
-
|
|
71
|
+
AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Plan))
|
|
72
72
|
.option("-d, --dir <dir>", "Coalesce pipeline Yaml file path", ".")
|
|
73
73
|
.option("--out <plan-location>", "Coalesce plan location", "./coa-plan.json")
|
|
74
74
|
.description("plan a Coalesce deployment")
|
|
75
75
|
.action((options, cmd) => {
|
|
76
|
-
const cliOverrides =
|
|
76
|
+
const cliOverrides = ComputeCLIOverrides(cmd);
|
|
77
77
|
const optsWithGlobals = cmd.optsWithGlobals();
|
|
78
78
|
const directoryPath = optsWithGlobals.dir;
|
|
79
79
|
let logContextToUse;
|
|
@@ -89,7 +89,7 @@ addOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Plan))
|
|
|
89
89
|
Shared.CLIOperations.DisableNonCLIConsoleLogs();
|
|
90
90
|
}
|
|
91
91
|
let config;
|
|
92
|
-
return CLIProfile.GetCLIConfig(cliOverrides)
|
|
92
|
+
return CLIProfile.GetCLIConfig(cliOverrides, optsWithGlobals.config)
|
|
93
93
|
.then((configResult) => {
|
|
94
94
|
config = configResult;
|
|
95
95
|
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(config.token, undefined);
|
|
@@ -118,11 +118,11 @@ addOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Plan))
|
|
|
118
118
|
/**
|
|
119
119
|
* Deploy command is responsible for taking an already generated plan, and executing it
|
|
120
120
|
*/
|
|
121
|
-
|
|
121
|
+
AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
122
122
|
.option("-p, --plan <plan-location>", "Coalesce plan location", "./coa-plan.json")
|
|
123
123
|
.description("run a coalesce deployment plan")
|
|
124
124
|
.action((options, cmd) => {
|
|
125
|
-
const cliOverrides =
|
|
125
|
+
const cliOverrides = ComputeCLIOverrides(cmd);
|
|
126
126
|
const optsWithGlobals = cmd.optsWithGlobals();
|
|
127
127
|
const plan = JSON.parse(fs_1.default.readFileSync(optsWithGlobals.plan, { encoding: "utf-8" }));
|
|
128
128
|
// const config = JSON.parse(fs.readFileSync(cmd.config, { encoding: "utf-8" }))
|
|
@@ -140,7 +140,7 @@ addOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
|
140
140
|
let logContextToUse;
|
|
141
141
|
let runInfo;
|
|
142
142
|
let config;
|
|
143
|
-
return CLIProfile.GetCLIConfig(cliOverrides)
|
|
143
|
+
return CLIProfile.GetCLIConfig(cliOverrides, optsWithGlobals.config)
|
|
144
144
|
.then((configResult) => {
|
|
145
145
|
config = configResult;
|
|
146
146
|
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(config.token, undefined);
|
|
@@ -168,7 +168,7 @@ addOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
|
168
168
|
Shared.CLIOperations.ExitCLISafe(0);
|
|
169
169
|
})
|
|
170
170
|
.catch(error => {
|
|
171
|
-
LogCLI.errorContext(logContextToUse, chalk_1.default.redBright(`An error occurred during deployment ${error}`));
|
|
171
|
+
LogCLI.errorContext(logContextToUse, chalk_1.default.redBright(`An error occurred during deployment ${error.toString()}`));
|
|
172
172
|
Shared.CLIOperations.ExitCLISafe(1);
|
|
173
173
|
});
|
|
174
174
|
});
|
|
@@ -176,10 +176,10 @@ addOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
|
176
176
|
/**
|
|
177
177
|
* Refresh command begins a locally executed Coalesce Environment Run
|
|
178
178
|
*/
|
|
179
|
-
|
|
179
|
+
AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Refresh))
|
|
180
180
|
.description("runs a Coalesce pipeline")
|
|
181
181
|
.action((options, command) => {
|
|
182
|
-
const cliOverrides =
|
|
182
|
+
const cliOverrides = ComputeCLIOverrides(command);
|
|
183
183
|
const optsWithGlobals = command.optsWithGlobals();
|
|
184
184
|
//const token = fs.readFileSync(cmd.token, { encoding: "utf8" })
|
|
185
185
|
//const config = JSON.parse(fs.readFileSync(cmd.config, { encoding: "utf8" }))
|
|
@@ -201,17 +201,21 @@ addOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Refresh)
|
|
|
201
201
|
//WHY DO WE HAVE THIS CONFIG?
|
|
202
202
|
let runInfo;
|
|
203
203
|
let config;
|
|
204
|
-
return CLIProfile.GetCLIConfig(cliOverrides)
|
|
204
|
+
return CLIProfile.GetCLIConfig(cliOverrides, optsWithGlobals.config)
|
|
205
205
|
.then((configResult) => {
|
|
206
206
|
config = configResult;
|
|
207
207
|
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(config.token, undefined);
|
|
208
|
-
})
|
|
208
|
+
})
|
|
209
|
+
.then(({ teamInfo }) => {
|
|
209
210
|
Shared.Logging.SetBackendGlobalContext({ userID: teamInfo.fbUserID, orgID: teamInfo.fbTeamID });
|
|
210
211
|
runInfo = {
|
|
211
212
|
runType: Shared.Runner.ERunType.refresh,
|
|
212
213
|
runStatus: Shared.Runner.ERunStatus.running,
|
|
213
214
|
runDetails: {
|
|
214
|
-
environmentID: config.runDetails.environmentID
|
|
215
|
+
environmentID: config.runDetails.environmentID,
|
|
216
|
+
jobID: config.runDetails.jobID,
|
|
217
|
+
includeNodesSelector: config.runDetails.includeNodesSelector,
|
|
218
|
+
excludeNodesSelector: config.runDetails.excludeNodesSelector
|
|
215
219
|
},
|
|
216
220
|
userCredentials: config.userCredentials,
|
|
217
221
|
runTimeParameters: {}
|
|
@@ -230,11 +234,11 @@ addOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Refresh)
|
|
|
230
234
|
.then(() => {
|
|
231
235
|
LogCLI.infoContext(logContextToUse, "Refresh successful!");
|
|
232
236
|
Shared.CLIOperations.ExitCLISafe(0);
|
|
233
|
-
})
|
|
234
|
-
.catch(error => {
|
|
235
|
-
LogCLI.errorContext(logContextToUse, chalk_1.default.redBright(`Error during refresh!: ${error.toString()}`));
|
|
236
|
-
Shared.CLIOperations.ExitCLISafe(1);
|
|
237
237
|
});
|
|
238
|
+
})
|
|
239
|
+
.catch(error => {
|
|
240
|
+
LogCLI.errorContext(logContextToUse, chalk_1.default.redBright(`Error during refresh!: ${error.toString()}`));
|
|
241
|
+
Shared.CLIOperations.ExitCLISafe(1);
|
|
238
242
|
});
|
|
239
243
|
});
|
|
240
244
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coalescesoftware/coa",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.102",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"author": "Coalesce Automation, Inc.",
|
|
6
6
|
"main": "index.js",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"start-cli-debug": "yarn run start --debug"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@coalescesoftware/shared": "^1.0.
|
|
15
|
+
"@coalescesoftware/shared": "^1.0.111",
|
|
16
16
|
"chalk": "^4.1.2",
|
|
17
17
|
"commander": "^9.2.0",
|
|
18
18
|
"firebase": "8.2.0",
|