@sap/cli-core 2025.17.0 → 2025.20.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 +12 -0
- package/README.md +1 -1
- package/cache/cache.js +16 -28
- package/cache/index.d.ts +2 -2
- package/cache/index.js +2 -12
- package/cache/secrets/SecretsStorageImpl.d.ts +2 -2
- package/cache/secrets/SecretsStorageImpl.js +18 -22
- package/cache/secrets/SecretsStorageSingleton.d.ts +1 -1
- package/cache/secrets/SecretsStorageSingleton.js +1 -5
- package/cache/secrets/types.d.ts +1 -1
- package/cache/secrets/types.js +1 -2
- package/cache/secrets/utils.d.ts +1 -1
- package/cache/secrets/utils.js +20 -27
- package/cache/utils.js +8 -15
- package/commands/config.command/cache.command/clean.command.d.ts +1 -1
- package/commands/config.command/cache.command/clean.command.js +10 -12
- package/commands/config.command/cache.command/index.d.ts +1 -1
- package/commands/config.command/cache.command/index.js +5 -10
- package/commands/config.command/cache.command/init.command/index.d.ts +1 -1
- package/commands/config.command/cache.command/init.command/index.js +29 -36
- package/commands/config.command/cache.command/init.command/utils.d.ts +1 -1
- package/commands/config.command/cache.command/init.command/utils.js +6 -13
- package/commands/config.command/cache.command/show.command.d.ts +1 -1
- package/commands/config.command/cache.command/show.command.js +7 -9
- package/commands/config.command/host.command.d.ts +1 -1
- package/commands/config.command/host.command.js +19 -23
- package/commands/config.command/index.d.ts +1 -1
- package/commands/config.command/index.js +5 -45
- package/commands/config.command/passcode.command.d.ts +1 -1
- package/commands/config.command/passcode.command.js +12 -16
- package/commands/config.command/secrets.command/check.command.d.ts +1 -2
- package/commands/config.command/secrets.command/check.command.js +10 -14
- package/commands/config.command/secrets.command/index.d.ts +1 -1
- package/commands/config.command/secrets.command/index.js +6 -11
- package/commands/config.command/secrets.command/refresh.command.d.ts +1 -1
- package/commands/config.command/secrets.command/refresh.command.js +5 -7
- package/commands/config.command/secrets.command/reset.command.d.ts +1 -1
- package/commands/config.command/secrets.command/reset.command.js +6 -8
- package/commands/config.command/secrets.command/show.command.d.ts +1 -1
- package/commands/config.command/secrets.command/show.command.js +8 -10
- package/commands/handler/authentication/index.d.ts +1 -1
- package/commands/handler/authentication/index.js +18 -21
- package/commands/handler/authentication/oauth/index.d.ts +1 -1
- package/commands/handler/authentication/oauth/index.js +13 -16
- package/commands/handler/authentication/oauth/secretsProvider/cache.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/cache.js +5 -9
- package/commands/handler/authentication/oauth/secretsProvider/file.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/file.js +20 -25
- package/commands/handler/authentication/oauth/secretsProvider/index.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/index.js +6 -10
- package/commands/handler/authentication/oauth/secretsProvider/options.d.ts +1 -1
- package/commands/handler/authentication/oauth/secretsProvider/options.js +25 -29
- package/commands/handler/authentication/oauth/tokenProvider/getToken.d.ts +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/getToken.js +16 -20
- package/commands/handler/authentication/oauth/tokenProvider/index.d.ts +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/index.js +7 -11
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.d.ts +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/refreshToken.js +5 -9
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.d.ts +1 -1
- package/commands/handler/authentication/oauth/tokenProvider/setAuthorization.js +19 -24
- package/commands/handler/authentication/oauth/tokenProvider/utils.js +30 -36
- package/commands/handler/authentication/oauth/utils.d.ts +1 -1
- package/commands/handler/authentication/oauth/utils.js +15 -24
- package/commands/handler/authentication/passcode/function.d.ts +1 -1
- package/commands/handler/authentication/passcode/function.js +11 -13
- package/commands/handler/authentication/passcode/index.d.ts +1 -1
- package/commands/handler/authentication/passcode/index.js +14 -17
- package/commands/handler/authentication/passcode/input.d.ts +1 -1
- package/commands/handler/authentication/passcode/input.js +13 -20
- package/commands/handler/authentication/passcode/setPasscode.d.ts +1 -1
- package/commands/handler/authentication/passcode/setPasscode.js +9 -13
- package/commands/handler/authentication/passcode/types.js +1 -2
- package/commands/handler/authentication/technicalJWT/cf.js +9 -11
- package/commands/handler/authentication/technicalJWT/exec.d.ts +5 -6
- package/commands/handler/authentication/technicalJWT/exec.js +15 -19
- package/commands/handler/authentication/technicalJWT/index.d.ts +1 -1
- package/commands/handler/authentication/technicalJWT/index.js +8 -12
- package/commands/handler/authentication/technicalJWT/types.d.ts +1 -1
- package/commands/handler/authentication/technicalJWT/types.js +1 -4
- package/commands/handler/authentication/technicalJWT/utils.js +20 -27
- package/commands/handler/authentication/utils.js +3 -7
- package/commands/handler/checkOptionsExistence.d.ts +1 -1
- package/commands/handler/checkOptionsExistence.js +5 -9
- package/commands/handler/error.d.ts +1 -1
- package/commands/handler/error.js +4 -8
- package/commands/handler/fail.d.ts +1 -1
- package/commands/handler/fail.js +3 -7
- package/commands/handler/fetch/fetch.d.ts +1 -1
- package/commands/handler/fetch/fetch.js +26 -27
- package/commands/handler/fetch/index.d.ts +1 -1
- package/commands/handler/fetch/index.js +10 -14
- package/commands/handler/fetch/utils.d.ts +2 -2
- package/commands/handler/fetch/utils.js +56 -75
- package/commands/handler/force.d.ts +1 -1
- package/commands/handler/force.js +8 -15
- package/commands/handler/index.d.ts +18 -18
- package/commands/handler/index.js +18 -39
- package/commands/handler/input/file.d.ts +1 -1
- package/commands/handler/input/file.js +22 -29
- package/commands/handler/input/index.d.ts +1 -1
- package/commands/handler/input/index.js +4 -8
- package/commands/handler/input/input.d.ts +1 -1
- package/commands/handler/input/input.js +16 -23
- package/commands/handler/mandatoryOptions.d.ts +1 -1
- package/commands/handler/mandatoryOptions.js +13 -17
- package/commands/handler/next.d.ts +1 -1
- package/commands/handler/next.js +4 -8
- package/commands/handler/options/env.d.ts +1 -1
- package/commands/handler/options/env.js +8 -12
- package/commands/handler/options/file.d.ts +1 -1
- package/commands/handler/options/file.js +8 -12
- package/commands/handler/options/index.d.ts +1 -1
- package/commands/handler/options/index.js +15 -19
- package/commands/handler/options/option.d.ts +1 -1
- package/commands/handler/options/option.js +12 -13
- package/commands/handler/options/utils.d.ts +4 -2
- package/commands/handler/options/utils.js +18 -26
- package/commands/handler/or.d.ts +1 -1
- package/commands/handler/or.js +3 -7
- package/commands/handler/parseArguments.d.ts +1 -1
- package/commands/handler/parseArguments.js +11 -15
- package/commands/handler/resilient.d.ts +1 -1
- package/commands/handler/resilient.js +3 -7
- package/commands/handler/root/index.d.ts +1 -1
- package/commands/handler/root/index.js +3 -7
- package/commands/handler/stackTrace.d.ts +1 -1
- package/commands/handler/stackTrace.js +3 -7
- package/commands/handler/succeed.d.ts +1 -1
- package/commands/handler/succeed.js +3 -7
- package/commands/handler/utils.d.ts +1 -1
- package/commands/handler/utils.js +17 -27
- package/commands/login.command.d.ts +1 -1
- package/commands/login.command.js +41 -45
- package/commands/logout.command.d.ts +1 -1
- package/commands/logout.command.js +15 -17
- package/commands/openAPI.command/index.d.ts +1 -1
- package/commands/openAPI.command/index.js +20 -24
- package/commands/openAPI.command/utils.d.ts +1 -1
- package/commands/openAPI.command/utils.js +47 -97
- package/commands/utils.d.ts +1 -1
- package/commands/utils.js +6 -11
- package/config/core.d.ts +1 -1
- package/config/core.js +12 -25
- package/config/index.d.ts +1 -1
- package/config/index.js +45 -49
- package/configureLoggers.js +2 -6
- package/constants.d.ts +1 -1
- package/constants.js +57 -63
- package/discovery/index.d.ts +1 -1
- package/discovery/index.js +32 -45
- package/discovery/utils.js +5 -12
- package/dwc/dwc.js +63 -76
- package/dwc/run.js +15 -19
- package/dwc/utils.d.ts +1 -1
- package/dwc/utils.js +43 -38
- package/index.d.ts +4 -4
- package/index.js +22 -68
- package/logger/index.d.ts +2 -2
- package/logger/index.js +17 -22
- package/logger/types.js +1 -2
- package/logger/utils.d.ts +1 -1
- package/logger/utils.js +4 -8
- package/module.d.ts +3 -3
- package/module.js +10 -48
- package/package.json +9 -7
- package/result/ResultHandlerFactory.d.ts +1 -1
- package/result/ResultHandlerFactory.js +1 -5
- package/result/ResultHandlerImpl.d.ts +1 -1
- package/result/ResultHandlerImpl.js +1 -5
- package/result/types.js +1 -2
- package/settings/index.d.ts +1 -1
- package/settings/index.js +11 -17
- package/types.d.ts +1 -1
- package/types.js +6 -9
- package/utils/commands.d.ts +3 -3
- package/utils/commands.js +23 -36
- package/utils/http/httpsAgent.js +16 -26
- package/utils/http/index.d.ts +1 -1
- package/utils/http/index.js +28 -35
- package/utils/http/utils.d.ts +1 -1
- package/utils/http/utils.js +4 -9
- package/utils/openUtils.js +8 -14
- package/utils/options.d.ts +1 -1
- package/utils/options.js +5 -10
- package/utils/utils.d.ts +2 -2
- package/utils/utils.js +42 -94
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const config_1 = require("../../../../config");
|
|
5
|
-
const utils_1 = require("../utils");
|
|
6
|
-
const utils_2 = require("../../utils");
|
|
1
|
+
import { get } from "../../../../config/index.js";
|
|
2
|
+
import { setAuthorization } from "../utils.js";
|
|
3
|
+
import { setAuthenticationMethod, setTargetHost } from "../../utils.js";
|
|
7
4
|
/* jscpd:ignore-start */
|
|
8
|
-
|
|
9
|
-
const create = () => async () => async () => {
|
|
10
|
-
const config =
|
|
5
|
+
import { AuthenticationMethod } from "../../../../constants.js";
|
|
6
|
+
export const create = () => async () => async () => {
|
|
7
|
+
const config = get();
|
|
11
8
|
/* jscpd:ignore-end */
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
setTargetHost(config.host);
|
|
10
|
+
setAuthorization({ passcode: config.passcode });
|
|
11
|
+
setAuthenticationMethod(AuthenticationMethod.passcode);
|
|
15
12
|
};
|
|
16
|
-
exports.create = create;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
var exec = require("./exec.js");
|
|
1
|
+
import * as exec from "./exec.js";
|
|
4
2
|
var getResults = exec.getResults;
|
|
5
|
-
|
|
3
|
+
export function searchAllApps(names, targetOrg, targetSpace) {
|
|
6
4
|
var nextUrl = "/v3/apps?names=" + names.join(",");
|
|
7
5
|
var fnFetchPage = function () {
|
|
8
6
|
return exec.cf(["curl", nextUrl], getResults);
|
|
@@ -65,8 +63,8 @@ module.exports.searchAllApps = function (names, targetOrg, targetSpace) {
|
|
|
65
63
|
})
|
|
66
64
|
.then(() => fnSearchPage())
|
|
67
65
|
.then(() => res);
|
|
68
|
-
}
|
|
69
|
-
|
|
66
|
+
}
|
|
67
|
+
export function getServiceKey(serviceName, serviceKeyName) {
|
|
70
68
|
function resourceFromPagination(cfResult) {
|
|
71
69
|
if (!cfResult || cfResult.length === 0) {
|
|
72
70
|
return [];
|
|
@@ -105,16 +103,16 @@ module.exports.getServiceKey = function (serviceName, serviceKeyName) {
|
|
|
105
103
|
.then((details) => JSON.parse(details));
|
|
106
104
|
})
|
|
107
105
|
.catch((err) => console.error(`Failed to fetch service key ${serviceKeyName}. ${err}`));
|
|
108
|
-
}
|
|
109
|
-
|
|
106
|
+
}
|
|
107
|
+
export function getEnv(names, targetOrg, targetSpace) {
|
|
110
108
|
if (!Array.isArray(names)) {
|
|
111
109
|
names = [names];
|
|
112
110
|
}
|
|
113
111
|
return module.exports
|
|
114
112
|
.searchAllApps(names, targetOrg, targetSpace)
|
|
115
113
|
.then((apps) => Promise.all(apps.map((a) => exec.cf(["curl", `/v3/apps/${a.guid}/env`], getResults))));
|
|
116
|
-
}
|
|
117
|
-
|
|
114
|
+
}
|
|
115
|
+
export function getCurrentTarget() {
|
|
118
116
|
return exec.cf(["t"], getResults).then((result) => {
|
|
119
117
|
var json = result
|
|
120
118
|
.replace(/ /g, "")
|
|
@@ -130,4 +128,4 @@ module.exports.getCurrentTarget = function () {
|
|
|
130
128
|
json = "{" + json.join(",\n") + "}";
|
|
131
129
|
return JSON.parse(json);
|
|
132
130
|
});
|
|
133
|
-
}
|
|
131
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
export function exec(cmd: any, args: any, options: any): Promise<any>;
|
|
2
|
+
export function kill(): Promise<any[]>;
|
|
1
3
|
export namespace getResults {
|
|
2
4
|
let stdio: (string | number)[];
|
|
3
5
|
}
|
|
4
|
-
export function
|
|
5
|
-
export function
|
|
6
|
-
|
|
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 };
|
|
6
|
+
export function cf(args: any, options: any): any;
|
|
7
|
+
export function npm(args: any, options: any): any;
|
|
8
|
+
export function git(args: any, options: any): Promise<any>;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var childProcess = require("child_process");
|
|
1
|
+
import * as jsZip from "jszip";
|
|
2
|
+
import * as childProcess from "child_process";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import * as http from "https";
|
|
5
|
+
import * as fs from "fs-extra";
|
|
7
6
|
process.on("message", (m) => {
|
|
8
7
|
if (m.kill) {
|
|
9
8
|
module.exports.kill().then(() => {
|
|
@@ -14,10 +13,10 @@ process.on("message", (m) => {
|
|
|
14
13
|
// Define exec
|
|
15
14
|
var processes = {};
|
|
16
15
|
var killCallbacks = {};
|
|
17
|
-
var exec = function (cmd, args, options) {
|
|
16
|
+
export var exec = function (cmd, args, options) {
|
|
18
17
|
options = options || {};
|
|
19
18
|
options.stdio = options.stdio || [0, 1, 2];
|
|
20
|
-
options.cwd = options.cwd || path.resolve(
|
|
19
|
+
options.cwd = options.cwd || path.resolve(import.meta.dirname);
|
|
21
20
|
console.log("Executing command: " + cmd + " " + args.join(" "));
|
|
22
21
|
return new Promise((resolve, reject) => {
|
|
23
22
|
var output = [];
|
|
@@ -48,7 +47,7 @@ var exec = function (cmd, args, options) {
|
|
|
48
47
|
});
|
|
49
48
|
});
|
|
50
49
|
};
|
|
51
|
-
var kill = function () {
|
|
50
|
+
export var kill = function () {
|
|
52
51
|
var pids = Object.keys(processes);
|
|
53
52
|
var proms = [];
|
|
54
53
|
for (const pid of pids) {
|
|
@@ -66,9 +65,7 @@ var kill = function () {
|
|
|
66
65
|
}
|
|
67
66
|
return Promise.all(proms);
|
|
68
67
|
};
|
|
69
|
-
|
|
70
|
-
module.exports.kill = kill;
|
|
71
|
-
module.exports.getResults = { stdio: [0, "pipe", 2] };
|
|
68
|
+
export const getResults = { stdio: [0, "pipe", 2] };
|
|
72
69
|
// Define cf
|
|
73
70
|
var cfReady;
|
|
74
71
|
var cfCmd = "cf";
|
|
@@ -78,7 +75,7 @@ var checkCF = function () {
|
|
|
78
75
|
var win = process.platform === "win32";
|
|
79
76
|
var mac = process.platform === "darwin";
|
|
80
77
|
var plat = win ? "windows64-exe" : mac ? "macosx64-binary" : "linux64-binary";
|
|
81
|
-
var tmpFolder = path.resolve(
|
|
78
|
+
var tmpFolder = path.resolve(import.meta.dirname, "../.tmp/cf");
|
|
82
79
|
var cfZipFile = path.resolve(tmpFolder, "client.zip");
|
|
83
80
|
var cfExeFile = path.resolve(tmpFolder, "cf.exe");
|
|
84
81
|
var cfBinFile = path.resolve(tmpFolder, "cf");
|
|
@@ -127,7 +124,6 @@ var checkCF = function () {
|
|
|
127
124
|
return fs
|
|
128
125
|
.readFile(cfZipFile)
|
|
129
126
|
.then((data) => {
|
|
130
|
-
var jsZip = require("jszip");
|
|
131
127
|
// NOSONAR we're dealing with cf and we're pretty sure nobody messes it up
|
|
132
128
|
return jsZip.loadAsync(data);
|
|
133
129
|
})
|
|
@@ -172,7 +168,7 @@ var checkCF = function () {
|
|
|
172
168
|
var execCF = function (args, options) {
|
|
173
169
|
return checkCF().then(() => exec(cfCmd, args, options));
|
|
174
170
|
};
|
|
175
|
-
|
|
171
|
+
export const cf = execCF;
|
|
176
172
|
// Define npm
|
|
177
173
|
var execNpm = function (args, options) {
|
|
178
174
|
if (typeof args === "string") {
|
|
@@ -180,17 +176,17 @@ var execNpm = function (args, options) {
|
|
|
180
176
|
}
|
|
181
177
|
var cmd = process.platform === "win32" ? "npm.cmd" : "npm";
|
|
182
178
|
options = options || {};
|
|
183
|
-
options.cwd = options.cwd || path.resolve(
|
|
179
|
+
options.cwd = options.cwd || path.resolve(import.meta.dirname, "..");
|
|
184
180
|
return exec(cmd, args, options);
|
|
185
181
|
};
|
|
186
182
|
var execNpmRun = function (script) {
|
|
187
|
-
return execNpm(["run", script], { cwd: path.resolve(
|
|
183
|
+
return execNpm(["run", script], { cwd: path.resolve(import.meta.dirname, "..") });
|
|
188
184
|
};
|
|
189
|
-
|
|
185
|
+
export const npm = execNpm;
|
|
190
186
|
// Define git
|
|
191
187
|
var execGit = function (args, options) {
|
|
192
188
|
options = options || {};
|
|
193
189
|
options.stdio = options.stdio || ["pipe", 1, 2];
|
|
194
190
|
return exec("git", args, options);
|
|
195
191
|
};
|
|
196
|
-
|
|
192
|
+
export const git = execGit;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../../../types";
|
|
1
|
+
import { Handler } from "../../../../types.js";
|
|
2
2
|
export declare const create: () => Handler;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const utils_1 = require("./utils");
|
|
8
|
-
const create = () => async (command) => {
|
|
9
|
-
command.addOption(await (0, commands_1.buildOption)(command, types_1.OPTION_SECRET));
|
|
1
|
+
import { set as setConfig } from "../../../../config/index.js";
|
|
2
|
+
import { buildOption } from "../../../../utils/commands.js";
|
|
3
|
+
import { OPTION_SECRET } from "./types.js";
|
|
4
|
+
import { getTechnicalJwt } from "./utils.js";
|
|
5
|
+
export const create = () => async (command) => {
|
|
6
|
+
command.addOption(await buildOption(command, OPTION_SECRET));
|
|
10
7
|
return async () => {
|
|
11
|
-
const token = await
|
|
12
|
-
(
|
|
8
|
+
const token = await getTechnicalJwt();
|
|
9
|
+
setConfig({ authorization: { Authorization: `Bearer ${token}` } });
|
|
13
10
|
};
|
|
14
11
|
};
|
|
15
|
-
exports.create = create;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Option } from "../../../../types";
|
|
1
|
+
import { Option } from "../../../../types.js";
|
|
2
2
|
export declare const OPTION_SECRET: Option;
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OPTION_SECRET = void 0;
|
|
4
|
-
exports.OPTION_SECRET = {
|
|
1
|
+
export const OPTION_SECRET = {
|
|
5
2
|
longName: "secret",
|
|
6
3
|
description: "specifies the path to the secret file",
|
|
7
4
|
args: [{ name: "secret" }],
|
|
@@ -1,29 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const http_1 = require("../../../../utils/http");
|
|
13
|
-
const types_1 = require("./types");
|
|
14
|
-
const types_2 = require("../../../../types");
|
|
15
|
-
const getLogger = () => (0, logger_1.get)("commands.handler.authentication.technicalJWT.utils");
|
|
16
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires, import/extensions
|
|
17
|
-
const cf = require("./cf.js");
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { URLSearchParams } from "url";
|
|
3
|
+
import fs from "fs-extra";
|
|
4
|
+
// eslint-disable-next-line import/extensions
|
|
5
|
+
import * as cf from "./cf.js";
|
|
6
|
+
import { get as getConfig } from "../../../../config/index.js";
|
|
7
|
+
import { get } from "../../../../logger/index.js";
|
|
8
|
+
import { fetch } from "../../../../utils/http/index.js";
|
|
9
|
+
import { OPTION_SECRET } from "./types.js";
|
|
10
|
+
import { GrantType } from "../../../../types.js";
|
|
11
|
+
const getLogger = () => get("commands.handler.authentication.technicalJWT.utils");
|
|
18
12
|
const APPNAME_GLOBAL = "dwaas-core";
|
|
19
13
|
const getSecret = async () => {
|
|
20
14
|
const { trace } = getLogger();
|
|
21
|
-
const config = (
|
|
22
|
-
const secretsFile = config.options[
|
|
23
|
-
|
|
15
|
+
const config = getConfig();
|
|
16
|
+
const secretsFile = config.options[OPTION_SECRET.longName] ||
|
|
17
|
+
path.join(process.cwd(), ".secret.json");
|
|
24
18
|
trace("reading secret from", secretsFile);
|
|
25
|
-
if (
|
|
26
|
-
const content = await
|
|
19
|
+
if (fs.existsSync(secretsFile)) {
|
|
20
|
+
const content = await fs.readFile(secretsFile, "utf8");
|
|
27
21
|
return JSON.parse(content);
|
|
28
22
|
}
|
|
29
23
|
const currentTarget = await cf.getCurrentTarget();
|
|
@@ -50,14 +44,14 @@ const getSecret = async () => {
|
|
|
50
44
|
tenantid: uaa.credentials.tenantid,
|
|
51
45
|
};
|
|
52
46
|
};
|
|
53
|
-
const getTechnicalJwt = async () => {
|
|
47
|
+
export const getTechnicalJwt = async () => {
|
|
54
48
|
const secret = await getSecret();
|
|
55
|
-
const { data } = await
|
|
49
|
+
const { data } = await fetch({
|
|
56
50
|
method: "POST",
|
|
57
51
|
url: `${secret.uaaUrl}/oauth/token`,
|
|
58
52
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
59
|
-
data: new
|
|
60
|
-
grant_type:
|
|
53
|
+
data: new URLSearchParams({
|
|
54
|
+
grant_type: GrantType.client_credentials,
|
|
61
55
|
response_type: "token",
|
|
62
56
|
client_id: secret.clientid,
|
|
63
57
|
client_secret: secret.clientsecret,
|
|
@@ -68,4 +62,3 @@ const getTechnicalJwt = async () => {
|
|
|
68
62
|
}
|
|
69
63
|
return data.access_token;
|
|
70
64
|
};
|
|
71
|
-
exports.getTechnicalJwt = getTechnicalJwt;
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const config_1 = require("../../../config");
|
|
5
|
-
const setAuthorization = (authorization) => {
|
|
6
|
-
(0, config_1.set)({ authorization: { ...authorization } });
|
|
1
|
+
import { set } from "../../../config/index.js";
|
|
2
|
+
export const setAuthorization = (authorization) => {
|
|
3
|
+
set({ authorization: { ...authorization } });
|
|
7
4
|
};
|
|
8
|
-
exports.setAuthorization = setAuthorization;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler, Option } from "../../types";
|
|
1
|
+
import { Handler, Option } from "../../types.js";
|
|
2
2
|
export declare const create: (option: Option, throwIfExists?: boolean) => Handler;
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const create = (option, throwIfExists = true) => async () => async () => {
|
|
7
|
-
const config = (0, config_1.get)();
|
|
8
|
-
const { trace } = (0, logger_1.get)("commands.handler.checkOptionsExistence");
|
|
1
|
+
import { get as getConfig } from "../../config/index.js";
|
|
2
|
+
import { get } from "../../logger/index.js";
|
|
3
|
+
export const create = (option, throwIfExists = true) => async () => async () => {
|
|
4
|
+
const config = getConfig();
|
|
5
|
+
const { trace } = get("commands.handler.checkOptionsExistence");
|
|
9
6
|
trace(`checking options existence ${option.longName} in config, value in config is ${config.options[option.longName]}, throw error if option exists ${throwIfExists}`);
|
|
10
7
|
if (config.options[option.longName] && throwIfExists) {
|
|
11
8
|
throw new Error(`option ${option.longName} already set`);
|
|
@@ -14,4 +11,3 @@ const create = (option, throwIfExists = true) => async () => async () => {
|
|
|
14
11
|
throw new Error(`option ${option.longName} is not set`);
|
|
15
12
|
}
|
|
16
13
|
};
|
|
17
|
-
exports.create = create;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../types";
|
|
1
|
+
import { Handler } from "../../types.js";
|
|
2
2
|
export declare const create: (errorMessage: string, handler: Handler) => Handler;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.create = void 0;
|
|
4
|
-
const logger_1 = require("../../logger");
|
|
5
|
-
const stackTrace_1 = require("./stackTrace");
|
|
1
|
+
import { get } from "../../logger/index.js";
|
|
2
|
+
import { create as createStackTraceHandler } from "./stackTrace.js";
|
|
6
3
|
const errorHandler = (errorMessage, handler) => async (command) => {
|
|
7
4
|
const commandHandler = await handler(command);
|
|
8
5
|
return async (...args) => {
|
|
@@ -10,12 +7,11 @@ const errorHandler = (errorMessage, handler) => async (command) => {
|
|
|
10
7
|
await commandHandler(...args);
|
|
11
8
|
}
|
|
12
9
|
catch (err) {
|
|
13
|
-
const { error } =
|
|
10
|
+
const { error } = get("commands.handler.error");
|
|
14
11
|
error(errorMessage, err);
|
|
15
12
|
throw new Error(`handler failed: ${errorMessage}`);
|
|
16
13
|
}
|
|
17
14
|
};
|
|
18
15
|
};
|
|
19
|
-
const create = (errorMessage, handler) => (
|
|
20
|
-
exports.create = create;
|
|
16
|
+
export const create = (errorMessage, handler) => createStackTraceHandler(errorHandler(errorMessage, handler));
|
|
21
17
|
/* jscpd:ignore-end */
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../types";
|
|
1
|
+
import { Handler } from "../../types.js";
|
|
2
2
|
export declare const create: () => Handler;
|
package/commands/handler/fail.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const logger_1 = require("../../logger");
|
|
5
|
-
const create = () => async () => async () => {
|
|
6
|
-
const { debug } = (0, logger_1.get)("commands.handler.fail");
|
|
1
|
+
import { get } from "../../logger/index.js";
|
|
2
|
+
export const create = () => async () => async () => {
|
|
3
|
+
const { debug } = get("commands.handler.fail");
|
|
7
4
|
debug(`running fail handler`);
|
|
8
5
|
throw new Error("Fail I must");
|
|
9
6
|
};
|
|
10
|
-
exports.create = create;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler, HTTPMethod, ParameterMappings, ResponsePostProcessor } from "../../../types";
|
|
1
|
+
import { Handler, HTTPMethod, ParameterMappings, ResponsePostProcessor } from "../../../types.js";
|
|
2
2
|
export declare const create: (method: HTTPMethod, path: string, parameterMappings?: ParameterMappings, responsePostProcessor?: ResponsePostProcessor) => Handler;
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { get as getConfig } from "../../../config/index.js";
|
|
2
|
+
import { X_CSRF_TOKEN } from "../../../constants.js";
|
|
3
|
+
import { get } from "../../../logger/index.js";
|
|
4
|
+
import { fetch } from "../../../utils/http/index.js";
|
|
5
|
+
import { refreshToken } from "../authentication/oauth/tokenProvider/utils.js";
|
|
6
|
+
import { buildHttpConfig, checkConfiguration, handleResponse, handleResponseData, } from "./utils.js";
|
|
7
|
+
const getLogger = () => get("commands.handler.fetch");
|
|
8
|
+
const hasResponse = (err) => {
|
|
9
|
+
return !!err.response;
|
|
10
|
+
};
|
|
11
11
|
const removeCsrfTokenFromConfig = () => {
|
|
12
|
-
const config = (
|
|
13
|
-
delete config[
|
|
12
|
+
const config = getConfig();
|
|
13
|
+
delete config[X_CSRF_TOKEN];
|
|
14
14
|
};
|
|
15
15
|
// developer.mozilla.org/en-US/docs/Web/HTTP/Redirections
|
|
16
16
|
const REDIRECT_STATUS_CODES = [301, 302, 303, 307, 308];
|
|
17
17
|
const REDIRECT_WITHOUT_CHANGE = [307, 308];
|
|
18
18
|
const fetchData = async (method, path, parameterMappings, responsePostProcessor) => {
|
|
19
|
-
const config = (
|
|
20
|
-
|
|
21
|
-
const conf = await
|
|
22
|
-
const response = await
|
|
19
|
+
const config = getConfig();
|
|
20
|
+
checkConfiguration(config);
|
|
21
|
+
const conf = await buildHttpConfig(method, path, parameterMappings);
|
|
22
|
+
const response = await fetch(conf);
|
|
23
23
|
removeCsrfTokenFromConfig();
|
|
24
|
-
await
|
|
24
|
+
await handleResponse(response.data, response.headers);
|
|
25
25
|
if (responsePostProcessor) {
|
|
26
26
|
await responsePostProcessor(response);
|
|
27
27
|
}
|
|
@@ -30,7 +30,7 @@ const handle401 = async (method, path, parameterMappings) => {
|
|
|
30
30
|
const { debug, error } = getLogger();
|
|
31
31
|
debug("response status is 401, trying to refresh access_token");
|
|
32
32
|
try {
|
|
33
|
-
await
|
|
33
|
+
await refreshToken(true);
|
|
34
34
|
await fetchData(method, path, parameterMappings);
|
|
35
35
|
debug("refreshing token and fetching data succeeded");
|
|
36
36
|
}
|
|
@@ -40,26 +40,26 @@ const handle401 = async (method, path, parameterMappings) => {
|
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
42
|
const handleRedirect = async (error, method, redirect) => {
|
|
43
|
-
|
|
44
|
-
if (!location) {
|
|
43
|
+
if (!error.response.headers.location) {
|
|
45
44
|
throw new Error("location header is not present for redirect");
|
|
46
45
|
}
|
|
47
46
|
let newMethod = method;
|
|
48
|
-
if (!REDIRECT_WITHOUT_CHANGE.includes(error.response
|
|
47
|
+
if (!REDIRECT_WITHOUT_CHANGE.includes(error.response.status)) {
|
|
49
48
|
newMethod = "GET";
|
|
50
49
|
}
|
|
51
|
-
await redirect(newMethod, location);
|
|
50
|
+
await redirect(newMethod, error.response.headers.location);
|
|
52
51
|
};
|
|
53
52
|
const handleError = async (error, method, redirect, path, parameterMappings) => {
|
|
54
53
|
const { error: logError } = getLogger();
|
|
55
54
|
logError("failed to fetch data", error);
|
|
56
|
-
if (error.response?.data && (
|
|
57
|
-
await
|
|
55
|
+
if (error.response?.data && getConfig().verbose) {
|
|
56
|
+
await handleResponseData(error.response.data);
|
|
58
57
|
}
|
|
59
58
|
if (error.response?.status === 401) {
|
|
60
59
|
await handle401(method, path, parameterMappings);
|
|
61
60
|
}
|
|
62
|
-
else if (
|
|
61
|
+
else if (hasResponse(error) &&
|
|
62
|
+
REDIRECT_STATUS_CODES.includes(error.response.status)) {
|
|
63
63
|
await handleRedirect(error, method, redirect);
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
@@ -76,8 +76,7 @@ const runRequest = (method, path, parameterMappings, responsePostProcessor) => a
|
|
|
76
76
|
}
|
|
77
77
|
};
|
|
78
78
|
/* jscpd:ignore-start */
|
|
79
|
-
const create = (method, path, parameterMappings, responsePostProcessor) => {
|
|
79
|
+
export const create = (method, path, parameterMappings, responsePostProcessor) => {
|
|
80
80
|
/* jscpd:ignore-end */
|
|
81
81
|
return async () => runRequest(method, path, parameterMappings, responsePostProcessor);
|
|
82
82
|
};
|
|
83
|
-
exports.create = create;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler, HTTPMethod, ParameterMappings, ResponsePostProcessor } from "../../../types";
|
|
1
|
+
import { Handler, HTTPMethod, ParameterMappings, ResponsePostProcessor } from "../../../types.js";
|
|
2
2
|
export declare const create: (method: HTTPMethod, path: string, parameterMappings?: ParameterMappings, responsePostProcessor?: ResponsePostProcessor) => Handler;
|
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const requiresCsrfToken = (parameterMappings) => !!parameterMappings?.find((param) => param.name === constants_1.X_CSRF_TOKEN);
|
|
8
|
-
const createCsrfTokenFetchHandler = (path, parameterMappings) => (0, fetch_1.create)("GET", path, parameterMappings
|
|
9
|
-
?.filter((param) => param.name !== constants_1.X_CSRF_TOKEN)
|
|
1
|
+
import { X_CSRF_TOKEN } from "../../../constants.js";
|
|
2
|
+
import { create as createFetchHandler } from "./fetch.js";
|
|
3
|
+
import { create as createNextHandler } from "../next.js";
|
|
4
|
+
const requiresCsrfToken = (parameterMappings) => !!parameterMappings?.find((param) => param.name === X_CSRF_TOKEN);
|
|
5
|
+
const createCsrfTokenFetchHandler = (path, parameterMappings) => createFetchHandler("GET", path, parameterMappings
|
|
6
|
+
.filter((param) => param.name !== X_CSRF_TOKEN)
|
|
10
7
|
.concat([
|
|
11
8
|
{
|
|
12
|
-
name:
|
|
9
|
+
name: X_CSRF_TOKEN,
|
|
13
10
|
in: "header",
|
|
14
11
|
source: { type: "value", value: "fetch" },
|
|
15
12
|
},
|
|
16
13
|
]));
|
|
17
14
|
/* jscpd:ignore-start */
|
|
18
|
-
const create = (method, path, parameterMappings, responsePostProcessor) => {
|
|
15
|
+
export const create = (method, path, parameterMappings, responsePostProcessor) => {
|
|
19
16
|
/* jscpd:ignore-end */
|
|
20
17
|
if (requiresCsrfToken(parameterMappings)) {
|
|
21
|
-
return (
|
|
18
|
+
return createNextHandler("commands.handler.fetch", createCsrfTokenFetchHandler(path, parameterMappings), createFetchHandler(method, path, parameterMappings, responsePostProcessor));
|
|
22
19
|
}
|
|
23
|
-
return (
|
|
20
|
+
return createFetchHandler(method, path, parameterMappings, responsePostProcessor);
|
|
24
21
|
};
|
|
25
|
-
exports.create = create;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { URL } from "url";
|
|
2
1
|
import { AxiosResponseHeaders, RawAxiosResponseHeaders } from "axios";
|
|
3
|
-
import {
|
|
2
|
+
import { URL } from "url";
|
|
3
|
+
import { HTTPConfig, HTTPMethod, KeyValuePair, ParameterMapping, ParameterMappings } from "../../../types.js";
|
|
4
4
|
export declare const checkConfiguration: (config: KeyValuePair) => void;
|
|
5
5
|
export declare const removeLeadingPathSegmentForPasscode: (path: string) => string;
|
|
6
6
|
export declare const handleMappingIn: (mapping: ParameterMapping, url: URL, value: any, headers: KeyValuePair, bodyWrapper: any) => void;
|