@opscompass/opscompass-cli 1.0.47 → 1.3.1
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/colors.js +5 -5
- package/credentials.js +20 -29
- package/environment/current.js +6 -6
- package/environment/demo.js +6 -6
- package/environment/dev.js +6 -6
- package/environment/local.js +6 -6
- package/environment/production.js +6 -6
- package/error.js +1 -1
- package/index.js +20 -20
- package/lib/cliHelpers.js +34 -15
- package/lib/consts.js +2 -11
- package/lib/homeInteraction.js +21 -22
- package/lib/maskValues.js +17 -17
- package/lib/parseMetrics.js +25 -21
- package/lib/pgpTools.js +8 -10
- package/lib/utils.js +15 -19
- package/login.js +90 -40
- package/modules/accounts.js +32 -26
- package/modules/compliance.js +75 -76
- package/modules/data-gathering-scripts.js +41 -41
- package/modules/defaults.js +12 -12
- package/modules/expiration-info.js +54 -25
- package/modules/license-manager/microsoft.js +95 -72
- package/modules/license-manager/nutanix.js +31 -22
- package/modules/license-manager/vcenter.js +31 -22
- package/modules/license-manager.js +89 -91
- package/modules/resources.js +140 -70
- package/modules.js +31 -15
- package/oauth.js +2 -2
- package/opscompass.js +8 -9
- package/package.json +3 -2
- package/updates.js +9 -11
package/colors.js
CHANGED
|
@@ -5,8 +5,8 @@ global.yellowText = "\x1b[33m%s\x1b[0m";
|
|
|
5
5
|
global.greenText = "\x1b[32m%s\x1b[0m";
|
|
6
6
|
global.redText = "\x1b[31m%s\x1b[0m";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
};
|
|
8
|
+
const yellowText = global.yellowText;
|
|
9
|
+
const greenText = global.greenText;
|
|
10
|
+
const redText = global.redText;
|
|
11
|
+
|
|
12
|
+
export { yellowText, greenText, redText };
|
package/credentials.js
CHANGED
|
@@ -1,30 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} = require("./lib/homeInteraction.js");
|
|
8
|
-
const {
|
|
9
|
-
canReadFile, FilePermissions
|
|
10
|
-
} = require("./lib/cliHelpers.js");
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { redeemRefreshToken } from "./oauth.js";
|
|
4
|
+
import { opscompassHome, cliCommand } from "./environment/current.js";
|
|
5
|
+
import { writeFileToHome } from "./lib/homeInteraction.js";
|
|
6
|
+
import { canReadFile, FilePermissions } from "./lib/cliHelpers.js";
|
|
11
7
|
|
|
12
8
|
function canReadStoredCredentials() {
|
|
13
|
-
return canReadFile(
|
|
14
|
-
path.join(
|
|
15
|
-
opscompassHome,
|
|
16
|
-
"tokens.json"
|
|
17
|
-
)
|
|
18
|
-
);
|
|
9
|
+
return canReadFile(path.join(opscompassHome, "tokens.json"));
|
|
19
10
|
}
|
|
20
11
|
|
|
21
12
|
async function storeCredentials(data) {
|
|
22
13
|
// calculate the expires_at from the expires_in
|
|
23
14
|
if (data.expires_in) {
|
|
24
|
-
data.expires_at = new Date(Date.now() +
|
|
15
|
+
data.expires_at = new Date(Date.now() + data.expires_in * 1000);
|
|
25
16
|
}
|
|
26
17
|
|
|
27
|
-
return writeFileToHome(
|
|
18
|
+
return writeFileToHome("tokens.json", data, 0o600);
|
|
28
19
|
}
|
|
29
20
|
|
|
30
21
|
async function getCredentials() {
|
|
@@ -32,7 +23,7 @@ async function getCredentials() {
|
|
|
32
23
|
return new Promise((resolve, reject) => {
|
|
33
24
|
try {
|
|
34
25
|
fs.readFile(
|
|
35
|
-
path.join(opscompassHome,
|
|
26
|
+
path.join(opscompassHome, "tokens.json"),
|
|
36
27
|
async (err, data) => {
|
|
37
28
|
try {
|
|
38
29
|
// if the read failed, reject
|
|
@@ -43,11 +34,13 @@ async function getCredentials() {
|
|
|
43
34
|
|
|
44
35
|
const tokensData = JSON.parse(data.toString());
|
|
45
36
|
const expires_at = new Date(tokensData.expires_at);
|
|
46
|
-
|
|
37
|
+
|
|
47
38
|
// if the token has already expired,
|
|
48
39
|
// redeem the refresh token and return that
|
|
49
40
|
if (new Date() > expires_at && tokensData.refresh_token) {
|
|
50
|
-
const refreshedTokenResponse = await redeemRefreshToken(
|
|
41
|
+
const refreshedTokenResponse = await redeemRefreshToken(
|
|
42
|
+
tokensData.refresh_token,
|
|
43
|
+
);
|
|
51
44
|
const refreshedTokenData = refreshedTokenResponse.data;
|
|
52
45
|
await storeCredentials(refreshedTokenData);
|
|
53
46
|
resolve(refreshedTokenData);
|
|
@@ -57,10 +50,12 @@ async function getCredentials() {
|
|
|
57
50
|
} catch (innerError) {
|
|
58
51
|
reject();
|
|
59
52
|
console.log();
|
|
60
|
-
console.warn(
|
|
53
|
+
console.warn(
|
|
54
|
+
`You aren't logged in. Please run '${cliCommand} login' to log in.`,
|
|
55
|
+
);
|
|
61
56
|
console.log();
|
|
62
|
-
|
|
63
|
-
}
|
|
57
|
+
}
|
|
58
|
+
},
|
|
64
59
|
);
|
|
65
60
|
} catch (e) {
|
|
66
61
|
// this should only happen if the path can't be built
|
|
@@ -69,8 +64,4 @@ async function getCredentials() {
|
|
|
69
64
|
});
|
|
70
65
|
}
|
|
71
66
|
|
|
72
|
-
|
|
73
|
-
canReadStoredCredentials,
|
|
74
|
-
getCredentials,
|
|
75
|
-
storeCredentials,
|
|
76
|
-
};
|
|
67
|
+
export { canReadStoredCredentials, getCredentials, storeCredentials };
|
package/environment/current.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// production: OpsCompassClient is referenced from npm package
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import {
|
|
4
4
|
OpsCompassClient,
|
|
5
5
|
ScriptType,
|
|
6
6
|
OAuthHandler,
|
|
7
7
|
licenseManagerConfigurationTypes,
|
|
8
|
-
}
|
|
8
|
+
} from "@opscompass/opscompass-api";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { homedir } from "os";
|
|
12
12
|
const opscompassHome = path.join(homedir(), ".opscompass");
|
|
13
13
|
const cliCommand = "opscompass";
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ const clientId = "vOakDaOv4L26f3uuI4sp3KC1Sov3nsW2";
|
|
|
18
18
|
const oAuthClient = new OAuthHandler(clientId);
|
|
19
19
|
const isLocal = false;
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
export {
|
|
22
22
|
OpsCompassClient,
|
|
23
23
|
licenseManagerConfigurationTypes,
|
|
24
24
|
ScriptType,
|
|
@@ -26,5 +26,5 @@ module.exports = {
|
|
|
26
26
|
opscompassHome,
|
|
27
27
|
isLocal,
|
|
28
28
|
cliCommand,
|
|
29
|
-
decoder: "TjFXOWhWdnppb2Zoa2ZFcmd1TWI",
|
|
30
29
|
};
|
|
30
|
+
export const decoder = "TjFXOWhWdnppb2Zoa2ZFcmd1TWI";
|
package/environment/demo.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// demo: @opscompass/opscompass-api-demo
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import {
|
|
4
4
|
OpsCompassClient,
|
|
5
5
|
ScriptType,
|
|
6
6
|
OAuthHandler,
|
|
7
7
|
licenseManagerConfigurationTypes,
|
|
8
|
-
}
|
|
8
|
+
} from "@opscompass/opscompass-api-demo";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { homedir } from "os";
|
|
12
12
|
const opscompassHome = path.join(homedir(), ".opscompassdemo");
|
|
13
13
|
const cliCommand = "opscompassdemo";
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ const audience = "https://opscompass-api-demo.azure-api.net";
|
|
|
18
18
|
const oAuthClient = new OAuthHandler(clientId, authDomain, audience);
|
|
19
19
|
const isLocal = false;
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
export {
|
|
22
22
|
OpsCompassClient,
|
|
23
23
|
licenseManagerConfigurationTypes,
|
|
24
24
|
ScriptType,
|
|
@@ -26,5 +26,5 @@ module.exports = {
|
|
|
26
26
|
opscompassHome,
|
|
27
27
|
isLocal,
|
|
28
28
|
cliCommand,
|
|
29
|
-
decoder: "TjFXOWhWdnppb2Zoa2ZFcmd1TWI",
|
|
30
29
|
};
|
|
30
|
+
export const decoder = "TjFXOWhWdnppb2Zoa2ZFcmd1TWI";
|
package/environment/dev.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// dev: @opscompass/opscompass-api-dev
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import {
|
|
4
4
|
OpsCompassClient,
|
|
5
5
|
ScriptType,
|
|
6
6
|
OAuthHandler,
|
|
7
7
|
licenseManagerConfigurationTypes,
|
|
8
|
-
}
|
|
8
|
+
} from "@opscompass/opscompass-api-dev";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { homedir } from "os";
|
|
12
12
|
const opscompassHome = path.join(homedir(), ".opscompassdev");
|
|
13
13
|
const cliCommand = "opscompassdev";
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ const audience = "https://fa-sampleapi-cus-dev.azurewebsites.net";
|
|
|
18
18
|
const oAuthClient = new OAuthHandler(clientId, authDomain, audience);
|
|
19
19
|
const isLocal = false;
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
export {
|
|
22
22
|
OpsCompassClient,
|
|
23
23
|
licenseManagerConfigurationTypes,
|
|
24
24
|
ScriptType,
|
|
@@ -26,5 +26,5 @@ module.exports = {
|
|
|
26
26
|
opscompassHome,
|
|
27
27
|
isLocal,
|
|
28
28
|
cliCommand,
|
|
29
|
-
decoder: "TjFXOWhWdnppb2Zoa2ZFcmd1TWI",
|
|
30
29
|
};
|
|
30
|
+
export const decoder = "TjFXOWhWdnppb2Zoa2ZFcmd1TWI";
|
package/environment/local.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// local: @opscompass/opscompass-api is pointing to the local file system.
|
|
2
2
|
// set up your local functions to use dev's token settings.
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import {
|
|
5
5
|
OpsCompassClient,
|
|
6
6
|
ScriptType,
|
|
7
7
|
OAuthHandler,
|
|
8
8
|
licenseManagerConfigurationTypes,
|
|
9
|
-
}
|
|
9
|
+
} from "@opscompass/opscompass-api";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
import path from "path";
|
|
12
|
+
import { homedir } from "os";
|
|
13
13
|
const opscompassHome = path.join(homedir(), ".opscompassdev");
|
|
14
14
|
const cliCommand = "opscompassdev";
|
|
15
15
|
|
|
@@ -19,7 +19,7 @@ const audience = "https://fa-sampleapi-cus-dev.azurewebsites.net";
|
|
|
19
19
|
const oAuthClient = new OAuthHandler(clientId, authDomain, audience);
|
|
20
20
|
const isLocal = true;
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
export {
|
|
23
23
|
OpsCompassClient,
|
|
24
24
|
licenseManagerConfigurationTypes,
|
|
25
25
|
ScriptType,
|
|
@@ -27,5 +27,5 @@ module.exports = {
|
|
|
27
27
|
opscompassHome,
|
|
28
28
|
isLocal,
|
|
29
29
|
cliCommand,
|
|
30
|
-
decoder: "TjFXOWhWdnppb2Zoa2ZFcmd1TWI",
|
|
31
30
|
};
|
|
31
|
+
export const decoder = "TjFXOWhWdnppb2Zoa2ZFcmd1TWI";
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
// production: OpsCompassClient is referenced from npm package
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import {
|
|
4
4
|
OpsCompassClient,
|
|
5
5
|
ScriptType,
|
|
6
6
|
OAuthHandler,
|
|
7
7
|
licenseManagerConfigurationTypes,
|
|
8
|
-
}
|
|
8
|
+
} from "@opscompass/opscompass-api";
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
import path from "path";
|
|
11
|
+
import { homedir } from "os";
|
|
12
12
|
const opscompassHome = path.join(homedir(), ".opscompass");
|
|
13
13
|
const cliCommand = "opscompass";
|
|
14
14
|
|
|
@@ -18,7 +18,7 @@ const clientId = "vOakDaOv4L26f3uuI4sp3KC1Sov3nsW2";
|
|
|
18
18
|
const oAuthClient = new OAuthHandler(clientId);
|
|
19
19
|
const isLocal = false;
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
export {
|
|
22
22
|
OpsCompassClient,
|
|
23
23
|
licenseManagerConfigurationTypes,
|
|
24
24
|
ScriptType,
|
|
@@ -26,5 +26,5 @@ module.exports = {
|
|
|
26
26
|
opscompassHome,
|
|
27
27
|
isLocal,
|
|
28
28
|
cliCommand,
|
|
29
|
-
decoder: "TjFXOWhWdnppb2Zoa2ZFcmd1TWI",
|
|
30
29
|
};
|
|
30
|
+
export const decoder = "TjFXOWhWdnppb2Zoa2ZFcmd1TWI";
|
package/error.js
CHANGED
package/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
import modules from "./modules.js";
|
|
4
|
+
import handleError from "./error.js";
|
|
5
|
+
import { canReadStoredCredentials } from "./credentials.js";
|
|
6
|
+
import { isLocal, opscompassHome } from "./environment/current.js";
|
|
7
|
+
import pkg from "./package.json" with { type: "json" };
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
import fs from "fs";
|
|
10
|
+
import path from "path";
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
import semver from "semver";
|
|
13
|
+
import { yellowText, redText } from "./colors.js";
|
|
14
14
|
|
|
15
15
|
let defaultParams = JSON.parse("{}");
|
|
16
16
|
|
|
@@ -21,7 +21,7 @@ try {
|
|
|
21
21
|
}
|
|
22
22
|
} catch (error) {
|
|
23
23
|
console.error(
|
|
24
|
-
`Error: Unable to create Opscompass home directory at ${opscompassHome}: ${error.message}
|
|
24
|
+
`Error: Unable to create Opscompass home directory at ${opscompassHome}: ${error.message}`,
|
|
25
25
|
);
|
|
26
26
|
process.exit(1);
|
|
27
27
|
}
|
|
@@ -33,7 +33,7 @@ if (fs.existsSync(offlinePath)) {
|
|
|
33
33
|
isOffline = true;
|
|
34
34
|
}
|
|
35
35
|
global.isOffline = isOffline;
|
|
36
|
-
const { versionCheck } =
|
|
36
|
+
const { versionCheck } = await import("./updates.js");
|
|
37
37
|
|
|
38
38
|
function checkDefaults() {
|
|
39
39
|
const defaultsPath = path.join(opscompassHome, "defaults.json");
|
|
@@ -48,17 +48,17 @@ function checkDefaults() {
|
|
|
48
48
|
* When an individual string is passed to the API, default param will be provided if it exists.
|
|
49
49
|
* Default value is overwritten when explicitly included in CLI command.
|
|
50
50
|
*/
|
|
51
|
-
companySlug = defaultParams.company;
|
|
52
|
-
company = defaultParams.company;
|
|
53
|
-
account = defaultParams.account;
|
|
54
|
-
monitoringConfig = defaultParams.monitoringConfiguration;
|
|
55
|
-
valuesMask = defaultParams.maskValues || [];
|
|
51
|
+
global.companySlug = defaultParams.company;
|
|
52
|
+
global.company = defaultParams.company;
|
|
53
|
+
global.account = defaultParams.account;
|
|
54
|
+
global.monitoringConfig = defaultParams.monitoringConfiguration;
|
|
55
|
+
global.valuesMask = defaultParams.maskValues || [];
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* When a callParams object is passed to the API rather than one of the above strings, default values will be used unless explicitly replaced.
|
|
59
59
|
* Other properties can still be added to the callParams object. Unneeded default parameters may be included, but are ignored by the API.
|
|
60
60
|
*/
|
|
61
|
-
callParams = defaultParams;
|
|
61
|
+
global.callParams = defaultParams;
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
function requiresLogin() {
|
|
@@ -74,7 +74,7 @@ function help() {
|
|
|
74
74
|
console.log();
|
|
75
75
|
console.log("Command format:");
|
|
76
76
|
console.log(
|
|
77
|
-
" opscompass module action --parameter1 value --parameter2 value"
|
|
77
|
+
" opscompass module action --parameter1 value --parameter2 value",
|
|
78
78
|
);
|
|
79
79
|
console.log();
|
|
80
80
|
console.log("Available modules:");
|
|
@@ -126,13 +126,13 @@ function help() {
|
|
|
126
126
|
if (versions && semver.gt(versions.latest, pkg.version)) {
|
|
127
127
|
console.error(
|
|
128
128
|
yellowText,
|
|
129
|
-
`Warning! You are using CLI version ${pkg.version}, but the latest version is ${versions.latest}. To upgrade to the latest version, please run
|
|
129
|
+
`Warning! You are using CLI version ${pkg.version}, but the latest version is ${versions.latest}. To upgrade to the latest version, please run:`,
|
|
130
130
|
);
|
|
131
131
|
|
|
132
132
|
/* Prompt user to upgrade to the correct package based on their current environment */
|
|
133
133
|
console.error(
|
|
134
134
|
greenText,
|
|
135
|
-
`\nnpm install -g ${versions.pkg}@${versions.latest}\n
|
|
135
|
+
`\nnpm install -g ${versions.pkg}@${versions.latest}\n`,
|
|
136
136
|
);
|
|
137
137
|
}
|
|
138
138
|
}
|
package/lib/cliHelpers.js
CHANGED
|
@@ -1,14 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import https from "https";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import AdmZip from "adm-zip";
|
|
5
5
|
|
|
6
6
|
let httpsProxyAgent;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
)
|
|
7
|
+
let proxyAgentPromise;
|
|
8
|
+
|
|
9
|
+
// Lazy load the proxy agent when needed
|
|
10
|
+
function getHttpsProxyAgent() {
|
|
11
|
+
if (httpsProxyAgent) {
|
|
12
|
+
return httpsProxyAgent;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (
|
|
16
|
+
!proxyAgentPromise &&
|
|
17
|
+
(process.env.https_proxy || process.env.HTTPS_PROXY)
|
|
18
|
+
) {
|
|
19
|
+
proxyAgentPromise = import("https-proxy-agent").then(
|
|
20
|
+
({ createHttpsProxyAgent }) => {
|
|
21
|
+
httpsProxyAgent = createHttpsProxyAgent(
|
|
22
|
+
process.env.https_proxy || process.env.HTTPS_PROXY,
|
|
23
|
+
);
|
|
24
|
+
return httpsProxyAgent;
|
|
25
|
+
},
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return proxyAgentPromise || null;
|
|
12
30
|
}
|
|
13
31
|
|
|
14
32
|
/**
|
|
@@ -107,11 +125,12 @@ function deleteDirectory(directoryPath) {
|
|
|
107
125
|
* @returns {Promise<void>} Returns once the download is complete
|
|
108
126
|
*/
|
|
109
127
|
async function downloadFile(downloadUrl, downloadFilePath, downloadName) {
|
|
110
|
-
return new Promise((resolve, reject) => {
|
|
128
|
+
return new Promise(async (resolve, reject) => {
|
|
111
129
|
const getOptions = {};
|
|
112
130
|
|
|
113
|
-
|
|
114
|
-
|
|
131
|
+
const proxyAgent = await getHttpsProxyAgent();
|
|
132
|
+
if (proxyAgent) {
|
|
133
|
+
getOptions.agent = proxyAgent;
|
|
115
134
|
}
|
|
116
135
|
|
|
117
136
|
// Download the file
|
|
@@ -119,7 +138,7 @@ async function downloadFile(downloadUrl, downloadFilePath, downloadName) {
|
|
|
119
138
|
.get(downloadUrl, getOptions, (res) => {
|
|
120
139
|
// Open file in local filesystem
|
|
121
140
|
const file = fs.createWriteStream(
|
|
122
|
-
path.join(downloadFilePath, downloadName)
|
|
141
|
+
path.join(downloadFilePath, downloadName),
|
|
123
142
|
);
|
|
124
143
|
|
|
125
144
|
// Write data into local file
|
|
@@ -162,7 +181,7 @@ async function unzipFile(unzipFileLocation, unzipFileName) {
|
|
|
162
181
|
* @returns {string[]} all file paths recursively for the passed in directory path
|
|
163
182
|
*/
|
|
164
183
|
function getAllFilesInFolder(dirPath) {
|
|
165
|
-
files = fs.readdirSync(dirPath);
|
|
184
|
+
let files = fs.readdirSync(dirPath);
|
|
166
185
|
|
|
167
186
|
var arrayOfFiles = arrayOfFiles || [];
|
|
168
187
|
|
|
@@ -232,7 +251,7 @@ const FilePermissions = {
|
|
|
232
251
|
userReadWrite: 600,
|
|
233
252
|
};
|
|
234
253
|
|
|
235
|
-
|
|
254
|
+
export {
|
|
236
255
|
setArgumentArrays,
|
|
237
256
|
writeFile,
|
|
238
257
|
deleteFile,
|
package/lib/consts.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true,
|
|
5
|
-
});
|
|
6
|
-
|
|
7
3
|
// Resources to check for sensitive attributes
|
|
8
|
-
const resourceTypes = {
|
|
4
|
+
export const resourceTypes = {
|
|
9
5
|
oracle_dbs: "oracle_dbs",
|
|
10
6
|
microsoft_dbs: "microsoft_dbs",
|
|
11
7
|
vcenters: "vcenters",
|
|
@@ -13,14 +9,9 @@ const resourceTypes = {
|
|
|
13
9
|
};
|
|
14
10
|
|
|
15
11
|
// Sensitive attributes to be encrypted by default
|
|
16
|
-
const encryptAttrs = {
|
|
12
|
+
export const encryptAttrs = {
|
|
17
13
|
username: "username",
|
|
18
14
|
user: "user",
|
|
19
15
|
password: "password",
|
|
20
16
|
connect: "connect",
|
|
21
17
|
};
|
|
22
|
-
|
|
23
|
-
module.exports = {
|
|
24
|
-
encryptAttrs,
|
|
25
|
-
resourceTypes,
|
|
26
|
-
};
|
package/lib/homeInteraction.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import fs from "fs-extra";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { Verify } from "./pgpTools.js";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
import {
|
|
6
6
|
opscompassHome,
|
|
7
7
|
ScriptType,
|
|
8
8
|
OpsCompassClient,
|
|
9
|
-
}
|
|
10
|
-
|
|
9
|
+
} from "../environment/current.js";
|
|
10
|
+
import {
|
|
11
11
|
findOrCreateFolder,
|
|
12
12
|
deleteDirectory,
|
|
13
13
|
downloadFile,
|
|
@@ -18,10 +18,10 @@ const {
|
|
|
18
18
|
canReadFile,
|
|
19
19
|
FilePermissions,
|
|
20
20
|
getAllFilesInFolder,
|
|
21
|
-
}
|
|
22
|
-
|
|
21
|
+
} from "./cliHelpers.js";
|
|
22
|
+
import { nextTick } from "process";
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
import semver from "semver";
|
|
25
25
|
|
|
26
26
|
const SRC_FOLDER_NAME = "src";
|
|
27
27
|
const METADATA_FILE_NAME = "metadata.json";
|
|
@@ -45,7 +45,7 @@ async function writeFileToHome(fileName, data, mode) {
|
|
|
45
45
|
path.join(opscompassHome, fileName),
|
|
46
46
|
JSON.stringify(data),
|
|
47
47
|
{ mode: mode },
|
|
48
|
-
() => resolve()
|
|
48
|
+
() => resolve(),
|
|
49
49
|
);
|
|
50
50
|
} catch (ex) {
|
|
51
51
|
reject(ex);
|
|
@@ -137,7 +137,7 @@ async function downloadScriptsToHome(
|
|
|
137
137
|
scriptVersion,
|
|
138
138
|
companySlug,
|
|
139
139
|
client,
|
|
140
|
-
scriptsRemote = undefined
|
|
140
|
+
scriptsRemote = undefined,
|
|
141
141
|
) {
|
|
142
142
|
// If scriptsRemote is provided, use it instead of fetching from api
|
|
143
143
|
if (!!scriptsRemote) {
|
|
@@ -147,15 +147,14 @@ async function downloadScriptsToHome(
|
|
|
147
147
|
// Ensure base scripts are downloaded/updated for all modules
|
|
148
148
|
if (scriptType !== ScriptType.baseScripts) {
|
|
149
149
|
const localBaseVersion = await getInstalledScriptVersion(
|
|
150
|
-
ScriptType.baseScripts
|
|
150
|
+
ScriptType.baseScripts,
|
|
151
151
|
);
|
|
152
152
|
|
|
153
153
|
// Determine what is available
|
|
154
154
|
if (!scriptsAvailable) {
|
|
155
155
|
console.log("Fetching remote versions...");
|
|
156
|
-
scriptsAvailable =
|
|
157
|
-
companySlug
|
|
158
|
-
);
|
|
156
|
+
scriptsAvailable =
|
|
157
|
+
await client.dataGatheringScripts.getScriptVersions(companySlug);
|
|
159
158
|
}
|
|
160
159
|
|
|
161
160
|
var availableBase = undefined;
|
|
@@ -164,7 +163,7 @@ async function downloadScriptsToHome(
|
|
|
164
163
|
scriptsAvailable.versions?.length > 0
|
|
165
164
|
) {
|
|
166
165
|
availableBase = scriptsAvailable.versions.find(
|
|
167
|
-
(version) => version.scriptType === ScriptType.baseScripts
|
|
166
|
+
(version) => version.scriptType === ScriptType.baseScripts,
|
|
168
167
|
);
|
|
169
168
|
}
|
|
170
169
|
|
|
@@ -178,7 +177,7 @@ async function downloadScriptsToHome(
|
|
|
178
177
|
ScriptType.baseScripts,
|
|
179
178
|
undefined,
|
|
180
179
|
companySlug,
|
|
181
|
-
client
|
|
180
|
+
client,
|
|
182
181
|
);
|
|
183
182
|
console.log("Base scripts updated (v%s)", baseVersion);
|
|
184
183
|
}
|
|
@@ -188,7 +187,7 @@ async function downloadScriptsToHome(
|
|
|
188
187
|
const scriptDownloadInfo = await client.dataGatheringScripts.getScriptsUrl(
|
|
189
188
|
companySlug,
|
|
190
189
|
scriptType,
|
|
191
|
-
scriptVersion
|
|
190
|
+
scriptVersion,
|
|
192
191
|
);
|
|
193
192
|
const scriptTypeFolderPath = findOrCreateScriptTypeFolder(scriptType);
|
|
194
193
|
const fileName = scriptDownloadInfo.fileName;
|
|
@@ -198,14 +197,14 @@ async function downloadScriptsToHome(
|
|
|
198
197
|
await downloadFile(
|
|
199
198
|
scriptDownloadInfo.downloadUrl,
|
|
200
199
|
scriptTypeFolderPath,
|
|
201
|
-
fileName
|
|
200
|
+
fileName,
|
|
202
201
|
);
|
|
203
202
|
|
|
204
203
|
// Attempt to verify the download - returns true if signed and verified
|
|
205
204
|
// outputs validation error(s) and returns false otherwise
|
|
206
205
|
// - we continue regardless of validation for now...
|
|
207
206
|
scriptDownloadInfo.filePath = path.join(scriptTypeFolderPath, fileName);
|
|
208
|
-
const zipValidated = await
|
|
207
|
+
const zipValidated = await Verify(scriptDownloadInfo);
|
|
209
208
|
|
|
210
209
|
await unzipFile(scriptTypeFolderPath, fileName);
|
|
211
210
|
|
|
@@ -213,7 +212,7 @@ async function downloadScriptsToHome(
|
|
|
213
212
|
const destinationPath = path.join(scriptTypeFolderPath, SRC_FOLDER_NAME);
|
|
214
213
|
await moveFolder(
|
|
215
214
|
path.join(scriptTypeFolderPath, scriptVersion),
|
|
216
|
-
destinationPath
|
|
215
|
+
destinationPath,
|
|
217
216
|
);
|
|
218
217
|
|
|
219
218
|
// File permissions should be set by the pipeline that builds the distribution bundle
|
|
@@ -284,7 +283,7 @@ async function setScriptMetadata(scriptFolderPath, scriptVersion) {
|
|
|
284
283
|
await writeFile(metadataFilePath, scriptMetadata);
|
|
285
284
|
}
|
|
286
285
|
|
|
287
|
-
|
|
286
|
+
export {
|
|
288
287
|
SRC_FOLDER_NAME,
|
|
289
288
|
BASE_SCRIPTS_RUN_ALL_RELATIVE_PATH,
|
|
290
289
|
writeFileToHome,
|