@coalescesoftware/coa 1.0.112 → 1.0.113
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/{Common.js → CommonCLI/CommonCLI.js} +28 -9
- package/bin/CommonCLI/CommonCLI.test.js +28 -0
- package/bin/CommonCLI.js +13 -1
- package/bin/Deploy/Deploy.js +70 -0
- package/bin/Plan/Plan.js +41 -0
- package/bin/Refresh/Refresh.js +65 -0
- package/bin/RunOutput.js +82 -0
- package/bin/index.js +17 -9
- package/package.json +2 -2
- package/bin/CLIOperations.js +0 -135
- package/bin/Profile.js +0 -53
|
@@ -19,11 +19,32 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.GetUserConnectionForCLI = exports.CleanupCLIJob = void 0;
|
|
22
|
+
exports.GetUserConnectionForCLI = exports.CleanupCLIJob = exports.GetToken = exports.GetConfig = exports.ConsoleLog = void 0;
|
|
23
23
|
const Shared = __importStar(require("@coalescesoftware/shared"));
|
|
24
|
-
const fs = __importStar(require("fs"));
|
|
25
24
|
const crypto = __importStar(require("crypto"));
|
|
25
|
+
const fs = __importStar(require("fs"));
|
|
26
26
|
const RunnerBackendLogger = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.RunnerBackend);
|
|
27
|
+
exports.ConsoleLog = console.log;
|
|
28
|
+
const GetConfig = (path) => {
|
|
29
|
+
try {
|
|
30
|
+
return JSON.parse(fs.readFileSync(path, { encoding: "utf8" }));
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
(0, exports.ConsoleLog)(`Unable to read or parse config file: ${error}`);
|
|
34
|
+
throw error;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.GetConfig = GetConfig;
|
|
38
|
+
const GetToken = (path) => {
|
|
39
|
+
try {
|
|
40
|
+
return fs.readFileSync(path, { encoding: "utf8" }).trim();
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
(0, exports.ConsoleLog)(`Unable to read token file: ${error}`);
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
exports.GetToken = GetToken;
|
|
27
48
|
const CleanupCLIJob = (runCompletion, firebase, logContext, action) => {
|
|
28
49
|
const cleanupPromise = new Promise((resolve, reject) => {
|
|
29
50
|
let promiseError = null;
|
|
@@ -75,20 +96,18 @@ const GetKeyPairKey = (keyPairPath) => {
|
|
|
75
96
|
const GetUserConnectionForCLI = (userID, runInfo) => {
|
|
76
97
|
return new Promise((resolve, reject) => {
|
|
77
98
|
var _a, _b, _c, _d;
|
|
99
|
+
Shared.Common.assert(Shared.Logging.LoggingArea.RunnerBackend, !!((_a = runInfo.userCredentials) === null || _a === void 0 ? void 0 : _a.snowflakeAuthType), "ERROR (GetUserConnectionForCLI): no auth type provided");
|
|
78
100
|
const output = {
|
|
79
101
|
connectionDetails: {
|
|
80
102
|
userID,
|
|
81
103
|
user: "mx2323",
|
|
82
104
|
role: "SYSADMIN",
|
|
83
105
|
warehouse: "COMPUTE_WH",
|
|
84
|
-
authenticator: (
|
|
106
|
+
authenticator: (_b = runInfo.userCredentials) === null || _b === void 0 ? void 0 : _b.snowflakeAuthType
|
|
85
107
|
},
|
|
86
|
-
connectionType: (
|
|
108
|
+
connectionType: (_c = runInfo.userCredentials) === null || _c === void 0 ? void 0 : _c.snowflakeAuthType
|
|
87
109
|
};
|
|
88
|
-
if (
|
|
89
|
-
reject(new Error("ERROR (GetUserConnectionForCLI): no auth type provided"));
|
|
90
|
-
}
|
|
91
|
-
else if (((_d = runInfo.userCredentials) === null || _d === void 0 ? void 0 : _d.snowflakeAuthType) === Shared.ConnectionOperations.EUserConnectionTypes.keyPair) {
|
|
110
|
+
if (((_d = runInfo.userCredentials) === null || _d === void 0 ? void 0 : _d.snowflakeAuthType) === Shared.ConnectionOperations.EUserConnectionTypes.keyPair) {
|
|
92
111
|
GetKeyPairKey(Shared.Common.getValueSafe(runInfo, ["userCredentials", "snowflakeKeyPairPath"], ""))
|
|
93
112
|
.then((keyPair) => {
|
|
94
113
|
output.connectionDetails.keyPair = keyPair;
|
|
@@ -104,4 +123,4 @@ const GetUserConnectionForCLI = (userID, runInfo) => {
|
|
|
104
123
|
});
|
|
105
124
|
};
|
|
106
125
|
exports.GetUserConnectionForCLI = GetUserConnectionForCLI;
|
|
107
|
-
//# sourceMappingURL=
|
|
126
|
+
//# sourceMappingURL=CommonCLI.js.map
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
const CommonCLI = __importStar(require("./CommonCLI"));
|
|
23
|
+
test("should fail to read and parse invalid JSON", () => {
|
|
24
|
+
expect(() => {
|
|
25
|
+
CommonCLI.GetConfig("cli/src/__mocks__/invalid.json");
|
|
26
|
+
}).toThrow("Unexpected token I in JSON at position 0");
|
|
27
|
+
});
|
|
28
|
+
//# sourceMappingURL=CommonCLI.test.js.map
|
package/bin/CommonCLI.js
CHANGED
|
@@ -19,11 +19,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
19
|
return result;
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.GetUserConnectionForCLI = exports.CleanupCLIJob = void 0;
|
|
22
|
+
exports.FinishWithOutputFile = exports.GetUserConnectionForCLI = exports.CleanupCLIJob = void 0;
|
|
23
23
|
const Shared = __importStar(require("@coalescesoftware/shared"));
|
|
24
24
|
const fs = __importStar(require("fs"));
|
|
25
25
|
const crypto = __importStar(require("crypto"));
|
|
26
|
+
const RunOutput = __importStar(require("./RunOutput"));
|
|
26
27
|
const RunnerBackendLogger = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.RunnerBackend);
|
|
28
|
+
const LogCLIInternal = Shared.Logging.GetLogger(Shared.Logging.LoggingArea.CLI_INTERNAL);
|
|
27
29
|
const CleanupCLIJob = (runCompletion, firebase, logContext, action) => {
|
|
28
30
|
const cleanupPromise = new Promise((resolve, reject) => {
|
|
29
31
|
let promiseError = null;
|
|
@@ -104,4 +106,14 @@ const GetUserConnectionForCLI = (userID, runInfo) => {
|
|
|
104
106
|
});
|
|
105
107
|
};
|
|
106
108
|
exports.GetUserConnectionForCLI = GetUserConnectionForCLI;
|
|
109
|
+
const FinishWithOutputFile = (logContextToUse, outputFilePath, runCounter, token) => {
|
|
110
|
+
if (!outputFilePath) {
|
|
111
|
+
return Promise.resolve();
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
LogCLIInternal.infoContext(logContextToUse, "saving run results to file", outputFilePath);
|
|
115
|
+
return RunOutput.SaveRunOutputToFile(outputFilePath, runCounter.toString(), token);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
exports.FinishWithOutputFile = FinishWithOutputFile;
|
|
107
119
|
//# sourceMappingURL=CommonCLI.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
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.DeployWithCLI = 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 plan
|
|
34
|
+
* @param config
|
|
35
|
+
* @param token
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
const DeployWithCLI = (plan, config, token) => {
|
|
39
|
+
let firebase;
|
|
40
|
+
let logContext;
|
|
41
|
+
let teamDetailsStored, runInfo, RunSQL;
|
|
42
|
+
return Shared.SchedulerOperations.AuthenticateFirebaseTokenAndRetrieveTeamInfoForCLI(token, undefined)
|
|
43
|
+
.then((teamDetails) => {
|
|
44
|
+
var _a;
|
|
45
|
+
teamDetailsStored = teamDetails;
|
|
46
|
+
const { teamInfo, teamInfo: { fbUserID: userID, fbTeamID: teamID } } = teamDetails;
|
|
47
|
+
firebase = teamDetails.firebase;
|
|
48
|
+
const environmentID = (_a = config.runDetails) === null || _a === void 0 ? void 0 : _a.environmentID;
|
|
49
|
+
logContext = Shared.Logging.CreateLogContext(teamID, environmentID, userID);
|
|
50
|
+
const connectionCache = new Shared.Snowflake.ConnectionStorageClass();
|
|
51
|
+
RunSQL = Shared.SQLExecutorCreators.CreateRunSQLWithoutScheduler(teamDetails, connectionCache);
|
|
52
|
+
runInfo = Shared.DeployOperations.CreateDeployRequestObject(plan.plan, plan.environmentState, teamInfo, plan.gitInfo, plan.targetEnvironment, "");
|
|
53
|
+
runInfo.userCredentials = config.userCredentials;
|
|
54
|
+
return CommonCLI.GetUserConnectionForCLI(userID, runInfo);
|
|
55
|
+
})
|
|
56
|
+
.then((connection) => {
|
|
57
|
+
LogCLI.infoContext(logContext, "Deploy starting (CLI)");
|
|
58
|
+
return Shared.SchedulerOperations.HandleDeploy(runInfo, teamDetailsStored, RunSQL, connection);
|
|
59
|
+
})
|
|
60
|
+
.then(({ runCounter, runCompletion }) => {
|
|
61
|
+
const cleanupPromise = CommonCLI.CleanupCLIJob(runCompletion, firebase, logContext, "Deploy");
|
|
62
|
+
return {
|
|
63
|
+
runCounter,
|
|
64
|
+
runCompletion: cleanupPromise,
|
|
65
|
+
logContext,
|
|
66
|
+
};
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
exports.DeployWithCLI = DeployWithCLI;
|
|
70
|
+
//# sourceMappingURL=Deploy.js.map
|
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
|
|
@@ -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
|
@@ -31,6 +31,7 @@ const Shared = __importStar(require("@coalescesoftware/shared"));
|
|
|
31
31
|
const CLIProfile = __importStar(require("./CLIProfile"));
|
|
32
32
|
const chalk_1 = __importDefault(require("chalk"));
|
|
33
33
|
const commander_1 = require("commander");
|
|
34
|
+
const CommonCLI = __importStar(require("./CommonCLI"));
|
|
34
35
|
const fs_1 = __importDefault(require("fs"));
|
|
35
36
|
// setting this needs to be first!
|
|
36
37
|
Shared.Logging.SetHTTPTransportOptions(Shared.Logging.EHttpServices.CLI);
|
|
@@ -120,6 +121,7 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Plan))
|
|
|
120
121
|
*/
|
|
121
122
|
AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
122
123
|
.option("-p, --plan <plan-location>", "Coalesce plan location", "./coa-plan.json")
|
|
124
|
+
.option("-o, --out <output json>", "Run Results Output in Json ")
|
|
123
125
|
.description("run a coalesce deployment plan")
|
|
124
126
|
.action((options, cmd) => {
|
|
125
127
|
const cliOverrides = ComputeCLIOverrides(cmd);
|
|
@@ -161,7 +163,10 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
|
161
163
|
const { runCounter, runCompletion, logContext } = result;
|
|
162
164
|
logContextToUse = logContext !== null && logContext !== void 0 ? logContext : {};
|
|
163
165
|
LogCLI.infoContext(logContextToUse, chalk_1.default.whiteBright(`Job ${runCounter}: ${chalk_1.default.green("running")}...`));
|
|
164
|
-
return runCompletion
|
|
166
|
+
return runCompletion.finally(() => {
|
|
167
|
+
const outputFilePath = optsWithGlobals.out;
|
|
168
|
+
CommonCLI.FinishWithOutputFile(logContextToUse, outputFilePath, runCounter, config.token);
|
|
169
|
+
});
|
|
165
170
|
})
|
|
166
171
|
.then(() => {
|
|
167
172
|
LogCLI.infoContext(logContextToUse, "Deployment successful!");
|
|
@@ -178,6 +183,7 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Deploy))
|
|
|
178
183
|
*/
|
|
179
184
|
AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Refresh))
|
|
180
185
|
.description("runs a Coalesce pipeline")
|
|
186
|
+
.option("-o, --out <output json>", "Run Results Output in Json ")
|
|
181
187
|
.action((options, command) => {
|
|
182
188
|
const cliOverrides = ComputeCLIOverrides(command);
|
|
183
189
|
const optsWithGlobals = command.optsWithGlobals();
|
|
@@ -230,16 +236,18 @@ AddOverridesToCommand(program.command(Shared.CLIOperations.ECLICommands.Refresh)
|
|
|
230
236
|
const { runCounter, runCompletion, logContext } = result;
|
|
231
237
|
logContextToUse = logContext !== null && logContext !== void 0 ? logContext : {};
|
|
232
238
|
LogCLI.infoContext(logContextToUse, chalk_1.default.whiteBright(`Refresh run initialized. RunCounter: ${runCounter}`));
|
|
233
|
-
return runCompletion
|
|
239
|
+
return runCompletion.finally(() => {
|
|
240
|
+
const outputFilePath = optsWithGlobals.out;
|
|
241
|
+
CommonCLI.FinishWithOutputFile(logContextToUse, outputFilePath, runCounter, config.token);
|
|
242
|
+
}).then(() => {
|
|
243
|
+
LogCLI.infoContext(logContextToUse, "Refresh successful!");
|
|
244
|
+
Shared.CLIOperations.ExitCLISafe(0);
|
|
245
|
+
});
|
|
234
246
|
})
|
|
235
|
-
.
|
|
236
|
-
LogCLI.
|
|
237
|
-
Shared.CLIOperations.ExitCLISafe(
|
|
247
|
+
.catch(error => {
|
|
248
|
+
LogCLI.errorContext(logContextToUse, chalk_1.default.redBright(`Error during refresh!: ${error.toString()}`));
|
|
249
|
+
Shared.CLIOperations.ExitCLISafe(1);
|
|
238
250
|
});
|
|
239
|
-
})
|
|
240
|
-
.catch(error => {
|
|
241
|
-
LogCLI.errorContext(logContextToUse, chalk_1.default.redBright(`Error during refresh!: ${error.toString()}`));
|
|
242
|
-
Shared.CLIOperations.ExitCLISafe(1);
|
|
243
251
|
});
|
|
244
252
|
});
|
|
245
253
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coalescesoftware/coa",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.113",
|
|
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.113",
|
|
16
16
|
"chalk": "^4.1.2",
|
|
17
17
|
"commander": "^9.2.0",
|
|
18
18
|
"firebase": "8.2.0",
|
package/bin/CLIOperations.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
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.DisableNonCLIConsoleLogs = exports.ExitCLISafe = exports.VerifyAllRefreshItems = exports.VerifyAllPlanItems = exports.VerifyAllDeployItems = void 0;
|
|
23
|
-
const Templates = __importStar(require("@coalescesoftware/shared/src/Templates"));
|
|
24
|
-
const R = __importStar(require("runtypes"));
|
|
25
|
-
const Logging = __importStar(require("@coalescesoftware/shared/src/Logging"));
|
|
26
|
-
const Firebase = __importStar(require("@coalescesoftware/shared/src/Firebase"));
|
|
27
|
-
const LogCLI = Logging.GetLogger(Logging.LoggingArea.CLI);
|
|
28
|
-
const UserCredentialsDeployType = R.Record({
|
|
29
|
-
snowflakeUsername: R.String,
|
|
30
|
-
snowflakePassword: R.String.optional(),
|
|
31
|
-
snowflakeRole: R.String.optional(),
|
|
32
|
-
snowflakeWarehouse: R.String.optional(),
|
|
33
|
-
});
|
|
34
|
-
const UserCredentialsRefreshType = R.Record({
|
|
35
|
-
snowflakePassword: R.String.optional(),
|
|
36
|
-
});
|
|
37
|
-
const BaseEnvironmentType = R.Record({
|
|
38
|
-
environmentID: R.Union(R.String, R.Number),
|
|
39
|
-
});
|
|
40
|
-
const EnvironmentRefreshType = BaseEnvironmentType.extend({
|
|
41
|
-
jobID: R.String.optional(),
|
|
42
|
-
});
|
|
43
|
-
const DeployConfig = R.Record({
|
|
44
|
-
token: userCredentials, UserCredentialsDeployType,
|
|
45
|
-
});
|
|
46
|
-
const RefreshConfig = R.Record({
|
|
47
|
-
userCredentials: UserCredentialsRefreshType,
|
|
48
|
-
runDetails: EnvironmentRefreshType,
|
|
49
|
-
});
|
|
50
|
-
const Plan = R.Record({
|
|
51
|
-
version: R.Number,
|
|
52
|
-
targetEnvironment: R.Number,
|
|
53
|
-
plan: R.Unknown,
|
|
54
|
-
environmentState: R.Unknown,
|
|
55
|
-
gitInfo: R.Unknown,
|
|
56
|
-
});
|
|
57
|
-
const PlanConfig = R.Record({
|
|
58
|
-
runDetails: BaseEnvironmentType,
|
|
59
|
-
});
|
|
60
|
-
const Token = R.String;
|
|
61
|
-
const VerifyAllDeployItems = (plan,
|
|
62
|
-
// TODO-AI: move coalesceToken out of usercredentials to one level higher
|
|
63
|
-
config, token) => {
|
|
64
|
-
const runTypesAndObjectsToVerify = [
|
|
65
|
-
{ runType: Plan, object: plan },
|
|
66
|
-
{ runType: DeployConfig, object: config },
|
|
67
|
-
{ runType: Token, object: token },
|
|
68
|
-
];
|
|
69
|
-
return Templates.ValidateMultipleRunTypesAndReturnSuccessOrErrorMessages(runTypesAndObjectsToVerify);
|
|
70
|
-
};
|
|
71
|
-
exports.VerifyAllDeployItems = VerifyAllDeployItems;
|
|
72
|
-
const VerifyAllPlanItems = (config) => {
|
|
73
|
-
const { coalescetoken: token } = config;
|
|
74
|
-
const runTypesAndObjectsToVerify = [
|
|
75
|
-
{ runType: PlanConfig, object: config },
|
|
76
|
-
{ runType: Token, object: token },
|
|
77
|
-
];
|
|
78
|
-
return Templates.ValidateMultipleRunTypesAndReturnSuccessOrErrorMessages(runTypesAndObjectsToVerify);
|
|
79
|
-
};
|
|
80
|
-
exports.VerifyAllPlanItems = VerifyAllPlanItems;
|
|
81
|
-
const VerifyAllRefreshItems = (config, token) => {
|
|
82
|
-
const runTypesAndObjectsToVerify = [
|
|
83
|
-
{ runType: RefreshConfig, object: config },
|
|
84
|
-
{ runType: Token, object: token },
|
|
85
|
-
];
|
|
86
|
-
return Templates.ValidateMultipleRunTypesAndReturnSuccessOrErrorMessages(runTypesAndObjectsToVerify);
|
|
87
|
-
};
|
|
88
|
-
exports.VerifyAllRefreshItems = VerifyAllRefreshItems;
|
|
89
|
-
/**
|
|
90
|
-
* Should be used in place of all process.exit() or process.exitCode = x instances. process.exit() kills all processes immediately and we lose logs and can
|
|
91
|
-
* cause other issues, process.exitCode = x will hang indefinitely if firebase apps aren't deleted first
|
|
92
|
-
* @param exitCode normal nodeJS exit code that would be passed to process.exit or process.exitCode
|
|
93
|
-
*/
|
|
94
|
-
const ExitCLISafe = (exitCode) => {
|
|
95
|
-
// force exit if FB fails to exit (or less likely, logs fail to send) in 5 seconds
|
|
96
|
-
const forceExitTimeout = setTimeout(() => {
|
|
97
|
-
LogCLI.alert("CLI exit timeout");
|
|
98
|
-
// inner timeout is so the above log can be sent to Datadog; proper methods for waiting on winston transports don't work on our datadog transport
|
|
99
|
-
setTimeout(() => process.exit(exitCode), 1000);
|
|
100
|
-
}, 5000);
|
|
101
|
-
try {
|
|
102
|
-
const firebase = Firebase.justFirebase;
|
|
103
|
-
// Firebase Apps is an App[]
|
|
104
|
-
if (firebase.apps.length) {
|
|
105
|
-
firebase.apps.forEach((app) => {
|
|
106
|
-
firebase.app(app.name).delete();
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
clearTimeout(forceExitTimeout);
|
|
110
|
-
process.exitCode = exitCode;
|
|
111
|
-
}
|
|
112
|
-
catch (error) {
|
|
113
|
-
LogCLI.error("Error while attempting to close Firebase apps in CLI");
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
exports.ExitCLISafe = ExitCLISafe;
|
|
117
|
-
const DisableNonCLIConsoleLogs = () => {
|
|
118
|
-
const allLoggersConfigs = {};
|
|
119
|
-
Object.values(Logging.LoggingArea).forEach(logArea => {
|
|
120
|
-
if (logArea !== Logging.LoggingArea.CLI) {
|
|
121
|
-
allLoggersConfigs[logArea] = {
|
|
122
|
-
level: Logging.LoggingAreas[logArea].level,
|
|
123
|
-
transports: [Logging.GetHttpTransport(), Logging.GetOurTransport()]
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
});
|
|
127
|
-
const CLIAreaInfo = Logging.LoggingAreas[Logging.LoggingArea.CLI];
|
|
128
|
-
allLoggersConfigs[Logging.LoggingArea.CLI] = {
|
|
129
|
-
level: CLIAreaInfo.level,
|
|
130
|
-
transports: Logging.GetDefaultTransports(CLIAreaInfo)
|
|
131
|
-
};
|
|
132
|
-
Logging.ReconfigureLoggers(allLoggersConfigs);
|
|
133
|
-
};
|
|
134
|
-
exports.DisableNonCLIConsoleLogs = DisableNonCLIConsoleLogs;
|
|
135
|
-
//# sourceMappingURL=CLIOperations.js.map
|
package/bin/Profile.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/* eslint-disable multiline-comment-style */
|
|
3
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
6
|
-
}) : (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
o[k2] = m[k];
|
|
9
|
-
}));
|
|
10
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
11
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
12
|
-
}) : function(o, v) {
|
|
13
|
-
o["default"] = v;
|
|
14
|
-
});
|
|
15
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
16
|
-
if (mod && mod.__esModule) return mod;
|
|
17
|
-
var result = {};
|
|
18
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
19
|
-
__setModuleDefault(result, mod);
|
|
20
|
-
return result;
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
const Shared = __importStar(require("@coalescesoftware/shared"));
|
|
24
|
-
const GetCLIConfigFromCLIProfile = (CLIProfile) => {
|
|
25
|
-
return {
|
|
26
|
-
token: "AIwUaOn1n7RzQXkyx6mwVO7x17s-agEgNHtIROspfSBx-QjsII6O9Kp7Qxpl_7TtjG3a59dq32VBeItGG5X6sN2kKmn54u-RMFxoJnZg0VXh3p1qM-0Palu7hVDiMIFuNdX2dyOQy2DK7WLjwbH6kXFrDQy8zLlDCKFGxzcMMNU3wp2TPtb2uxbZYtVcCqZg3be7Lr3esaKYhJLcKuW5lixc_JCAEhMjQw",
|
|
27
|
-
runDetails: {
|
|
28
|
-
environmentID: 2
|
|
29
|
-
},
|
|
30
|
-
userCredentials: {
|
|
31
|
-
snowflakeAccount: "ww56326.us-central1.gcp",
|
|
32
|
-
snowflakeAuthType: Shared.ConnectionOperations.EUserConnectionTypes.basic,
|
|
33
|
-
snowflakePassword: "ThisIsAPassword1!",
|
|
34
|
-
snowflakeRole: "SYSADMIN",
|
|
35
|
-
snowflakeUsername: "mx2323",
|
|
36
|
-
snowflakeWarehouse: "COMPUTE_WH"
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
// TODO: create a profile class that takes the cmd object in the constructor
|
|
41
|
-
// store contents of configuration file
|
|
42
|
-
// if no config file path option
|
|
43
|
-
// check if there's a valid configuration file in the current working directory or home directory
|
|
44
|
-
// if none exists
|
|
45
|
-
// create a configuration file with empty default profile
|
|
46
|
-
// prompt user to either rerun the command with valid config file, per-command flags for all profile values, or run `coa init` to go through prompts for creating a profile
|
|
47
|
-
// if a configuration file exists, but any required property holds a falsy value
|
|
48
|
-
// inform user which fields are missing and prompt to run `coa init` to fill out invalid fields
|
|
49
|
-
// method: validate configuration file
|
|
50
|
-
// method: get final profile for current command
|
|
51
|
-
// create a function getCLIProfile that returns a CLI profile, this should return a promise that resolve in CLI profile
|
|
52
|
-
// hardcode a profile
|
|
53
|
-
//# sourceMappingURL=Profile.js.map
|