@sap/cli-core 2023.23.0 → 2023.24.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/commands/handler/fetch/utils.d.ts +8 -1
- package/commands/handler/fetch/utils.js +21 -5
- package/constants.d.ts +1 -0
- package/constants.js +3 -2
- package/package.json +3 -2
- package/utils/http/index.js +12 -1
- package/utils/utils.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 2023.24.0
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- The defined HTTP protocol was not applied to calculated authorization URL and token URL. No matter which HTTP protocol (`http` or `https`) was used, the automatically calculated authorization URL and token URL always used the `https` protocol.
|
|
13
|
+
|
|
14
|
+
### Added
|
|
15
|
+
|
|
16
|
+
- HTTPS proxy support via environment variable `https_proxy`. When using an HTTPS proxy to communicate with the public internet, you can configure the environment variable `https_proxy`. The CLI uses the value from the environment variable to establish a correct connection to the HTTPS proxy.
|
|
17
|
+
|
|
18
|
+
- Support for response header `x-sap-datasphere-cli-file-name`. When the user adds option `--output` and provides a path to a file location, this value is always used to store the response data, no matter whether response header `x-sap-datasphere-cli-file-name` is present. If the user adds option `--output` without providing a path to a file location and the response header `x-sap-datasphere-cli-file-name` is present, the response data is stored in the location mentioned in `x-sap-datasphere-cli-file-name`. In all other cases, the response data is printed to the console.
|
|
19
|
+
|
|
8
20
|
## 2023.23.0
|
|
9
21
|
|
|
10
22
|
### Fixed
|
|
@@ -8,7 +8,14 @@ export declare const buildParameters: (path: string, parameterMappings?: Paramet
|
|
|
8
8
|
headers: KeyValuePair;
|
|
9
9
|
body: any;
|
|
10
10
|
};
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* If --output is present: Return value of --output if defined, otherwise take value from outputPath.
|
|
13
|
+
* If --output is not present, print response to console
|
|
14
|
+
* @param outputPath Optional path defined by server
|
|
15
|
+
* @returns Path to output file
|
|
16
|
+
*/
|
|
17
|
+
export declare function getOutputFileName(outputPath?: string): string;
|
|
18
|
+
export declare const handleResponseData: (data: any, outputPath?: string) => Promise<void>;
|
|
12
19
|
export declare const handleResponse: (data: any, headers?: RawAxiosResponseHeaders | AxiosResponseHeaders) => Promise<void>;
|
|
13
20
|
export declare const configRequiresBody: (method: HTTPMethod) => boolean;
|
|
14
21
|
export declare const buildHttpConfig: (method: HTTPMethod, path: string, parameterMappings?: ParameterMappings) => HTTPConfig;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.buildHttpConfig = exports.configRequiresBody = exports.handleResponse = exports.handleResponseData = exports.buildParameters = exports.removeLeadingPathSegmentForPasscode = exports.checkConfiguration = void 0;
|
|
6
|
+
exports.buildHttpConfig = exports.configRequiresBody = exports.handleResponse = exports.handleResponseData = exports.getOutputFileName = exports.buildParameters = exports.removeLeadingPathSegmentForPasscode = exports.checkConfiguration = void 0;
|
|
7
7
|
const url_1 = require("url");
|
|
8
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
9
9
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
@@ -103,7 +103,22 @@ const buildParameters = (path, parameterMappings) => {
|
|
|
103
103
|
};
|
|
104
104
|
};
|
|
105
105
|
exports.buildParameters = buildParameters;
|
|
106
|
-
|
|
106
|
+
/**
|
|
107
|
+
* If --output is present: Return value of --output if defined, otherwise take value from outputPath.
|
|
108
|
+
* If --output is not present, print response to console
|
|
109
|
+
* @param outputPath Optional path defined by server
|
|
110
|
+
* @returns Path to output file
|
|
111
|
+
*/
|
|
112
|
+
function getOutputFileName(outputPath = "") {
|
|
113
|
+
const config = (0, config_1.get)();
|
|
114
|
+
if (typeof config.options[constants_1.OPTION_OUTPUT.longName] === "boolean" &&
|
|
115
|
+
config.options[constants_1.OPTION_OUTPUT.longName]) {
|
|
116
|
+
return outputPath;
|
|
117
|
+
}
|
|
118
|
+
return config.options[constants_1.OPTION_OUTPUT.longName];
|
|
119
|
+
}
|
|
120
|
+
exports.getOutputFileName = getOutputFileName;
|
|
121
|
+
const handleResponseData = async (data, outputPath) => {
|
|
107
122
|
const config = (0, config_1.get)();
|
|
108
123
|
if (!config.doNotStoreResult) {
|
|
109
124
|
ResultHandlerFactory_1.ResultHandlerFactory.get().setResult(data);
|
|
@@ -112,8 +127,9 @@ const handleResponseData = async (data) => {
|
|
|
112
127
|
const formatted = config.options.pretty
|
|
113
128
|
? JSON.stringify(data, null, 2)
|
|
114
129
|
: JSON.stringify(data);
|
|
115
|
-
|
|
116
|
-
|
|
130
|
+
const outputFileName = getOutputFileName(outputPath);
|
|
131
|
+
if (outputFileName) {
|
|
132
|
+
await fs_extra_1.default.writeFile(outputFileName, formatted);
|
|
117
133
|
}
|
|
118
134
|
else {
|
|
119
135
|
output(formatted);
|
|
@@ -125,7 +141,7 @@ const handleResponse = async (data, headers) => {
|
|
|
125
141
|
(0, config_1.set)({ [constants_1.X_CSRF_TOKEN]: headers[constants_1.X_CSRF_TOKEN] });
|
|
126
142
|
}
|
|
127
143
|
else if (data) {
|
|
128
|
-
await (0, exports.handleResponseData)(data);
|
|
144
|
+
await (0, exports.handleResponseData)(data, headers?.[constants_1.X_OUTPUT_FILE_NAME]);
|
|
129
145
|
}
|
|
130
146
|
};
|
|
131
147
|
exports.handleResponse = handleResponse;
|
package/constants.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export declare const CLI_GENERIC_OPTIONS_HELP = "cli-generic-options-help";
|
|
|
18
18
|
export declare const SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH: string[];
|
|
19
19
|
export declare const DISCOVERY_METADATA_PATH = "discovery-metadata.json";
|
|
20
20
|
export declare const X_CSRF_TOKEN = "x-csrf-token";
|
|
21
|
+
export declare const X_OUTPUT_FILE_NAME = "x-sap-datasphere-cli-file-name";
|
|
21
22
|
export declare const PATH_TO_SUCCESS_HTML: string;
|
|
22
23
|
export declare const PATH_TO_ERROR_HTML: string;
|
|
23
24
|
export declare const CACHE_SECRETS_FILE = "secrets.json";
|
package/constants.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.OPTION_INPUT = exports.OPTION_FILE_PATH = exports.OPTION_OPTIONS_FILE = exports.CONFIG_PASSCODE_FUNCTION = exports.OPTION_PASSCODE = exports.OPTION_CODE = exports.OPTION_SECRETS_FILE = exports.OPTION_EXPIRES_IN = exports.OPTION_REFRESH_TOKEN = exports.OPTION_ACCESS_TOKEN = exports.OPTION_TOKEN_URL = exports.OPTION_AUTHORIZATION_URL = exports.OPTION_CLIENT_SECRET = exports.OPTION_CLIENT_ID = exports.OPTION_FORCE = exports.OPTION_VERBOSE = exports.OPTION_NO_PRETTY = exports.OPTION_OUTPUT = exports.OPTION_LOGIN_ID = exports.OPTION_HOST = exports.OPTION_HELP = exports.OPTION_VERSION = exports.CACHE_SECRETS_FILE = exports.PATH_TO_ERROR_HTML = exports.PATH_TO_SUCCESS_HTML = exports.X_CSRF_TOKEN = exports.DISCOVERY_METADATA_PATH = exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = exports.CLI_GENERIC_OPTIONS_HELP = exports.CLI_SUPPORTED_AUTHENTICATION_METHODS = exports.CLI_DEPRECATION_MESSAGE = exports.CLI_DEPRECATED = exports.CLI_VERSION = exports.CLI_SAP_HELP = exports.CLI_DISCOVERY_PATH = exports.CLI_DESCRIPTION = exports.CLI_PACKAGE_NAME = exports.CLI_NAME = exports.AuthenticationMethod = exports.DISCOVERY_DOCUMENT_PREFIX = exports.VERSION = void 0;
|
|
6
|
+
exports.OPTION_INPUT = exports.OPTION_FILE_PATH = exports.OPTION_OPTIONS_FILE = exports.CONFIG_PASSCODE_FUNCTION = exports.OPTION_PASSCODE = exports.OPTION_CODE = exports.OPTION_SECRETS_FILE = exports.OPTION_EXPIRES_IN = exports.OPTION_REFRESH_TOKEN = exports.OPTION_ACCESS_TOKEN = exports.OPTION_TOKEN_URL = exports.OPTION_AUTHORIZATION_URL = exports.OPTION_CLIENT_SECRET = exports.OPTION_CLIENT_ID = exports.OPTION_FORCE = exports.OPTION_VERBOSE = exports.OPTION_NO_PRETTY = exports.OPTION_OUTPUT = exports.OPTION_LOGIN_ID = exports.OPTION_HOST = exports.OPTION_HELP = exports.OPTION_VERSION = exports.CACHE_SECRETS_FILE = exports.PATH_TO_ERROR_HTML = exports.PATH_TO_SUCCESS_HTML = exports.X_OUTPUT_FILE_NAME = exports.X_CSRF_TOKEN = exports.DISCOVERY_METADATA_PATH = exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = exports.CLI_GENERIC_OPTIONS_HELP = exports.CLI_SUPPORTED_AUTHENTICATION_METHODS = exports.CLI_DEPRECATION_MESSAGE = exports.CLI_DEPRECATED = exports.CLI_VERSION = exports.CLI_SAP_HELP = exports.CLI_DISCOVERY_PATH = exports.CLI_DESCRIPTION = exports.CLI_PACKAGE_NAME = exports.CLI_NAME = exports.AuthenticationMethod = exports.DISCOVERY_DOCUMENT_PREFIX = exports.VERSION = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const utils_1 = require("./utils/utils");
|
|
9
9
|
exports.VERSION = (0, utils_1.getVersion)();
|
|
@@ -26,6 +26,7 @@ exports.CLI_GENERIC_OPTIONS_HELP = "cli-generic-options-help";
|
|
|
26
26
|
exports.SEGMENTS_TO_REMOVE_FOR_PASSCODE_AUTH = ["dwaas-core"];
|
|
27
27
|
exports.DISCOVERY_METADATA_PATH = "discovery-metadata.json";
|
|
28
28
|
exports.X_CSRF_TOKEN = "x-csrf-token";
|
|
29
|
+
exports.X_OUTPUT_FILE_NAME = "x-sap-datasphere-cli-file-name";
|
|
29
30
|
exports.PATH_TO_SUCCESS_HTML = path_1.default.join(__dirname, "assets", "success.html");
|
|
30
31
|
exports.PATH_TO_ERROR_HTML = path_1.default.join(__dirname, "assets", "error.html");
|
|
31
32
|
exports.CACHE_SECRETS_FILE = "secrets.json";
|
|
@@ -64,7 +65,7 @@ exports.OPTION_LOGIN_ID = {
|
|
|
64
65
|
exports.OPTION_OUTPUT = {
|
|
65
66
|
longName: "output",
|
|
66
67
|
description: "specifies the file to store the output of the command",
|
|
67
|
-
args: [{ name: "output" }],
|
|
68
|
+
args: [{ name: "output", optional: true }],
|
|
68
69
|
hidden: true,
|
|
69
70
|
};
|
|
70
71
|
exports.OPTION_NO_PRETTY = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap/cli-core",
|
|
3
|
-
"version": "2023.
|
|
3
|
+
"version": "2023.24.0",
|
|
4
4
|
"description": "Command-Line Interface (CLI) Core Module",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"author": "SAP SE",
|
|
@@ -19,11 +19,12 @@
|
|
|
19
19
|
"dependencies": {
|
|
20
20
|
"ajv": "8.12.0",
|
|
21
21
|
"axios": "1.5.1",
|
|
22
|
-
"commander": "11.
|
|
22
|
+
"commander": "11.1.0",
|
|
23
23
|
"config": "3.3.9",
|
|
24
24
|
"dotenv": "16.3.1",
|
|
25
25
|
"fs-extra": "11.1.1",
|
|
26
26
|
"https": "1.0.0",
|
|
27
|
+
"https-proxy-agent": "7.0.2",
|
|
27
28
|
"lodash": "4.17.21",
|
|
28
29
|
"open": "8.4.2",
|
|
29
30
|
"path": "0.12.7",
|
package/utils/http/index.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.fetch = exports.DEFAULTS = void 0;
|
|
7
7
|
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const https_proxy_agent_1 = require("https-proxy-agent");
|
|
8
9
|
const config_1 = require("../../config");
|
|
9
10
|
const logger_1 = require("../../logger");
|
|
10
11
|
const constants_1 = require("../../constants");
|
|
@@ -13,10 +14,11 @@ const core_1 = require("../../config/core");
|
|
|
13
14
|
exports.DEFAULTS = {
|
|
14
15
|
maxBodyLength: -1,
|
|
15
16
|
maxContentLength: -1,
|
|
16
|
-
maxRedirects: 0, // must be set to 0 because maxBodyLength: -1 won't work otherwise, see github.com/axios/axios/issues/4263
|
|
17
|
+
maxRedirects: 0, // must be set to 0 because maxBodyLength: -1 won't work otherwise, see github.com/axios/axios/issues/4263,
|
|
17
18
|
};
|
|
18
19
|
const HEADERS_ETAG = "x-sap-cli-core-discovery-etag";
|
|
19
20
|
const getLogger = () => (0, logger_1.get)("http");
|
|
21
|
+
const HTTPS_PROXY = process.env.https_proxy ?? process.env.HTTPS_PROXY;
|
|
20
22
|
const setEtag = (headers) => {
|
|
21
23
|
const { debug } = getLogger();
|
|
22
24
|
if (headers?.[HEADERS_ETAG]) {
|
|
@@ -38,7 +40,16 @@ const fetch = async (config) => {
|
|
|
38
40
|
output("%s %s", config.method.toUpperCase(), config.url);
|
|
39
41
|
}
|
|
40
42
|
debug("http config: %s", JSON.stringify(config));
|
|
43
|
+
const httpsAgent = HTTPS_PROXY ? new https_proxy_agent_1.HttpsProxyAgent(HTTPS_PROXY) : null;
|
|
44
|
+
if (httpsAgent && cnfg.verbose) {
|
|
45
|
+
output(`using https proxy agent for https proxy`);
|
|
46
|
+
debug(`using https proxy agent for https proxy ${HTTPS_PROXY}`);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
debug("no https proxy defined via environment variable https_proxy");
|
|
50
|
+
}
|
|
41
51
|
const res = await (0, axios_1.default)({
|
|
52
|
+
httpsAgent,
|
|
42
53
|
...config,
|
|
43
54
|
...exports.DEFAULTS,
|
|
44
55
|
headers: {
|
package/utils/utils.js
CHANGED
|
@@ -148,8 +148,8 @@ const getInfoFromTenant = (tenant, verbose, printOutput = true) => {
|
|
|
148
148
|
host: `${protocol}//dwaas-core.sac${region}.cfapps.orca.net.sap`,
|
|
149
149
|
publicfqdn: parsedTenant,
|
|
150
150
|
passcodeUrl: `https://${hostname}.authentication.${region}.hana.ondemand.com/passcode`,
|
|
151
|
-
authorizationUrl:
|
|
152
|
-
tokenUrl:
|
|
151
|
+
authorizationUrl: `${protocol}//${hostname}.authentication.${region}.hana.ondemand.com/oauth/authorize`,
|
|
152
|
+
tokenUrl: `${protocol}//${hostname}.authentication.${region}.hana.ondemand.com/oauth/token`,
|
|
153
153
|
tenantUrl: `${protocol}//${parsedTenant}`,
|
|
154
154
|
};
|
|
155
155
|
};
|