@coalescesoftware/coa 1.0.112 → 1.0.115
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 +22 -10
- package/bin/{Common.js → CommonCLI/CommonCLI.js} +28 -9
- package/bin/CommonCLI/CommonCLI.test.js +28 -0
- package/bin/CommonCLI.js +38 -6
- package/bin/Deploy/Deploy.js +70 -0
- package/bin/Deploy.js +1 -1
- package/bin/Package.js +758 -0
- package/bin/Plan/Plan.js +41 -0
- package/bin/Plan.js +2 -2
- package/bin/Refresh/Refresh.js +65 -0
- package/bin/RunOutput.js +82 -0
- package/bin/index.js +266 -29
- package/package.json +3 -2
- package/bin/CLIOperations.js +0 -135
- package/bin/Profile.js +0 -53
package/bin/Plan/Plan.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.CreatePlan = void 0;
|
|
26
|
+
const Shared = __importStar(require("@coalescesoftware/shared"));
|
|
27
|
+
const fs_1 = __importDefault(require("fs"));
|
|
28
|
+
const CreatePlan = (path, environmentID, token, message) => {
|
|
29
|
+
const fsSettings = {
|
|
30
|
+
fs: fs_1.default,
|
|
31
|
+
dir: path,
|
|
32
|
+
};
|
|
33
|
+
return Shared.DeployOperations.CreatePlanCLI(environmentID, fsSettings, token, Shared.Templates.PlatformType.snowflake)
|
|
34
|
+
.then(result => {
|
|
35
|
+
const { plan } = result;
|
|
36
|
+
plan.gitInfo = { commit: { message: message }, oid: "" };
|
|
37
|
+
return result;
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
exports.CreatePlan = CreatePlan;
|
|
41
|
+
//# sourceMappingURL=Plan.js.map
|
package/bin/Plan.js
CHANGED
|
@@ -25,12 +25,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
25
25
|
exports.CreatePlan = void 0;
|
|
26
26
|
const Shared = __importStar(require("@coalescesoftware/shared"));
|
|
27
27
|
const fs_1 = __importDefault(require("fs"));
|
|
28
|
-
const CreatePlan = (path, environmentID, token, message) => {
|
|
28
|
+
const CreatePlan = (path, environmentID, token, message, runtimeParameters) => {
|
|
29
29
|
const fsSettings = {
|
|
30
30
|
fs: fs_1.default,
|
|
31
31
|
dir: path,
|
|
32
32
|
};
|
|
33
|
-
return Shared.DeployOperations.CreatePlanCLI(environmentID, fsSettings, token, Shared.Templates.PlatformType.snowflake)
|
|
33
|
+
return Shared.DeployOperations.CreatePlanCLI(environmentID, fsSettings, token, Shared.Templates.PlatformType.snowflake, runtimeParameters)
|
|
34
34
|
.then(result => {
|
|
35
35
|
const { plan } = result;
|
|
36
36
|
plan.gitInfo = { commit: { message: message }, oid: "" };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.RefreshWithCLI = void 0;
|
|
23
|
+
const Shared = __importStar(require("@coalescesoftware/shared"));
|
|
24
|
+
const CommonCLI = __importStar(require("../CommonCLI/CommonCLI"));
|
|
25
|
+
const CryptoJS = require("crypto-js");
|
|
26
|
+
const v8 = require("v8");
|
|
27
|
+
Shared.Snowflake.CryptoJS = CryptoJS;
|
|
28
|
+
Shared.Snowflake.salt = CryptoJS.lib.WordArray.random(128 / 8);
|
|
29
|
+
Shared.Snowflake.v8 = v8;
|
|
30
|
+
const LogCLI = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI);
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param token
|
|
34
|
+
* @param runInfo
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
const RefreshWithCLI = (token, runInfo) => {
|
|
38
|
+
let firebase;
|
|
39
|
+
let logContext;
|
|
40
|
+
let RunSQL, teamDetails;
|
|
41
|
+
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(token, undefined)
|
|
42
|
+
.then((teamInfoAndFirebase) => {
|
|
43
|
+
const { teamInfo: { fbUserID: userID, fbTeamID: teamID } } = teamInfoAndFirebase;
|
|
44
|
+
firebase = teamInfoAndFirebase.firebase;
|
|
45
|
+
const environmentID = runInfo.runDetails.environmentID;
|
|
46
|
+
logContext = Shared.Logging.CreateLogContext(teamID, environmentID, userID);
|
|
47
|
+
const connectionCache = new Shared.Snowflake.ConnectionStorageClass();
|
|
48
|
+
RunSQL = Shared.SQLExecutorCreators.CreateRunSQLWithoutScheduler(teamInfoAndFirebase, connectionCache);
|
|
49
|
+
LogCLI.infoContext(logContext, "Starting refresh (CLI)");
|
|
50
|
+
return CommonCLI.GetUserConnectionForCLI(userID, runInfo);
|
|
51
|
+
})
|
|
52
|
+
.then((connection) => {
|
|
53
|
+
return Shared.SchedulerOperations.HandleRefresh(runInfo, teamDetails, RunSQL, connection);
|
|
54
|
+
})
|
|
55
|
+
.then(({ runCounter, runCompletion }) => {
|
|
56
|
+
const cleanupPromise = CommonCLI.CleanupCLIJob(runCompletion, firebase, logContext, "Refresh");
|
|
57
|
+
return {
|
|
58
|
+
runCounter,
|
|
59
|
+
runCompletion: cleanupPromise,
|
|
60
|
+
logContext,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
exports.RefreshWithCLI = RefreshWithCLI;
|
|
65
|
+
//# sourceMappingURL=Refresh.js.map
|
package/bin/RunOutput.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.SaveRunOutputToFile = void 0;
|
|
23
|
+
const Shared = __importStar(require("@coalescesoftware/shared"));
|
|
24
|
+
const CLILogger = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI);
|
|
25
|
+
const cleanRunResult = (nodeID, runResult) => {
|
|
26
|
+
return {
|
|
27
|
+
nodeID,
|
|
28
|
+
queryResultSequence: runResult.queryResultSequence
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
const GetRunOutputForRunCounter = (firestore, teamID, runID) => {
|
|
32
|
+
let runData;
|
|
33
|
+
return Shared.Runs.getRun(firestore, teamID, runID).get()
|
|
34
|
+
.then((runDataResult /*query snapshot*/) => {
|
|
35
|
+
if (!runDataResult.docs.length) {
|
|
36
|
+
const errorMessage = `wasnt able to get exactly one run for runID ${runID}`;
|
|
37
|
+
CLILogger.emergContext({
|
|
38
|
+
orgID: teamID
|
|
39
|
+
}, errorMessage);
|
|
40
|
+
throw new Error(errorMessage);
|
|
41
|
+
}
|
|
42
|
+
const runInfo = runDataResult.docs[0].data();
|
|
43
|
+
runData = {
|
|
44
|
+
runResults: {
|
|
45
|
+
runStartTime: runInfo.runStartTime,
|
|
46
|
+
runEndTime: runInfo.runEndTime,
|
|
47
|
+
runType: runInfo.runType,
|
|
48
|
+
runStatus: runInfo.runStatus,
|
|
49
|
+
runID: runInfo.id,
|
|
50
|
+
runResults: []
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
return Shared.Runs.getRunRunResultsCollection(firestore, teamID, runID.toString())
|
|
54
|
+
.get().then((queryResult /*querySnapshot*/) => {
|
|
55
|
+
let runResults = {};
|
|
56
|
+
queryResult.docs.forEach((runResultDoc) => {
|
|
57
|
+
const stepCounter = runResultDoc.id;
|
|
58
|
+
const runResult = runResultDoc.data();
|
|
59
|
+
runResults[stepCounter] = cleanRunResult(stepCounter, runResult.history[0]);
|
|
60
|
+
});
|
|
61
|
+
runData.runResults.runResults = runInfo.runHistory.map((stepCounter) => {
|
|
62
|
+
return runResults[stepCounter];
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
}).then(() => {
|
|
66
|
+
return runData;
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
const SaveRunOutputToFile = (runOutputFileLocation, runIDString, token) => {
|
|
70
|
+
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(token, undefined).then((authInfo) => {
|
|
71
|
+
const { teamInfo, firebase } = authInfo;
|
|
72
|
+
const teamID = teamInfo.fbTeamID;
|
|
73
|
+
const firestore = firebase.firestore();
|
|
74
|
+
const runID = parseInt(runIDString);
|
|
75
|
+
return GetRunOutputForRunCounter(firestore, teamID, runID);
|
|
76
|
+
}).then((runOutput) => {
|
|
77
|
+
const runOutputJSON = Shared.Common.StringifyFirestoreObject(runOutput);
|
|
78
|
+
return Shared.Common.WriteFile(runOutputFileLocation, runOutputJSON + "\n");
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
exports.SaveRunOutputToFile = SaveRunOutputToFile;
|
|
82
|
+
//# sourceMappingURL=RunOutput.js.map
|
package/bin/index.js
CHANGED
|
@@ -27,19 +27,28 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
27
27
|
const Deploy = __importStar(require("./Deploy"));
|
|
28
28
|
const Plan = __importStar(require("./Plan"));
|
|
29
29
|
const Refresh = __importStar(require("./Refresh"));
|
|
30
|
+
const Package = __importStar(require("./Package"));
|
|
30
31
|
const Shared = __importStar(require("@coalescesoftware/shared"));
|
|
31
32
|
const CLIProfile = __importStar(require("./CLIProfile"));
|
|
32
33
|
const chalk_1 = __importDefault(require("chalk"));
|
|
33
34
|
const commander_1 = require("commander");
|
|
35
|
+
const CommonCLI = __importStar(require("./CommonCLI"));
|
|
34
36
|
const fs_1 = __importDefault(require("fs"));
|
|
37
|
+
const inquirer_1 = __importDefault(require("inquirer"));
|
|
35
38
|
// setting this needs to be first!
|
|
36
39
|
Shared.Logging.SetHTTPTransportOptions(Shared.Logging.EHttpServices.CLI);
|
|
37
40
|
const LogCLI = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI);
|
|
38
41
|
const LogCLIInternal = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI_INTERNAL);
|
|
42
|
+
const ChalkLogger = {
|
|
43
|
+
error: (message) => LogCLI.error(chalk_1.default.redBright(message)),
|
|
44
|
+
green: (message) => LogCLI.info(chalk_1.default.green(message)),
|
|
45
|
+
white: (message) => LogCLI.info(chalk_1.default.whiteBright(message)),
|
|
46
|
+
blue: (message) => LogCLI.info(chalk_1.default.blueBright(message)),
|
|
47
|
+
};
|
|
39
48
|
const program = new commander_1.Command();
|
|
40
49
|
program.version(require("../package.json").version, "-v, --version");
|
|
41
50
|
program.option("-b, --debug", "Output extra debugging", false);
|
|
42
|
-
program.option("--config <coa-config-location>", "coa config file location"
|
|
51
|
+
program.option("--config <coa-config-location>", "coa config file location");
|
|
43
52
|
const AddOverridesToCommand = (command) => {
|
|
44
53
|
Object.keys(CLIProfile.ICLIProfileExample).forEach((key) => {
|
|
45
54
|
command.option(`--${key} <value>`, CLIProfile.ICLIProfileExample[key], "");
|
|
@@ -89,14 +98,26 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Plan))
|
|
|
89
98
|
Shared.CLIOperations.DisableNonCLIConsoleLogs();
|
|
90
99
|
}
|
|
91
100
|
let config;
|
|
92
|
-
return
|
|
101
|
+
return Promise.resolve().then(() => {
|
|
102
|
+
return CLIProfile.GetCLIConfig(cliOverrides, optsWithGlobals.config);
|
|
103
|
+
})
|
|
93
104
|
.then((configResult) => {
|
|
94
105
|
config = configResult;
|
|
106
|
+
if (config.runtimeParameters) {
|
|
107
|
+
CommonCLI.ValidateRuntimeParameters(config.runtimeParameters);
|
|
108
|
+
}
|
|
95
109
|
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(config.token, undefined);
|
|
96
|
-
})
|
|
110
|
+
})
|
|
111
|
+
.then(({ teamInfo, firebase }) => {
|
|
112
|
+
const firestore = firebase.firestore();
|
|
97
113
|
Shared.Logging.SetBackendGlobalContext({ userID: teamInfo.fbUserID, orgID: teamInfo.fbTeamID });
|
|
114
|
+
const teamID = teamInfo.fbTeamID;
|
|
115
|
+
const environmentID = config.runDetails.environmentID;
|
|
116
|
+
return Shared.SchedulerOperations.GetRuntimeParametersObjectForRun(firestore, teamID, environmentID, config.runtimeParameters);
|
|
117
|
+
})
|
|
118
|
+
.then((runtimeParametersObject) => {
|
|
98
119
|
const envID = config.runDetails.environmentID;
|
|
99
|
-
return Plan.CreatePlan(directoryPath, envID, config.token, `Deploy to environment: ${envID}
|
|
120
|
+
return Plan.CreatePlan(directoryPath, envID, config.token, `Deploy to environment: ${envID}`, JSON.stringify(runtimeParametersObject));
|
|
100
121
|
}).then(result => {
|
|
101
122
|
const { plan, logContext } = result;
|
|
102
123
|
logContextToUse = logContext;
|
|
@@ -120,6 +141,7 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Plan))
|
|
|
120
141
|
*/
|
|
121
142
|
AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
122
143
|
.option("-p, --plan <plan-location>", "Coalesce plan location", "./coa-plan.json")
|
|
144
|
+
.option("-o, --out <output json>", "Run Results Output in Json ")
|
|
123
145
|
.description("run a coalesce deployment plan")
|
|
124
146
|
.action((options, cmd) => {
|
|
125
147
|
const cliOverrides = ComputeCLIOverrides(cmd);
|
|
@@ -140,7 +162,9 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
|
140
162
|
let logContextToUse;
|
|
141
163
|
let runInfo;
|
|
142
164
|
let config;
|
|
143
|
-
return
|
|
165
|
+
return Promise.resolve().then(() => {
|
|
166
|
+
return CLIProfile.GetCLIConfig(cliOverrides, optsWithGlobals.config);
|
|
167
|
+
})
|
|
144
168
|
.then((configResult) => {
|
|
145
169
|
config = configResult;
|
|
146
170
|
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(config.token, undefined);
|
|
@@ -153,7 +177,7 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
|
153
177
|
environmentID: config.runDetails.environmentID
|
|
154
178
|
},
|
|
155
179
|
userCredentials: config.userCredentials,
|
|
156
|
-
runTimeParameters: {}
|
|
180
|
+
runTimeParameters: plan.runtimeParameters || {},
|
|
157
181
|
};
|
|
158
182
|
Shared.Common.assert(Shared.Logging.LoggingArea.CLI, !!runInfo, "runinfo must exist to continue");
|
|
159
183
|
return Deploy.DeployWithCLI(plan, runInfo, config.token)
|
|
@@ -161,16 +185,18 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
|
161
185
|
const { runCounter, runCompletion, logContext } = result;
|
|
162
186
|
logContextToUse = logContext !== null && logContext !== void 0 ? logContext : {};
|
|
163
187
|
LogCLI.infoContext(logContextToUse, chalk_1.default.whiteBright(`Job ${runCounter}: ${chalk_1.default.green("running")}...`));
|
|
164
|
-
return runCompletion
|
|
188
|
+
return runCompletion.finally(() => {
|
|
189
|
+
const outputFilePath = optsWithGlobals.out;
|
|
190
|
+
CommonCLI.FinishWithOutputFile(logContextToUse, outputFilePath, runCounter, config.token);
|
|
191
|
+
});
|
|
165
192
|
})
|
|
166
193
|
.then(() => {
|
|
167
194
|
LogCLI.infoContext(logContextToUse, "Deployment successful!");
|
|
168
195
|
Shared.CLIOperations.ExitCLISafe(0);
|
|
169
|
-
})
|
|
170
|
-
.catch(error => {
|
|
171
|
-
LogCLI.errorContext(logContextToUse, chalk_1.default.redBright(`An error occurred during deployment ${error.toString()}`));
|
|
172
|
-
Shared.CLIOperations.ExitCLISafe(1);
|
|
173
196
|
});
|
|
197
|
+
}).catch(error => {
|
|
198
|
+
LogCLI.errorContext(logContextToUse, chalk_1.default.redBright(`An error occurred during deployment ${error.toString()}`));
|
|
199
|
+
Shared.CLIOperations.ExitCLISafe(1);
|
|
174
200
|
});
|
|
175
201
|
});
|
|
176
202
|
/**
|
|
@@ -178,19 +204,10 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
|
178
204
|
*/
|
|
179
205
|
AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Refresh))
|
|
180
206
|
.description("runs a Coalesce pipeline")
|
|
207
|
+
.option("-o, --out <output json>", "Run Results Output in Json ")
|
|
181
208
|
.action((options, command) => {
|
|
182
209
|
const cliOverrides = ComputeCLIOverrides(command);
|
|
183
210
|
const optsWithGlobals = command.optsWithGlobals();
|
|
184
|
-
//const token = fs.readFileSync(cmd.token, { encoding: "utf8" })
|
|
185
|
-
//const config = JSON.parse(fs.readFileSync(cmd.config, { encoding: "utf8" }))
|
|
186
|
-
/*
|
|
187
|
-
try {
|
|
188
|
-
Shared.CLIOperations.VerifyAllRefreshItems(config, token)
|
|
189
|
-
} catch (error) {
|
|
190
|
-
LogCLI.error(Chalk.redBright(`Error with required option values: ${error}`))
|
|
191
|
-
Shared.CLIOperations.ExitCLISafe(1)
|
|
192
|
-
}
|
|
193
|
-
*/
|
|
194
211
|
const debugMode = optsWithGlobals.debug;
|
|
195
212
|
if (!debugMode) {
|
|
196
213
|
Shared.CLIOperations.DisableNonCLIConsoleLogs();
|
|
@@ -201,13 +218,21 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Refresh)
|
|
|
201
218
|
//WHY DO WE HAVE THIS CONFIG?
|
|
202
219
|
let runInfo;
|
|
203
220
|
let config;
|
|
204
|
-
return
|
|
221
|
+
return Promise.resolve().then(() => {
|
|
222
|
+
return CLIProfile.GetCLIConfig(cliOverrides, optsWithGlobals.config);
|
|
223
|
+
})
|
|
205
224
|
.then((configResult) => {
|
|
206
225
|
config = configResult;
|
|
207
226
|
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(config.token, undefined);
|
|
208
227
|
})
|
|
209
|
-
.then(({ teamInfo }) => {
|
|
228
|
+
.then(({ teamInfo, firebase }) => {
|
|
229
|
+
const firestore = firebase.firestore();
|
|
210
230
|
Shared.Logging.SetBackendGlobalContext({ userID: teamInfo.fbUserID, orgID: teamInfo.fbTeamID });
|
|
231
|
+
const teamID = teamInfo.fbTeamID;
|
|
232
|
+
const environmentID = config.runDetails.environmentID;
|
|
233
|
+
return Shared.SchedulerOperations.GetRuntimeParametersObjectForRun(firestore, teamID, environmentID, config.runtimeParameters);
|
|
234
|
+
})
|
|
235
|
+
.then((runtimeParametersObject) => {
|
|
211
236
|
runInfo = {
|
|
212
237
|
runType: Shared.Runner.ERunType.refresh,
|
|
213
238
|
runStatus: Shared.Runner.ERunStatus.running,
|
|
@@ -218,27 +243,239 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Refresh)
|
|
|
218
243
|
excludeNodesSelector: config.runDetails.excludeNodesSelector
|
|
219
244
|
},
|
|
220
245
|
userCredentials: config.userCredentials,
|
|
221
|
-
runTimeParameters:
|
|
246
|
+
runTimeParameters: runtimeParametersObject,
|
|
222
247
|
};
|
|
223
248
|
Shared.Common.CleanupUndefinedValuesFromObject(runInfo);
|
|
224
249
|
LogCLIInternal.infoContext(logContextToUse, "cliOverrides", cliOverrides);
|
|
225
|
-
LogCLIInternal.infoContext(logContextToUse, "got the cli config", config)
|
|
226
|
-
LogCLIInternal.infoContext(logContextToUse, "got the run info", config)
|
|
250
|
+
//LogCLIInternal.infoContext(logContextToUse, "got the cli config", config)
|
|
251
|
+
//LogCLIInternal.infoContext(logContextToUse, "got the run info", config)
|
|
227
252
|
Shared.Common.assert(Shared.Logging.LoggingArea.CLI, !!runInfo, "runinfo must exist to continue");
|
|
228
253
|
return Refresh.RefreshWithCLI(config.token, runInfo)
|
|
229
254
|
.then((result) => {
|
|
230
255
|
const { runCounter, runCompletion, logContext } = result;
|
|
231
256
|
logContextToUse = logContext !== null && logContext !== void 0 ? logContext : {};
|
|
232
257
|
LogCLI.infoContext(logContextToUse, chalk_1.default.whiteBright(`Refresh run initialized. RunCounter: ${runCounter}`));
|
|
233
|
-
return runCompletion
|
|
258
|
+
return runCompletion.finally(() => {
|
|
259
|
+
const outputFilePath = optsWithGlobals.out;
|
|
260
|
+
CommonCLI.FinishWithOutputFile(logContextToUse, outputFilePath, runCounter, config.token);
|
|
261
|
+
}).then(() => {
|
|
262
|
+
LogCLI.infoContext(logContextToUse, "Refresh successful!");
|
|
263
|
+
Shared.CLIOperations.ExitCLISafe(0);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}).catch(error => {
|
|
267
|
+
LogCLI.errorContext(logContextToUse, chalk_1.default.redBright(`Error during refresh!: ${error.toString()}`));
|
|
268
|
+
Shared.CLIOperations.ExitCLISafe(1);
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
//////////////////////////////////////
|
|
272
|
+
///// COA PACKAGES
|
|
273
|
+
//////////////////////////////////////
|
|
274
|
+
const PackageInit = program.command(Shared.CLIOperations.ECLICommands.Package)
|
|
275
|
+
.description("experimental feature")
|
|
276
|
+
// removing description until Lhotse 4.0 release
|
|
277
|
+
// .description(`\n--------------------------------------\n*** Experimental Feature ***\n--------------------------------------\nImport workspace information (aka Coalesce Package) from other Coalesce repositories into your the environment provided in your COA config, or --environmentID override.
|
|
278
|
+
// \nSubcommands:
|
|
279
|
+
// add <location> imports data from <location> (either URL with optional #commit, #branch, or file path)
|
|
280
|
+
// remove <packageID> removes imported package with <packageID> from your Coalesce project\n--------------------------------------\n`)
|
|
281
|
+
.option("--list [workspaceID]", "Lists installed package names for default or specified workspace")
|
|
282
|
+
// .command("none", { hidden: true, isDefault: true }) // removing description until Lhotse 4.0 release
|
|
283
|
+
.action((opts, cmd) => {
|
|
284
|
+
const cliOverrides = ComputeCLIOverrides(cmd);
|
|
285
|
+
const optsWithGlobals = cmd.optsWithGlobals();
|
|
286
|
+
const list = optsWithGlobals.list;
|
|
287
|
+
const debugMode = optsWithGlobals.debug;
|
|
288
|
+
if (!debugMode) {
|
|
289
|
+
Shared.CLIOperations.DisableNonCLIConsoleLogs();
|
|
290
|
+
}
|
|
291
|
+
let environmentID;
|
|
292
|
+
if (list) {
|
|
293
|
+
return CLIProfile.GetCLIConfig(cliOverrides, optsWithGlobals.config)
|
|
294
|
+
.then((configResult) => {
|
|
295
|
+
// if list is a boolean, then --list had no workspaceID arg, so use workspaceID from coaConfig, else use provided workspaceID
|
|
296
|
+
environmentID = typeof list === "boolean" ? configResult.runDetails.environmentID : list;
|
|
297
|
+
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(configResult.token, undefined);
|
|
234
298
|
})
|
|
299
|
+
.then((authInfo) => {
|
|
300
|
+
const packageContext = Package.InitializePackageContext(authInfo, environmentID);
|
|
301
|
+
return Package.GetPackageListMessageCLI(packageContext);
|
|
302
|
+
})
|
|
303
|
+
.then((packageListCLI) => {
|
|
304
|
+
Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI).info(chalk_1.default.bgBlueBright(packageListCLI));
|
|
305
|
+
Shared.CLIOperations.ExitCLISafe(0);
|
|
306
|
+
})
|
|
307
|
+
.catch((error) => {
|
|
308
|
+
Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI).error(chalk_1.default.red(`CLI Package listing error`, error));
|
|
309
|
+
Shared.CLIOperations.ExitCLISafe(1);
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
program.help();
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
// removing description until Lhotse 4.0 release - also todo: do this better anyway
|
|
317
|
+
// PackageInit.command("none", { hidden: true, isDefault: true })
|
|
318
|
+
// .action(() => {
|
|
319
|
+
// PackageInit.help()
|
|
320
|
+
// })
|
|
321
|
+
const throwForbiddenExperimentalError = () => {
|
|
322
|
+
const errorMessage = ` 403 - Forbidden: You do not have permission to access this experimental feature`;
|
|
323
|
+
throw new Error(errorMessage);
|
|
324
|
+
};
|
|
325
|
+
const AddPackage = AddOverridesToCommand(PackageInit.command(`${Shared.CLIOperations.ECLICommands.Add} <location>`))
|
|
326
|
+
// .description("imports data from <location> (either URL with optional #commit or dir path) to your Coalesce project for given environment ID") // removing description until Lhotse 4.0 release
|
|
327
|
+
.option("-y", "Auto-confirm all overwrite prompts");
|
|
328
|
+
AddPackage
|
|
329
|
+
.action((location, options, cmd) => {
|
|
330
|
+
const cliOverrides = ComputeCLIOverrides(cmd);
|
|
331
|
+
const optsWithGlobals = cmd.optsWithGlobals();
|
|
332
|
+
const debugMode = optsWithGlobals.debug;
|
|
333
|
+
const packageLocation = location;
|
|
334
|
+
const confirmPrompts = options.y || false;
|
|
335
|
+
if (!debugMode) {
|
|
336
|
+
Shared.CLIOperations.DisableNonCLIConsoleLogs();
|
|
337
|
+
}
|
|
338
|
+
ChalkLogger.green(`Initializing package installation...`);
|
|
339
|
+
let loggerContext;
|
|
340
|
+
let token;
|
|
341
|
+
let cliConfig;
|
|
342
|
+
let environmentID;
|
|
343
|
+
let packageContext;
|
|
344
|
+
let packageProvider;
|
|
345
|
+
return CLIProfile.GetCLIConfig(cliOverrides, optsWithGlobals.config)
|
|
346
|
+
.then((configResult) => {
|
|
347
|
+
cliConfig = configResult;
|
|
348
|
+
token = cliConfig.token;
|
|
349
|
+
environmentID = cliConfig.runDetails.environmentID;
|
|
350
|
+
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(token, undefined);
|
|
351
|
+
})
|
|
352
|
+
.then((authInfo) => {
|
|
353
|
+
// this feature only available to SuperUsers until Lhotse release
|
|
354
|
+
if (!authInfo.teamInfo.fbHasSuperUserAccess) {
|
|
355
|
+
throwForbiddenExperimentalError();
|
|
356
|
+
}
|
|
357
|
+
packageContext = Package.InitializePackageContext(authInfo, environmentID);
|
|
358
|
+
packageProvider = new Package.PackageProvider(packageLocation, loggerContext);
|
|
359
|
+
// need to getWorkspaceDataFS here in order to get package ID from package provider
|
|
360
|
+
return packageProvider.getWorkspaceDataFS()
|
|
361
|
+
.then(() => Shared.Workspaces.getAllWorkspaceDataFromFirebase(authInfo.firebase.firestore(), authInfo.teamInfo.fbTeamID, environmentID));
|
|
362
|
+
})
|
|
363
|
+
.then(workspaceData => {
|
|
364
|
+
const isPackageAlreadyInstalled = Package.IsPackageAlreadyInstalled(workspaceData.packages || {}, packageProvider.id);
|
|
365
|
+
const install = () => {
|
|
366
|
+
return Package.InstallPackage(packageProvider, packageContext)
|
|
367
|
+
.then(() => {
|
|
368
|
+
Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI).info(chalk_1.default.green(`CLI Package Installation complete`));
|
|
369
|
+
Shared.CLIOperations.ExitCLISafe(0);
|
|
370
|
+
});
|
|
371
|
+
};
|
|
372
|
+
if (isPackageAlreadyInstalled) {
|
|
373
|
+
if (confirmPrompts) {
|
|
374
|
+
return install();
|
|
375
|
+
}
|
|
376
|
+
else {
|
|
377
|
+
const promptData = [
|
|
378
|
+
{
|
|
379
|
+
name: "confirmOverwrite",
|
|
380
|
+
type: "confirm",
|
|
381
|
+
message: `Package "${packageProvider.id}" already exists. Continuing with installation will remove any changes you might have made and overwrite the data previously imported from this package.
|
|
382
|
+
\n\nWould you like to continue installation and overwrite any previously installed package data from "${packageProvider.id}"?`,
|
|
383
|
+
default: false
|
|
384
|
+
},
|
|
385
|
+
];
|
|
386
|
+
return inquirer_1.default.prompt(promptData)
|
|
387
|
+
.then(answers => {
|
|
388
|
+
const shouldOverwrite = answers.confirmOverwrite;
|
|
389
|
+
if (shouldOverwrite) {
|
|
390
|
+
return install();
|
|
391
|
+
}
|
|
392
|
+
else {
|
|
393
|
+
Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI).info(`CLI Package installation aborted`);
|
|
394
|
+
Shared.CLIOperations.ExitCLISafe(0);
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
return install();
|
|
401
|
+
}
|
|
402
|
+
})
|
|
403
|
+
.catch(error => {
|
|
404
|
+
if (error.isTtyError) {
|
|
405
|
+
// Prompt couldn't be rendered in the current environment
|
|
406
|
+
Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI).errorContext(loggerContext, chalk_1.default.red(`There was a problem rendering the overwrite confirmation prompt in your environment. \n\n To overwrite package without prompts, add the -y param to the end of the command and try again.`, error));
|
|
407
|
+
}
|
|
408
|
+
Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI).errorContext(loggerContext, chalk_1.default.red(`CLI Package Installation error`, error));
|
|
409
|
+
Shared.CLIOperations.ExitCLISafe(1);
|
|
410
|
+
});
|
|
411
|
+
});
|
|
412
|
+
const RemovePackage = AddOverridesToCommand(PackageInit.command(`${Shared.CLIOperations.ECLICommands.Remove} <id>`))
|
|
413
|
+
// .description("removes imported package with <id> from your Coalesce project for given environment ID") // removing description until Lhotse 4.0 release
|
|
414
|
+
.option("-y", "Auto-confirm all remove prompts");
|
|
415
|
+
RemovePackage
|
|
416
|
+
.action((id, options, cmd) => {
|
|
417
|
+
const cliOverrides = ComputeCLIOverrides(cmd);
|
|
418
|
+
const optsWithGlobals = cmd.optsWithGlobals();
|
|
419
|
+
const debugMode = optsWithGlobals.debug;
|
|
420
|
+
const packageID = id.toUpperCase();
|
|
421
|
+
const confirmPrompts = options.y || false;
|
|
422
|
+
if (!debugMode) {
|
|
423
|
+
Shared.CLIOperations.DisableNonCLIConsoleLogs();
|
|
424
|
+
}
|
|
425
|
+
ChalkLogger.green(`Initializing package removal...`);
|
|
426
|
+
let loggerContext;
|
|
427
|
+
let token;
|
|
428
|
+
let cliConfig;
|
|
429
|
+
let environmentID;
|
|
430
|
+
return CLIProfile.GetCLIConfig(cliOverrides, optsWithGlobals.config)
|
|
431
|
+
.then((configResult) => {
|
|
432
|
+
cliConfig = configResult;
|
|
433
|
+
token = cliConfig.token;
|
|
434
|
+
environmentID = cliConfig.runDetails.environmentID;
|
|
435
|
+
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(token, undefined);
|
|
436
|
+
})
|
|
437
|
+
.then((authInfo) => {
|
|
438
|
+
// this feature only available to SuperUsers until Lhotse release
|
|
439
|
+
if (!authInfo.teamInfo.fbHasSuperUserAccess) {
|
|
440
|
+
throwForbiddenExperimentalError();
|
|
441
|
+
}
|
|
442
|
+
const packageContext = Package.InitializePackageContext(authInfo, environmentID);
|
|
443
|
+
const uninstall = () => Package.UninstallPackage(packageID, packageContext)
|
|
235
444
|
.then(() => {
|
|
236
|
-
|
|
445
|
+
ChalkLogger.green("Package removal completed successfully!");
|
|
237
446
|
Shared.CLIOperations.ExitCLISafe(0);
|
|
238
447
|
});
|
|
448
|
+
if (confirmPrompts) {
|
|
449
|
+
return uninstall();
|
|
450
|
+
}
|
|
451
|
+
else {
|
|
452
|
+
const promptData = [
|
|
453
|
+
{
|
|
454
|
+
name: "confirmRemove",
|
|
455
|
+
type: "confirm",
|
|
456
|
+
message: `Removing a package will remove all imported data from that package, including any edits you have made on that imported data. \n\nAre you sure you'd like to remove package "${packageID}"?`,
|
|
457
|
+
default: false
|
|
458
|
+
},
|
|
459
|
+
];
|
|
460
|
+
return inquirer_1.default.prompt(promptData)
|
|
461
|
+
.then(answers => {
|
|
462
|
+
const shouldRemove = answers.confirmRemove;
|
|
463
|
+
if (shouldRemove) {
|
|
464
|
+
return uninstall();
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI).info(`CLI Package removal aborted`);
|
|
468
|
+
Shared.CLIOperations.ExitCLISafe(0);
|
|
469
|
+
}
|
|
470
|
+
});
|
|
471
|
+
}
|
|
239
472
|
})
|
|
240
473
|
.catch(error => {
|
|
241
|
-
|
|
474
|
+
if (error.isTtyError) {
|
|
475
|
+
// Prompt couldn't be rendered in the current environment
|
|
476
|
+
Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI).errorContext(loggerContext, chalk_1.default.red(`There was a problem rendering the removal confirmation prompt in your environment. \n\n To remove without prompts, add the -y param to the end of the command and try again.`, error));
|
|
477
|
+
}
|
|
478
|
+
Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI).errorContext(loggerContext, chalk_1.default.red(`CLI Package removal error`, error));
|
|
242
479
|
Shared.CLIOperations.ExitCLISafe(1);
|
|
243
480
|
});
|
|
244
481
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coalescesoftware/coa",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.115",
|
|
4
4
|
"license": "ISC",
|
|
5
5
|
"author": "Coalesce Automation, Inc.",
|
|
6
6
|
"main": "index.js",
|
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
"start-cli-debug": "yarn run start --debug"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@coalescesoftware/shared": "^1.0.
|
|
15
|
+
"@coalescesoftware/shared": "^1.0.115",
|
|
16
16
|
"chalk": "^4.1.2",
|
|
17
17
|
"commander": "^9.2.0",
|
|
18
18
|
"firebase": "8.2.0",
|
|
19
19
|
"immer": "^9.0.12",
|
|
20
20
|
"ini": "^3.0.0",
|
|
21
21
|
"ink": "^3.2.0",
|
|
22
|
+
"inquirer": "^8.2.4",
|
|
22
23
|
"react": "^17.0.2",
|
|
23
24
|
"react-redux": "^7.2.6"
|
|
24
25
|
},
|