@sap/cli-core 2023.12.0
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/CHANGELOG.md +40 -0
- package/LICENSE +44 -0
- package/README.md +13 -0
- package/assets/error.html +20 -0
- package/assets/success.html +20 -0
- package/cache/cache.d.ts +6 -0
- package/cache/cache.js +82 -0
- package/cache/index.d.ts +2 -0
- package/cache/index.js +12 -0
- package/cache/utils.d.ts +1 -0
- package/cache/utils.js +16 -0
- package/commands/cache.command/clean.command.d.ts +3 -0
- package/commands/cache.command/clean.command.js +15 -0
- package/commands/cache.command/index.d.ts +3 -0
- package/commands/cache.command/index.js +15 -0
- package/commands/cache.command/init.command.d.ts +3 -0
- package/commands/cache.command/init.command.js +36 -0
- package/commands/cache.command/show.command.d.ts +3 -0
- package/commands/cache.command/show.command.js +30 -0
- package/commands/handler/authentication/index.d.ts +2 -0
- package/commands/handler/authentication/index.js +21 -0
- package/commands/handler/authentication/oauth/index.d.ts +2 -0
- package/commands/handler/authentication/oauth/index.js +18 -0
- package/commands/handler/authentication/oauth/secretsProvider/cache.d.ts +2 -0
- package/commands/handler/authentication/oauth/secretsProvider/cache.js +19 -0
- package/commands/handler/authentication/oauth/secretsProvider/file.d.ts +2 -0
- package/commands/handler/authentication/oauth/secretsProvider/file.js +25 -0
- package/commands/handler/authentication/oauth/secretsProvider/index.d.ts +2 -0
- package/commands/handler/authentication/oauth/secretsProvider/index.js +10 -0
- package/commands/handler/authentication/oauth/secretsProvider/options.d.ts +2 -0
- package/commands/handler/authentication/oauth/secretsProvider/options.js +30 -0
- package/commands/handler/authentication/oauth/tokenProvider/getToken.d.ts +2 -0
- package/commands/handler/authentication/oauth/tokenProvider/getToken.js +88 -0
- package/commands/handler/authentication/oauth/tokenProvider/index.d.ts +2 -0
- package/commands/handler/authentication/oauth/tokenProvider/index.js +11 -0
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.d.ts +2 -0
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.js +15 -0
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.d.ts +3 -0
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.js +35 -0
- package/commands/handler/authentication/oauth/tokenProvider/utils.d.ts +1 -0
- package/commands/handler/authentication/oauth/tokenProvider/utils.js +27 -0
- package/commands/handler/authentication/oauth/utils.d.ts +15 -0
- package/commands/handler/authentication/oauth/utils.js +58 -0
- package/commands/handler/authentication/passcode/function.d.ts +2 -0
- package/commands/handler/authentication/passcode/function.js +22 -0
- package/commands/handler/authentication/passcode/index.d.ts +2 -0
- package/commands/handler/authentication/passcode/index.js +19 -0
- package/commands/handler/authentication/passcode/input.d.ts +2 -0
- package/commands/handler/authentication/passcode/input.js +42 -0
- package/commands/handler/authentication/passcode/setPasscode.d.ts +2 -0
- package/commands/handler/authentication/passcode/setPasscode.js +16 -0
- package/commands/handler/authentication/passcode/types.d.ts +1 -0
- package/commands/handler/authentication/passcode/types.js +2 -0
- package/commands/handler/authentication/technicalJWT/cf.d.ts +4 -0
- package/commands/handler/authentication/technicalJWT/cf.js +133 -0
- package/commands/handler/authentication/technicalJWT/exec.d.ts +9 -0
- package/commands/handler/authentication/technicalJWT/exec.js +196 -0
- package/commands/handler/authentication/technicalJWT/index.d.ts +2 -0
- package/commands/handler/authentication/technicalJWT/index.js +15 -0
- package/commands/handler/authentication/technicalJWT/types.d.ts +2 -0
- package/commands/handler/authentication/technicalJWT/types.js +8 -0
- package/commands/handler/authentication/technicalJWT/utils.d.ts +1 -0
- package/commands/handler/authentication/technicalJWT/utils.js +70 -0
- package/commands/handler/authentication/utils.d.ts +3 -0
- package/commands/handler/authentication/utils.js +8 -0
- package/commands/handler/checkOptionsExistence.d.ts +2 -0
- package/commands/handler/checkOptionsExistence.js +17 -0
- package/commands/handler/error.d.ts +2 -0
- package/commands/handler/error.js +21 -0
- package/commands/handler/fail.d.ts +2 -0
- package/commands/handler/fail.js +10 -0
- package/commands/handler/fetch/fetch.d.ts +2 -0
- package/commands/handler/fetch/fetch.js +83 -0
- package/commands/handler/fetch/index.d.ts +2 -0
- package/commands/handler/fetch/index.js +25 -0
- package/commands/handler/fetch/utils.d.ts +14 -0
- package/commands/handler/fetch/utils.js +152 -0
- package/commands/handler/force.d.ts +2 -0
- package/commands/handler/force.js +35 -0
- package/commands/handler/index.d.ts +18 -0
- package/commands/handler/index.js +39 -0
- package/commands/handler/input/file.d.ts +2 -0
- package/commands/handler/input/file.js +34 -0
- package/commands/handler/input/index.d.ts +2 -0
- package/commands/handler/input/index.js +8 -0
- package/commands/handler/input/input.d.ts +2 -0
- package/commands/handler/input/input.js +44 -0
- package/commands/handler/mandatoryOptions.d.ts +2 -0
- package/commands/handler/mandatoryOptions.js +25 -0
- package/commands/handler/next.d.ts +2 -0
- package/commands/handler/next.js +19 -0
- package/commands/handler/options/env.d.ts +2 -0
- package/commands/handler/options/env.js +18 -0
- package/commands/handler/options/file.d.ts +2 -0
- package/commands/handler/options/file.js +21 -0
- package/commands/handler/options/index.d.ts +7 -0
- package/commands/handler/options/index.js +32 -0
- package/commands/handler/options/option.d.ts +2 -0
- package/commands/handler/options/option.js +20 -0
- package/commands/handler/options/pipe.d.ts +2 -0
- package/commands/handler/options/pipe.js +34 -0
- package/commands/handler/options/utils.d.ts +6 -0
- package/commands/handler/options/utils.js +63 -0
- package/commands/handler/or.d.ts +2 -0
- package/commands/handler/or.js +37 -0
- package/commands/handler/parseArguments.d.ts +4 -0
- package/commands/handler/parseArguments.js +22 -0
- package/commands/handler/resilient.d.ts +2 -0
- package/commands/handler/resilient.js +18 -0
- package/commands/handler/root/index.d.ts +2 -0
- package/commands/handler/root/index.js +18 -0
- package/commands/handler/stackTrace.d.ts +2 -0
- package/commands/handler/stackTrace.js +22 -0
- package/commands/handler/succeed.d.ts +2 -0
- package/commands/handler/succeed.js +9 -0
- package/commands/handler/utils.d.ts +7 -0
- package/commands/handler/utils.js +56 -0
- package/commands/host.command.d.ts +2 -0
- package/commands/host.command.js +68 -0
- package/commands/login.command.d.ts +3 -0
- package/commands/login.command.js +16 -0
- package/commands/logout.command.d.ts +3 -0
- package/commands/logout.command.js +21 -0
- package/commands/openAPI.command/index.d.ts +2 -0
- package/commands/openAPI.command/index.js +102 -0
- package/commands/openAPI.command/utils.d.ts +19 -0
- package/commands/openAPI.command/utils.js +334 -0
- package/commands/passcode.command.d.ts +2 -0
- package/commands/passcode.command.js +26 -0
- package/commands/secrets.command/index.d.ts +3 -0
- package/commands/secrets.command/index.js +13 -0
- package/commands/secrets.command/show.command.d.ts +3 -0
- package/commands/secrets.command/show.command.js +25 -0
- package/config/core.d.ts +10 -0
- package/config/core.js +23 -0
- package/config/index.d.ts +5 -0
- package/config/index.js +90 -0
- package/configureLoggers.d.ts +1 -0
- package/configureLoggers.js +11 -0
- package/constants.d.ts +43 -0
- package/constants.js +175 -0
- package/discovery/index.d.ts +10 -0
- package/discovery/index.js +142 -0
- package/discovery/utils.d.ts +7 -0
- package/discovery/utils.js +27 -0
- package/dwc/dwc.d.ts +10 -0
- package/dwc/dwc.js +180 -0
- package/dwc/run.d.ts +1 -0
- package/dwc/run.js +37 -0
- package/dwc/utils.d.ts +4 -0
- package/dwc/utils.js +37 -0
- package/index.d.ts +16 -0
- package/index.js +59 -0
- package/logger/index.d.ts +28 -0
- package/logger/index.js +63 -0
- package/module.d.ts +4 -0
- package/module.js +45 -0
- package/package.json +32 -0
- package/result/ResultHandlerFactory.d.ts +6 -0
- package/result/ResultHandlerFactory.js +12 -0
- package/result/ResultHandlerImpl.d.ts +6 -0
- package/result/ResultHandlerImpl.js +12 -0
- package/result/types.d.ts +4 -0
- package/result/types.js +2 -0
- package/schemas/discovery.json +347 -0
- package/settings/index.d.ts +4 -0
- package/settings/index.js +34 -0
- package/types.d.ts +182 -0
- package/types.js +67 -0
- package/utils/commands.d.ts +8 -0
- package/utils/commands.js +115 -0
- package/utils/http/index.d.ts +7 -0
- package/utils/http/index.js +69 -0
- package/utils/http/utils.d.ts +7 -0
- package/utils/http/utils.js +47 -0
- package/utils/options.d.ts +3 -0
- package/utils/options.js +25 -0
- package/utils/utils.d.ts +24 -0
- package/utils/utils.js +163 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const fs_extra_1 = require("fs-extra");
|
|
5
|
+
const http_1 = require("http");
|
|
6
|
+
const next_1 = require("../../../next");
|
|
7
|
+
const options_1 = require("../../../options");
|
|
8
|
+
const constants_1 = require("../../../../../constants");
|
|
9
|
+
const logger_1 = require("../../../../../logger");
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
const options_2 = require("../../../../../utils/options");
|
|
12
|
+
const utils_2 = require("../../../../../utils/utils");
|
|
13
|
+
const getLogger = () => (0, logger_1.get)("commands.handler.authentication.oauth.tokenProvider.getToken");
|
|
14
|
+
const retrieveCode = async () => new Promise((resolve, reject) => {
|
|
15
|
+
const PORT = parseInt(process.env.CLI_HTTP_PORT || "8080", 10);
|
|
16
|
+
const { debug } = getLogger();
|
|
17
|
+
let timeout;
|
|
18
|
+
const server = (0, http_1.createServer)(async (req, res) => {
|
|
19
|
+
clearTimeout(timeout);
|
|
20
|
+
const code = new URL(req.url ? `http://localhost:${PORT}${req.url}` : "http://no-code.damn").searchParams.get("code");
|
|
21
|
+
let file;
|
|
22
|
+
try {
|
|
23
|
+
file = await (0, fs_extra_1.readFile)(code ? constants_1.PATH_TO_SUCCESS_HTML : constants_1.PATH_TO_ERROR_HTML, "utf8");
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
debug("failed to read file for code", code, err);
|
|
27
|
+
file =
|
|
28
|
+
"<html><body>Ops, something went wrong! Please try again.</body></html>";
|
|
29
|
+
}
|
|
30
|
+
res.writeHead(200, {
|
|
31
|
+
"Content-Type": "text/html",
|
|
32
|
+
"Content-Security-Policy": "frame-ancestors 'none'",
|
|
33
|
+
"X-Frame-Options": "DENY",
|
|
34
|
+
});
|
|
35
|
+
res.end(file, "utf8");
|
|
36
|
+
server.close();
|
|
37
|
+
if (code) {
|
|
38
|
+
resolve(code);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
reject(new Error("no code found in callback URI"));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
timeout = setTimeout(() => {
|
|
45
|
+
server.close();
|
|
46
|
+
reject(new Error("Did not receive a code within 30 seconds"));
|
|
47
|
+
}, 30 * 1000);
|
|
48
|
+
server.listen(PORT);
|
|
49
|
+
debug(`started http server at localhost:${PORT}`);
|
|
50
|
+
});
|
|
51
|
+
const getCode = async (authorizeUrl, clientId) => {
|
|
52
|
+
const { debug } = getLogger();
|
|
53
|
+
try {
|
|
54
|
+
return (0, options_2.getOptionValueFromConfig)(constants_1.OPTION_CODE);
|
|
55
|
+
}
|
|
56
|
+
catch (err) {
|
|
57
|
+
debug("failed to retrieve code from options", err);
|
|
58
|
+
return (await Promise.all([
|
|
59
|
+
retrieveCode(),
|
|
60
|
+
(0, utils_2.openUrlInBrowser)(authorizeUrl, {
|
|
61
|
+
response_type: "code",
|
|
62
|
+
client_id: clientId,
|
|
63
|
+
}),
|
|
64
|
+
]))[0];
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const handler = () => async () => {
|
|
68
|
+
const { info: logInfo, debug } = getLogger();
|
|
69
|
+
logInfo("checking token existence");
|
|
70
|
+
const secrets = (0, utils_1.getSecrets)();
|
|
71
|
+
if (!secrets.access_token && !secrets.refresh_token) {
|
|
72
|
+
debug("access token not available, retrieving token from server");
|
|
73
|
+
const code = await getCode(secrets.authorization_url, secrets.client_id);
|
|
74
|
+
await (0, utils_1.readToken)({
|
|
75
|
+
code,
|
|
76
|
+
grant_type: "authorization_code",
|
|
77
|
+
});
|
|
78
|
+
await (0, utils_1.storeSecrets)();
|
|
79
|
+
}
|
|
80
|
+
else if (secrets.access_token) {
|
|
81
|
+
debug("token available");
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
throw new Error("access token not available");
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const create = () => (0, next_1.create)((0, options_1.create)(constants_1.OPTION_CODE), handler);
|
|
88
|
+
exports.create = create;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const next_1 = require("../../../next");
|
|
5
|
+
const error_1 = require("../../../error");
|
|
6
|
+
const or_1 = require("../../../or");
|
|
7
|
+
const refreshToken_1 = require("./refreshToken");
|
|
8
|
+
const setAuthorization_1 = require("./setAuthorization");
|
|
9
|
+
const getToken_1 = require("./getToken");
|
|
10
|
+
const create = () => (0, error_1.create)("failed to handle token", (0, next_1.create)((0, or_1.create)((0, getToken_1.create)(), (0, refreshToken_1.create)(true)), (0, setAuthorization_1.create)()));
|
|
11
|
+
exports.create = create;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const logger_1 = require("../../../../../logger");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
6
|
+
const create = (forceRefresh = false) => () => async () => {
|
|
7
|
+
try {
|
|
8
|
+
await (0, utils_1.refreshToken)(forceRefresh);
|
|
9
|
+
}
|
|
10
|
+
catch (err) {
|
|
11
|
+
const { error } = (0, logger_1.get)("commands.handler.authentication.oauth.tokenProvider.refreshToken");
|
|
12
|
+
error("failed to refresh token", err);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
exports.create = create;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = exports.updateAuthorization = void 0;
|
|
4
|
+
const config_1 = require("../../../../../config");
|
|
5
|
+
const constants_1 = require("../../../../../constants");
|
|
6
|
+
const logger_1 = require("../../../../../logger");
|
|
7
|
+
const options_1 = require("../../../../../utils/options");
|
|
8
|
+
const utils_1 = require("../../../options/utils");
|
|
9
|
+
const utils_2 = require("../../../utils");
|
|
10
|
+
const utils_3 = require("../../utils");
|
|
11
|
+
const utils_4 = require("../utils");
|
|
12
|
+
const updateAuthorization = async () => {
|
|
13
|
+
const { info: logInfo, debug } = (0, logger_1.get)("commands.handler.authentication.oauth.tokenProvider.setAuthorization");
|
|
14
|
+
logInfo("setting authorization using access token");
|
|
15
|
+
const config = (0, config_1.get)();
|
|
16
|
+
const secrets = (0, utils_4.getSecrets)();
|
|
17
|
+
const accessToken = secrets.access_token ||
|
|
18
|
+
(0, options_1.getOptionValueFromConfigGracefully)(constants_1.OPTION_ACCESS_TOKEN);
|
|
19
|
+
if (accessToken) {
|
|
20
|
+
debug("access token found");
|
|
21
|
+
(0, utils_3.setAuthorization)({ authorization: `Bearer ${accessToken}` });
|
|
22
|
+
(0, utils_2.setTargetHost)(`${config.tenantUrl}`);
|
|
23
|
+
(0, utils_2.setAuthenticationMethod)(constants_1.AuthenticationMethod.oauth);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
debug("no access token found");
|
|
27
|
+
throw new Error("cannot set authorization: no access token found in configuration");
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.updateAuthorization = updateAuthorization;
|
|
31
|
+
const create = () => (command) => {
|
|
32
|
+
(0, utils_1.checkOptions)(constants_1.OPTION_ACCESS_TOKEN, command);
|
|
33
|
+
return exports.updateAuthorization;
|
|
34
|
+
};
|
|
35
|
+
exports.create = create;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const refreshToken: (forceRefresh?: boolean) => Promise<void>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.refreshToken = void 0;
|
|
4
|
+
const logger_1 = require("../../../../../logger");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const setAuthorization_1 = require("./setAuthorization");
|
|
7
|
+
const refreshToken = async (forceRefresh = false) => {
|
|
8
|
+
const { info: logInfo, debug } = (0, logger_1.get)("commands.handler.authentication.oauth.tokenProvider.utils.refreshToken");
|
|
9
|
+
const secrets = (0, utils_1.getSecrets)();
|
|
10
|
+
if ((!forceRefresh && !secrets.expires_after) || !secrets.refresh_token) {
|
|
11
|
+
throw new Error("invalid secrets information");
|
|
12
|
+
}
|
|
13
|
+
logInfo("checking token expiry date");
|
|
14
|
+
if (forceRefresh || (0, utils_1.isExpired)(secrets.expires_after)) {
|
|
15
|
+
debug("access token is expired, refreshing token");
|
|
16
|
+
await (0, utils_1.readToken)({
|
|
17
|
+
refresh_token: secrets.refresh_token,
|
|
18
|
+
grant_type: "refresh_token",
|
|
19
|
+
});
|
|
20
|
+
await (0, utils_1.storeSecrets)();
|
|
21
|
+
await (0, setAuthorization_1.updateAuthorization)();
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
debug("access token is not expired");
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.refreshToken = refreshToken;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Secrets } from "../../../../types";
|
|
2
|
+
type Data = {
|
|
3
|
+
grant_type: "refresh_token";
|
|
4
|
+
refresh_token: string;
|
|
5
|
+
} | {
|
|
6
|
+
grant_type: "authorization_code";
|
|
7
|
+
code: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const setSecrets: (info: Partial<Secrets>) => void;
|
|
10
|
+
export declare const getSecrets: () => Secrets;
|
|
11
|
+
export declare const storeSecrets: () => Promise<void>;
|
|
12
|
+
export declare const calculateExpiresAfter: (expires_in: number) => number;
|
|
13
|
+
export declare const isExpired: (expires_after: number) => boolean;
|
|
14
|
+
export declare const readToken: (data: Data) => Promise<void>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.readToken = exports.isExpired = exports.calculateExpiresAfter = exports.storeSecrets = exports.getSecrets = exports.setSecrets = void 0;
|
|
7
|
+
const qs_1 = __importDefault(require("qs"));
|
|
8
|
+
const cache_1 = require("../../../../cache");
|
|
9
|
+
const config_1 = require("../../../../config");
|
|
10
|
+
const constants_1 = require("../../../../constants");
|
|
11
|
+
const http_1 = require("../../../../utils/http");
|
|
12
|
+
const setSecrets = (info) => {
|
|
13
|
+
(0, config_1.set)({ oauth: info });
|
|
14
|
+
};
|
|
15
|
+
exports.setSecrets = setSecrets;
|
|
16
|
+
const getSecrets = () => {
|
|
17
|
+
const { oauth } = (0, config_1.get)();
|
|
18
|
+
if (oauth) {
|
|
19
|
+
return oauth;
|
|
20
|
+
}
|
|
21
|
+
throw new Error("no secrets exist");
|
|
22
|
+
};
|
|
23
|
+
exports.getSecrets = getSecrets;
|
|
24
|
+
const storeSecrets = async () => {
|
|
25
|
+
await (0, cache_1.writeFile)(constants_1.CACHE_SECRETS_FILE, JSON.stringify((0, exports.getSecrets)()));
|
|
26
|
+
};
|
|
27
|
+
exports.storeSecrets = storeSecrets;
|
|
28
|
+
const calculateExpiresAfter = (expires_in) => Math.floor(Date.now() / 1000) + expires_in - 10;
|
|
29
|
+
exports.calculateExpiresAfter = calculateExpiresAfter;
|
|
30
|
+
const isExpired = (expires_after) => expires_after <= (0, exports.calculateExpiresAfter)(10);
|
|
31
|
+
exports.isExpired = isExpired;
|
|
32
|
+
const readToken = async (data) => {
|
|
33
|
+
const secrets = (0, exports.getSecrets)();
|
|
34
|
+
if (!secrets.token_url || !secrets.client_id || !secrets.client_secret) {
|
|
35
|
+
throw new Error("invalid secrets information");
|
|
36
|
+
}
|
|
37
|
+
const info = (await (0, http_1.fetch)({
|
|
38
|
+
method: "POST",
|
|
39
|
+
url: secrets.token_url,
|
|
40
|
+
auth: {
|
|
41
|
+
username: secrets.client_id,
|
|
42
|
+
password: secrets.client_secret,
|
|
43
|
+
},
|
|
44
|
+
headers: {
|
|
45
|
+
"x-sap-sac-custom-auth": true,
|
|
46
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
47
|
+
},
|
|
48
|
+
data: qs_1.default.stringify({
|
|
49
|
+
...data,
|
|
50
|
+
response_type: "token",
|
|
51
|
+
}),
|
|
52
|
+
})).data;
|
|
53
|
+
(0, exports.setSecrets)({
|
|
54
|
+
...info,
|
|
55
|
+
expires_after: (0, exports.calculateExpiresAfter)(info.expires_in),
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
exports.readToken = readToken;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const config_1 = require("../../../../config");
|
|
5
|
+
const constants_1 = require("../../../../constants");
|
|
6
|
+
const create = () => () => async () => {
|
|
7
|
+
const config = (0, config_1.get)();
|
|
8
|
+
/* jscpd:ignore-end */
|
|
9
|
+
if (!config[constants_1.CONFIG_PASSCODE_FUNCTION] ||
|
|
10
|
+
typeof config[constants_1.CONFIG_PASSCODE_FUNCTION] !== "function") {
|
|
11
|
+
throw new Error("passcode function not available from configuration or provided argument is no function");
|
|
12
|
+
}
|
|
13
|
+
let passcode = config.options[constants_1.OPTION_PASSCODE.longName];
|
|
14
|
+
if (!passcode) {
|
|
15
|
+
passcode = await config[constants_1.CONFIG_PASSCODE_FUNCTION]();
|
|
16
|
+
if (!passcode) {
|
|
17
|
+
throw new Error(`provided passcode function did not return a passcode. returned value was ${passcode}`);
|
|
18
|
+
}
|
|
19
|
+
(0, config_1.set)({ passcode });
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
exports.create = create;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const or_1 = require("../../or");
|
|
5
|
+
const next_1 = require("../../next");
|
|
6
|
+
const fail_1 = require("../../fail");
|
|
7
|
+
const checkOptionsExistence_1 = require("../../checkOptionsExistence");
|
|
8
|
+
const input_1 = require("./input");
|
|
9
|
+
const function_1 = require("./function");
|
|
10
|
+
const setPasscode_1 = require("./setPasscode");
|
|
11
|
+
const constants_1 = require("../../../../constants");
|
|
12
|
+
const core_1 = require("../../../../config/core");
|
|
13
|
+
const create = () => {
|
|
14
|
+
if ((0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)) {
|
|
15
|
+
return (0, next_1.create)((0, checkOptionsExistence_1.create)(constants_1.OPTION_CLIENT_ID), (0, checkOptionsExistence_1.create)(constants_1.OPTION_ACCESS_TOKEN), (0, checkOptionsExistence_1.create)(constants_1.OPTION_SECRETS_FILE), (0, or_1.create)((0, function_1.create)(), (0, input_1.create)()), (0, setPasscode_1.create)());
|
|
16
|
+
}
|
|
17
|
+
return (0, fail_1.create)();
|
|
18
|
+
};
|
|
19
|
+
exports.create = create;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.create = void 0;
|
|
7
|
+
const open_1 = __importDefault(require("open"));
|
|
8
|
+
const prompts_1 = __importDefault(require("prompts"));
|
|
9
|
+
const config_1 = require("../../../../config");
|
|
10
|
+
const constants_1 = require("../../../../constants");
|
|
11
|
+
const utils_1 = require("../../options/utils");
|
|
12
|
+
const create = () => (command) => {
|
|
13
|
+
(0, utils_1.checkOptions)(constants_1.OPTION_PASSCODE, command);
|
|
14
|
+
return async () => {
|
|
15
|
+
const config = (0, config_1.get)();
|
|
16
|
+
let passcode = config.options[constants_1.OPTION_PASSCODE.longName];
|
|
17
|
+
if (!passcode) {
|
|
18
|
+
if (!config.passcodeUrl) {
|
|
19
|
+
throw new Error("passcode url is not available");
|
|
20
|
+
}
|
|
21
|
+
const res = await prompts_1.default.prompt({
|
|
22
|
+
type: "confirm",
|
|
23
|
+
initial: true,
|
|
24
|
+
message: `Do you want to retrieve a temporary authentication code from ${config.passcodeUrl}?`,
|
|
25
|
+
name: "value",
|
|
26
|
+
});
|
|
27
|
+
if (res.value) {
|
|
28
|
+
await (0, open_1.default)(config.passcodeUrl);
|
|
29
|
+
passcode = (await prompts_1.default.prompt({
|
|
30
|
+
type: "password",
|
|
31
|
+
message: "Enter your temporary authentication code:",
|
|
32
|
+
name: "value",
|
|
33
|
+
})).value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (!passcode) {
|
|
37
|
+
throw new Error("no passcode");
|
|
38
|
+
}
|
|
39
|
+
(0, config_1.set)({ passcode });
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.create = create;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
const config_1 = require("../../../../config");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const utils_2 = require("../../utils");
|
|
7
|
+
/* jscpd:ignore-start */
|
|
8
|
+
const constants_1 = require("../../../../constants");
|
|
9
|
+
const create = () => () => async () => {
|
|
10
|
+
const config = (0, config_1.get)();
|
|
11
|
+
/* jscpd:ignore-end */
|
|
12
|
+
(0, utils_2.setTargetHost)(config.host);
|
|
13
|
+
(0, utils_1.setAuthorization)({ passcode: config.passcode });
|
|
14
|
+
(0, utils_2.setAuthenticationMethod)(constants_1.AuthenticationMethod.passcode);
|
|
15
|
+
};
|
|
16
|
+
exports.create = create;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type PasscodeFunction = () => Promise<string>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export function searchAllApps(names: any, targetOrg: any, targetSpace: any): any;
|
|
2
|
+
export function getServiceKey(serviceName: any, serviceKeyName: any): Promise<any>;
|
|
3
|
+
export function getEnv(names: any, targetOrg: any, targetSpace: any): any;
|
|
4
|
+
export function getCurrentTarget(): any;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
var exec = require("./exec.js");
|
|
4
|
+
var getResults = exec.getResults;
|
|
5
|
+
module.exports.searchAllApps = function (names, targetOrg, targetSpace) {
|
|
6
|
+
var nextUrl = "/v3/apps?names=" + names.join(",");
|
|
7
|
+
var fnFetchPage = function () {
|
|
8
|
+
return exec.cf(["curl", nextUrl], getResults);
|
|
9
|
+
};
|
|
10
|
+
var res = [];
|
|
11
|
+
var fnSearchPage = function () {
|
|
12
|
+
return fnFetchPage().then((apps) => {
|
|
13
|
+
try {
|
|
14
|
+
apps = JSON.parse(apps);
|
|
15
|
+
}
|
|
16
|
+
catch (e) {
|
|
17
|
+
console.error("Failed to parse the following body:");
|
|
18
|
+
console.error(apps);
|
|
19
|
+
throw e;
|
|
20
|
+
}
|
|
21
|
+
if (apps.errors) {
|
|
22
|
+
console.error(apps.errors[0]);
|
|
23
|
+
throw apps.errors[0];
|
|
24
|
+
}
|
|
25
|
+
for (const curResource of apps.resources) {
|
|
26
|
+
var resIndex = names.indexOf(curResource.name);
|
|
27
|
+
if (resIndex > -1) {
|
|
28
|
+
res[resIndex] = curResource;
|
|
29
|
+
for (var x = 0; x < names.length; x++) {
|
|
30
|
+
if (!res[x]) {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
if (x === names.length - 1) {
|
|
34
|
+
return Promise.resolve();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (apps.pagination &&
|
|
40
|
+
apps.pagination.next &&
|
|
41
|
+
apps.pagination.next.href) {
|
|
42
|
+
nextUrl = "/v3/" + apps.pagination.next.href.split("/v3/")[1];
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return Promise.resolve();
|
|
46
|
+
}
|
|
47
|
+
return fnSearchPage();
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
return exec
|
|
51
|
+
.cf(["curl", "/v3/organizations?names=" + targetOrg], getResults)
|
|
52
|
+
.then((orgs) => {
|
|
53
|
+
orgs = JSON.parse(orgs);
|
|
54
|
+
var orgGuid = orgs.resources && orgs.resources[0] && orgs.resources[0].guid;
|
|
55
|
+
nextUrl = nextUrl + "&organization_guids=" + orgGuid;
|
|
56
|
+
return exec.cf([
|
|
57
|
+
"curl",
|
|
58
|
+
"/v3/spaces?organization_guids=" + orgGuid + "&names=" + targetSpace,
|
|
59
|
+
], getResults);
|
|
60
|
+
})
|
|
61
|
+
.then((spaces) => {
|
|
62
|
+
spaces = JSON.parse(spaces);
|
|
63
|
+
var spaceGuid = spaces.resources && spaces.resources[0] && spaces.resources[0].guid;
|
|
64
|
+
nextUrl = nextUrl + "&space_guids=" + spaceGuid;
|
|
65
|
+
})
|
|
66
|
+
.then(() => fnSearchPage())
|
|
67
|
+
.then(() => res);
|
|
68
|
+
};
|
|
69
|
+
module.exports.getServiceKey = function (serviceName, serviceKeyName) {
|
|
70
|
+
function resourceFromPagination(cfResult) {
|
|
71
|
+
if (!cfResult || cfResult.length === 0) {
|
|
72
|
+
return [];
|
|
73
|
+
}
|
|
74
|
+
const oResult = JSON.parse(cfResult);
|
|
75
|
+
if (oResult.pagination["total_results"] > 0) {
|
|
76
|
+
return oResult.resources;
|
|
77
|
+
}
|
|
78
|
+
return [];
|
|
79
|
+
}
|
|
80
|
+
return Promise.all([
|
|
81
|
+
exec
|
|
82
|
+
.cf(["curl", `/v3/service_instances?names=${serviceName}`], getResults)
|
|
83
|
+
.then((result) => resourceFromPagination(result))
|
|
84
|
+
.catch((err) => console.error(err.message)),
|
|
85
|
+
exec
|
|
86
|
+
.cf(["curl", `/v3/service_credential_bindings?names=${serviceKeyName}`], getResults)
|
|
87
|
+
.then((result) => resourceFromPagination(result))
|
|
88
|
+
.catch((err) => console.error(err.message)),
|
|
89
|
+
])
|
|
90
|
+
.then((result) => {
|
|
91
|
+
var serviceGuid = result[0][0].guid;
|
|
92
|
+
var credKeys = result[1];
|
|
93
|
+
if (!serviceGuid || credKeys.length === 0) {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
var serviceKey = credKeys.filter((key) => key.relationships["service_instance"].data.guid === serviceGuid);
|
|
97
|
+
if (serviceKey.length === 0) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
return exec
|
|
101
|
+
.cf([
|
|
102
|
+
"curl",
|
|
103
|
+
`/v3/service_credential_bindings/${serviceKey[0].guid}/details`,
|
|
104
|
+
], getResults)
|
|
105
|
+
.then((details) => JSON.parse(details));
|
|
106
|
+
})
|
|
107
|
+
.catch((err) => console.error(`Failed to fetch service key ${serviceKeyName}. ${err}`));
|
|
108
|
+
};
|
|
109
|
+
module.exports.getEnv = function (names, targetOrg, targetSpace) {
|
|
110
|
+
if (!Array.isArray(names)) {
|
|
111
|
+
names = [names];
|
|
112
|
+
}
|
|
113
|
+
return module.exports
|
|
114
|
+
.searchAllApps(names, targetOrg, targetSpace)
|
|
115
|
+
.then((apps) => Promise.all(apps.map((a) => exec.cf(["curl", `/v3/apps/${a.guid}/env`], getResults))));
|
|
116
|
+
};
|
|
117
|
+
module.exports.getCurrentTarget = function () {
|
|
118
|
+
return exec.cf(["t"], getResults).then((result) => {
|
|
119
|
+
var json = result
|
|
120
|
+
.replace(/ /g, "")
|
|
121
|
+
.split("\n")
|
|
122
|
+
.map((l) => {
|
|
123
|
+
var i = l.indexOf(":");
|
|
124
|
+
if (i < 0) {
|
|
125
|
+
return l;
|
|
126
|
+
}
|
|
127
|
+
return '"' + l.substring(0, i) + '":"' + l.substring(i + 1) + '"';
|
|
128
|
+
});
|
|
129
|
+
json.pop();
|
|
130
|
+
json = "{" + json.join(",\n") + "}";
|
|
131
|
+
return JSON.parse(json);
|
|
132
|
+
});
|
|
133
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export namespace getResults {
|
|
2
|
+
const stdio: (string | number)[];
|
|
3
|
+
}
|
|
4
|
+
export function exec(cmd: any, args: any, options: any): Promise<any>;
|
|
5
|
+
export function kill(): Promise<any[]>;
|
|
6
|
+
declare function execCF(args: any, options: any): any;
|
|
7
|
+
declare function execNpm(args: any, options: any): any;
|
|
8
|
+
declare function execGit(args: any, options: any): Promise<any>;
|
|
9
|
+
export { execCF as cf, execNpm as npm, execGit as git };
|