@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,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../../../../types";
|
|
1
|
+
import { Handler } from "../../../../../types.js";
|
|
2
2
|
export declare const create: () => Handler;
|
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const SecretsStorageSingleton_1 = require("../../../../../cache/secrets/SecretsStorageSingleton");
|
|
12
|
-
const createOptHandler = (option) => (0, options_1.create)([option], undefined, true, true);
|
|
13
|
-
const getLogger = () => (0, logger_1.get)("commands.handler.authentication.oauth.secretsProvider.options");
|
|
1
|
+
import { create as createNextHandler } from "../../../next.js";
|
|
2
|
+
import { create as createOrHandler } from "../../../or.js";
|
|
3
|
+
import { create as createOptionsHandler } from "../../../options/index.js";
|
|
4
|
+
import { create as createCheckOptionsExistenceHandler } from "../../../checkOptionsExistence.js";
|
|
5
|
+
import { OPTION_ACCESS_TOKEN, OPTION_AUTHORIZATION_FLOW, OPTION_AUTHORIZATION_URL, OPTION_CLIENT_ID, OPTION_CLIENT_SECRET, OPTION_EXPIRES_IN, OPTION_REFRESH_TOKEN, OPTION_TOKEN_URL, } from "../../../../../constants.js";
|
|
6
|
+
import { get } from "../../../../../logger/index.js";
|
|
7
|
+
import { getOptionValueFromConfigGracefully } from "../../../../../utils/options.js";
|
|
8
|
+
import { SecretsStorageSingleton } from "../../../../../cache/secrets/SecretsStorageSingleton.js";
|
|
9
|
+
const createOptHandler = (option) => createOptionsHandler([option], undefined, true, true);
|
|
10
|
+
const getLogger = () => get("commands.handler.authentication.oauth.secretsProvider.options");
|
|
14
11
|
const setOAuthFromOptions = async () => async () => {
|
|
15
|
-
const expiresIn =
|
|
16
|
-
await
|
|
17
|
-
client_id:
|
|
18
|
-
client_secret:
|
|
19
|
-
authorization_url:
|
|
20
|
-
token_url:
|
|
21
|
-
access_token:
|
|
22
|
-
refresh_token:
|
|
23
|
-
authorization_flow:
|
|
12
|
+
const expiresIn = getOptionValueFromConfigGracefully(OPTION_EXPIRES_IN);
|
|
13
|
+
await SecretsStorageSingleton.SINGLETON.storeSecret({
|
|
14
|
+
client_id: getOptionValueFromConfigGracefully(OPTION_CLIENT_ID),
|
|
15
|
+
client_secret: getOptionValueFromConfigGracefully(OPTION_CLIENT_SECRET),
|
|
16
|
+
authorization_url: getOptionValueFromConfigGracefully(OPTION_AUTHORIZATION_URL),
|
|
17
|
+
token_url: getOptionValueFromConfigGracefully(OPTION_TOKEN_URL),
|
|
18
|
+
access_token: getOptionValueFromConfigGracefully(OPTION_ACCESS_TOKEN),
|
|
19
|
+
refresh_token: getOptionValueFromConfigGracefully(OPTION_REFRESH_TOKEN),
|
|
20
|
+
authorization_flow: getOptionValueFromConfigGracefully(OPTION_AUTHORIZATION_FLOW),
|
|
24
21
|
expires_in: expiresIn ? parseInt(expiresIn, 10) : undefined,
|
|
25
22
|
});
|
|
26
23
|
};
|
|
@@ -28,11 +25,10 @@ const pre = async () => async () => {
|
|
|
28
25
|
const { info } = getLogger();
|
|
29
26
|
info("reading secrets from options");
|
|
30
27
|
};
|
|
31
|
-
const create = () => (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
export const create = () => createNextHandler("handler.authentication.oauth.secretsProvider.options$outer", pre, createOrHandler("commands.handler.authentication.oauth.secretsProvider.options", createCheckOptionsExistenceHandler(OPTION_ACCESS_TOKEN, false), createNextHandler("handler.authentication.oauth.secretsProvider.options$inner", createOptHandler(OPTION_CLIENT_ID), createOptHandler(OPTION_CLIENT_SECRET), createOptionsHandler([
|
|
29
|
+
OPTION_AUTHORIZATION_URL,
|
|
30
|
+
OPTION_TOKEN_URL,
|
|
31
|
+
OPTION_REFRESH_TOKEN,
|
|
32
|
+
OPTION_EXPIRES_IN,
|
|
33
|
+
OPTION_AUTHORIZATION_FLOW,
|
|
37
34
|
]))), setOAuthFromOptions);
|
|
38
|
-
exports.create = create;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../../../../types";
|
|
1
|
+
import { Handler } from "../../../../../types.js";
|
|
2
2
|
export declare const create: () => Handler;
|
|
@@ -1,28 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const utils_2 = require("./utils");
|
|
11
|
-
const SecretsStorageSingleton_1 = require("../../../../../cache/secrets/SecretsStorageSingleton");
|
|
12
|
-
const getLogger = () => (0, logger_1.get)("commands.handler.authentication.oauth.tokenProvider.getToken");
|
|
1
|
+
import { create as createNextHandler } from "../../../next.js";
|
|
2
|
+
import { create as createOptionsHandler } from "../../../options/index.js";
|
|
3
|
+
import { OPTION_CODE } from "../../../../../constants.js";
|
|
4
|
+
import { get } from "../../../../../logger/index.js";
|
|
5
|
+
import { GrantType } from "../../../../../types.js";
|
|
6
|
+
import { readToken } from "../utils.js";
|
|
7
|
+
import { getCode } from "./utils.js";
|
|
8
|
+
import { SecretsStorageSingleton } from "../../../../../cache/secrets/SecretsStorageSingleton.js";
|
|
9
|
+
const getLogger = () => get("commands.handler.authentication.oauth.tokenProvider.getToken");
|
|
13
10
|
const createGetTokenHandler = () => {
|
|
14
11
|
const handler = async () => async () => {
|
|
15
12
|
const { info: logInfo, debug } = getLogger();
|
|
16
13
|
logInfo("checking token existence");
|
|
17
|
-
const secrets = await
|
|
14
|
+
const secrets = await SecretsStorageSingleton.SINGLETON.getDefaultSecret();
|
|
18
15
|
if (!secrets.access_token && !secrets.refresh_token) {
|
|
19
|
-
if (secrets.authorization_flow ===
|
|
20
|
-
const code = await
|
|
16
|
+
if (secrets.authorization_flow === GrantType.authorization_code) {
|
|
17
|
+
const code = await getCode(secrets.authorization_url, secrets.client_id);
|
|
21
18
|
debug("code received, reading token");
|
|
22
|
-
await
|
|
19
|
+
await readToken({ code, grant_type: secrets.authorization_flow });
|
|
23
20
|
}
|
|
24
|
-
else if (secrets.authorization_flow ===
|
|
25
|
-
await
|
|
21
|
+
else if (secrets.authorization_flow === GrantType.client_credentials) {
|
|
22
|
+
await readToken({ grant_type: secrets.authorization_flow });
|
|
26
23
|
}
|
|
27
24
|
else {
|
|
28
25
|
throw new Error(`invalid grant type ${secrets.authorization_flow}`);
|
|
@@ -37,5 +34,4 @@ const createGetTokenHandler = () => {
|
|
|
37
34
|
};
|
|
38
35
|
return handler;
|
|
39
36
|
};
|
|
40
|
-
const create = () => (
|
|
41
|
-
exports.create = create;
|
|
37
|
+
export const create = () => createNextHandler("commands.handler.authentication.oauth.tokenProvider.getToken", createOptionsHandler(OPTION_CODE), createGetTokenHandler());
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../../../../types";
|
|
1
|
+
import { Handler } from "../../../../../types.js";
|
|
2
2
|
export declare const create: () => Handler;
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
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)("commands.handler.authentication.oauth.tokenProvider", (0, or_1.create)("commands.handler.authentication.oauth.tokenProvider", (0, getToken_1.create)(), (0, refreshToken_1.create)(true)), (0, setAuthorization_1.create)()));
|
|
11
|
-
exports.create = create;
|
|
1
|
+
import { create as createNextHandler } from "../../../next.js";
|
|
2
|
+
import { create as createErrorHandler } from "../../../error.js";
|
|
3
|
+
import { create as createOrHandler } from "../../../or.js";
|
|
4
|
+
import { create as createRefreshTokenHandler } from "./refreshToken.js";
|
|
5
|
+
import { create as setAuthorizationHandler } from "./setAuthorization.js";
|
|
6
|
+
import { create as createGetTokenHandler } from "./getToken.js";
|
|
7
|
+
export const create = () => createErrorHandler("failed to handle token", createNextHandler("commands.handler.authentication.oauth.tokenProvider", createOrHandler("commands.handler.authentication.oauth.tokenProvider", createGetTokenHandler(), createRefreshTokenHandler(true)), setAuthorizationHandler()));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../../../../types";
|
|
1
|
+
import { Handler } from "../../../../../types.js";
|
|
2
2
|
export declare const create: (forceRefresh?: boolean) => Handler;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const logger_1 = require("../../../../../logger");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
|
-
const create = (forceRefresh = false) => async () => async () => {
|
|
1
|
+
import { get } from "../../../../../logger/index.js";
|
|
2
|
+
import { refreshToken } from "./utils.js";
|
|
3
|
+
export const create = (forceRefresh = false) => async () => async () => {
|
|
7
4
|
try {
|
|
8
|
-
await
|
|
5
|
+
await refreshToken(forceRefresh);
|
|
9
6
|
}
|
|
10
7
|
catch (err) {
|
|
11
|
-
const { error } =
|
|
8
|
+
const { error } = get("commands.handler.authentication.oauth.tokenProvider.refreshToken");
|
|
12
9
|
error("failed to refresh token", err);
|
|
13
10
|
}
|
|
14
11
|
};
|
|
15
|
-
exports.create = create;
|
|
@@ -1,35 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const SecretsStorageSingleton_1 = require("../../../../../cache/secrets/SecretsStorageSingleton");
|
|
12
|
-
const updateAuthorization = async () => {
|
|
13
|
-
const { info: logInfo, debug } = (0, logger_1.get)("commands.handler.authentication.oauth.tokenProvider.setAuthorization");
|
|
1
|
+
import { get as getConfig } from "../../../../../config/index.js";
|
|
2
|
+
import { AuthenticationMethod, OPTION_ACCESS_TOKEN, } from "../../../../../constants.js";
|
|
3
|
+
import { get } from "../../../../../logger/index.js";
|
|
4
|
+
import { getOptionValueFromConfigGracefully } from "../../../../../utils/options.js";
|
|
5
|
+
import { checkOptions } from "../../../options/utils.js";
|
|
6
|
+
import { setAuthenticationMethod, setTargetHost } from "../../../utils.js";
|
|
7
|
+
import { setAuthorization } from "../../utils.js";
|
|
8
|
+
import { SecretsStorageSingleton } from "../../../../../cache/secrets/SecretsStorageSingleton.js";
|
|
9
|
+
export const updateAuthorization = async () => {
|
|
10
|
+
const { info: logInfo, debug } = get("commands.handler.authentication.oauth.tokenProvider.setAuthorization");
|
|
14
11
|
logInfo("setting authorization using access token");
|
|
15
|
-
const config = (
|
|
16
|
-
const secrets = await
|
|
12
|
+
const config = getConfig();
|
|
13
|
+
const secrets = await SecretsStorageSingleton.SINGLETON.getDefaultSecret();
|
|
17
14
|
const accessToken = secrets.access_token ||
|
|
18
|
-
|
|
15
|
+
getOptionValueFromConfigGracefully(OPTION_ACCESS_TOKEN);
|
|
19
16
|
if (accessToken) {
|
|
20
17
|
debug("access token found");
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
setAuthorization({ authorization: `Bearer ${accessToken}` });
|
|
19
|
+
setTargetHost(`${config.tenantUrl}`);
|
|
20
|
+
setAuthenticationMethod(AuthenticationMethod.oauth);
|
|
24
21
|
}
|
|
25
22
|
else {
|
|
26
23
|
debug("no access token found");
|
|
27
24
|
throw new Error("cannot set authorization: no access token found in configuration");
|
|
28
25
|
}
|
|
29
26
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return exports.updateAuthorization;
|
|
27
|
+
export const create = () => async (command) => {
|
|
28
|
+
await checkOptions(OPTION_ACCESS_TOKEN, command);
|
|
29
|
+
return updateAuthorization;
|
|
34
30
|
};
|
|
35
|
-
exports.create = create;
|
|
@@ -1,55 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const types_1 = require("../../../../../types");
|
|
15
|
-
const getLogger = () => (0, logger_1.get)("commands.handler.authentication.oauth.tokenProvider.utils.refreshToken");
|
|
16
|
-
const refreshToken = async (forceRefresh = false) => {
|
|
1
|
+
import { createServer } from "http";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import { get } from "../../../../../logger/index.js";
|
|
4
|
+
import { isExpired, readToken } from "../utils.js";
|
|
5
|
+
import { updateAuthorization } from "./setAuthorization.js";
|
|
6
|
+
import { OPTION_CODE, PATH_TO_ERROR_HTML, PATH_TO_SUCCESS_HTML, } from "../../../../../constants.js";
|
|
7
|
+
import { getOptionValueFromConfig } from "../../../../../utils/options.js";
|
|
8
|
+
import { SecretsStorageSingleton } from "../../../../../cache/secrets/SecretsStorageSingleton.js";
|
|
9
|
+
import { openUrlInBrowser } from "../../../../../utils/openUtils.js";
|
|
10
|
+
import { logVerbose } from "../../../../../logger/utils.js";
|
|
11
|
+
import { GrantType } from "../../../../../types.js";
|
|
12
|
+
const getLogger = () => get("commands.handler.authentication.oauth.tokenProvider.utils.refreshToken");
|
|
13
|
+
export const refreshToken = async (forceRefresh = false) => {
|
|
17
14
|
const logger = getLogger();
|
|
18
|
-
const secrets = await
|
|
15
|
+
const secrets = await SecretsStorageSingleton.SINGLETON.getDefaultSecret();
|
|
19
16
|
if ((!forceRefresh && !secrets.expires_after) ||
|
|
20
|
-
(secrets.authorization_flow ===
|
|
17
|
+
(secrets.authorization_flow === GrantType.authorization_code &&
|
|
21
18
|
!secrets.refresh_token)) {
|
|
22
|
-
|
|
19
|
+
logVerbose(logger, "Access token cannot be refreshed. Is the refresh token available?");
|
|
23
20
|
throw new Error("invalid secrets information");
|
|
24
21
|
}
|
|
25
22
|
logger.info("checking token expiry date");
|
|
26
|
-
if (forceRefresh ||
|
|
23
|
+
if (forceRefresh || isExpired(secrets.expires_after)) {
|
|
27
24
|
logger.debug("access token is expired, refreshing token");
|
|
28
|
-
if (secrets.authorization_flow ===
|
|
29
|
-
await
|
|
25
|
+
if (secrets.authorization_flow === GrantType.client_credentials) {
|
|
26
|
+
await readToken({ grant_type: secrets.authorization_flow });
|
|
30
27
|
}
|
|
31
28
|
else {
|
|
32
|
-
await
|
|
29
|
+
await readToken({
|
|
33
30
|
refresh_token: secrets.refresh_token,
|
|
34
|
-
grant_type:
|
|
31
|
+
grant_type: GrantType.refresh_token,
|
|
35
32
|
});
|
|
36
33
|
}
|
|
37
|
-
await
|
|
34
|
+
await updateAuthorization();
|
|
38
35
|
}
|
|
39
36
|
else {
|
|
40
37
|
logger.debug("access token is not expired");
|
|
41
38
|
}
|
|
42
39
|
};
|
|
43
|
-
|
|
44
|
-
const retrieveCode = async () => new Promise((resolve, reject) => {
|
|
40
|
+
export const retrieveCode = async () => new Promise((resolve, reject) => {
|
|
45
41
|
void (async () => {
|
|
46
42
|
const { debug, error, output } = getLogger();
|
|
47
43
|
try {
|
|
48
|
-
const secrets = await
|
|
44
|
+
const secrets = await SecretsStorageSingleton.SINGLETON.getDefaultSecret();
|
|
49
45
|
const defaultPort = secrets.customClient ? "8080" : "65000";
|
|
50
46
|
const PORT = parseInt(process.env.CLI_HTTP_PORT ?? defaultPort, 10);
|
|
51
47
|
let timeout;
|
|
52
|
-
const server =
|
|
48
|
+
const server = createServer((req, res) => {
|
|
53
49
|
void (async () => {
|
|
54
50
|
clearTimeout(timeout);
|
|
55
51
|
const code = new URL(req.url
|
|
@@ -57,7 +53,7 @@ const retrieveCode = async () => new Promise((resolve, reject) => {
|
|
|
57
53
|
: "http://no-code.damn").searchParams.get("code");
|
|
58
54
|
let file;
|
|
59
55
|
try {
|
|
60
|
-
file = await
|
|
56
|
+
file = await fs.readFile(code ? PATH_TO_SUCCESS_HTML : PATH_TO_ERROR_HTML, "utf8");
|
|
61
57
|
}
|
|
62
58
|
catch (err) {
|
|
63
59
|
debug("failed to read file for code", code, err);
|
|
@@ -97,20 +93,18 @@ const retrieveCode = async () => new Promise((resolve, reject) => {
|
|
|
97
93
|
}
|
|
98
94
|
})();
|
|
99
95
|
});
|
|
100
|
-
|
|
101
|
-
const getCode = async (authorizeUrl, clientId) => {
|
|
96
|
+
export const getCode = async (authorizeUrl, clientId) => {
|
|
102
97
|
const { debug } = getLogger();
|
|
103
98
|
try {
|
|
104
|
-
return
|
|
99
|
+
return getOptionValueFromConfig(OPTION_CODE);
|
|
105
100
|
}
|
|
106
101
|
catch (err) {
|
|
107
102
|
debug("failed to retrieve code from options", err);
|
|
108
|
-
const code =
|
|
109
|
-
void
|
|
103
|
+
const code = retrieveCode();
|
|
104
|
+
void openUrlInBrowser(authorizeUrl, {
|
|
110
105
|
response_type: "code",
|
|
111
106
|
client_id: clientId,
|
|
112
107
|
});
|
|
113
108
|
return code;
|
|
114
109
|
}
|
|
115
110
|
};
|
|
116
|
-
exports.getCode = getCode;
|
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const utils_1 = require("../../../../logger/utils");
|
|
11
|
-
const logger_1 = require("../../../../logger");
|
|
12
|
-
const getLogger = () => (0, logger_1.get)("commands.handler.authentication.oauth.utils");
|
|
13
|
-
const calculateExpiresAfter = (expires_in) => Math.floor(Date.now() / 1000) + expires_in - 10;
|
|
14
|
-
exports.calculateExpiresAfter = calculateExpiresAfter;
|
|
15
|
-
const isExpired = (expires_after) => expires_after <= (0, exports.calculateExpiresAfter)(10);
|
|
16
|
-
exports.isExpired = isExpired;
|
|
17
|
-
const readToken = async (data) => {
|
|
1
|
+
import qs from "qs";
|
|
2
|
+
import { fetch } from "../../../../utils/http/index.js";
|
|
3
|
+
import { SecretsStorageSingleton } from "../../../../cache/secrets/SecretsStorageSingleton.js";
|
|
4
|
+
import { logVerbose } from "../../../../logger/utils.js";
|
|
5
|
+
import { get } from "../../../../logger/index.js";
|
|
6
|
+
const getLogger = () => get("commands.handler.authentication.oauth.utils");
|
|
7
|
+
export const calculateExpiresAfter = (expires_in) => Math.floor(Date.now() / 1000) + expires_in - 10;
|
|
8
|
+
export const isExpired = (expires_after) => expires_after <= calculateExpiresAfter(10);
|
|
9
|
+
export const readToken = async (data) => {
|
|
18
10
|
const logger = getLogger();
|
|
19
|
-
const secret = await
|
|
11
|
+
const secret = await SecretsStorageSingleton.SINGLETON.getDefaultSecret();
|
|
20
12
|
if (!secret.token_url || !secret.client_id || !secret.client_secret) {
|
|
21
|
-
|
|
13
|
+
logVerbose(logger, `The secret is invalid. Either the token URL, client ID, or client secret is missing.` +
|
|
22
14
|
`Please check the secret and login again.`);
|
|
23
15
|
throw new Error("invalid secrets information");
|
|
24
16
|
}
|
|
@@ -30,7 +22,7 @@ const readToken = async (data) => {
|
|
|
30
22
|
body.client_id = secret.client_id;
|
|
31
23
|
}
|
|
32
24
|
logger.debug(`reading token`);
|
|
33
|
-
const info = (await
|
|
25
|
+
const info = (await fetch({
|
|
34
26
|
method: "POST",
|
|
35
27
|
url: secret.token_url,
|
|
36
28
|
auth: {
|
|
@@ -41,13 +33,12 @@ const readToken = async (data) => {
|
|
|
41
33
|
"x-sap-sac-custom-auth": !!secret.customClient,
|
|
42
34
|
"content-type": "application/x-www-form-urlencoded",
|
|
43
35
|
},
|
|
44
|
-
data:
|
|
36
|
+
data: qs.stringify(body),
|
|
45
37
|
})).data;
|
|
46
38
|
logger.debug(`token received: ${JSON.stringify(info, null, 2)}`);
|
|
47
|
-
await
|
|
39
|
+
await SecretsStorageSingleton.SINGLETON.storeSecret({
|
|
48
40
|
...secret,
|
|
49
41
|
...info,
|
|
50
|
-
expires_after:
|
|
42
|
+
expires_after: calculateExpiresAfter(info.expires_in),
|
|
51
43
|
});
|
|
52
44
|
};
|
|
53
|
-
exports.readToken = readToken;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../../../types";
|
|
1
|
+
import { Handler } from "../../../../types.js";
|
|
2
2
|
export declare const create: () => Handler;
|
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const config = (0, config_1.get)();
|
|
1
|
+
import { set, get } from "../../../../config/index.js";
|
|
2
|
+
import { CONFIG_PASSCODE_FUNCTION, OPTION_PASSCODE,
|
|
3
|
+
/* jscpd:ignore-start */
|
|
4
|
+
} from "../../../../constants.js";
|
|
5
|
+
export const create = () => async () => async () => {
|
|
6
|
+
const config = get();
|
|
8
7
|
/* jscpd:ignore-end */
|
|
9
|
-
if (!config[
|
|
10
|
-
typeof config[
|
|
8
|
+
if (!config[CONFIG_PASSCODE_FUNCTION] ||
|
|
9
|
+
typeof config[CONFIG_PASSCODE_FUNCTION] !== "function") {
|
|
11
10
|
throw new Error("passcode function not available from configuration or provided argument is no function");
|
|
12
11
|
}
|
|
13
|
-
let passcode = config.options[
|
|
12
|
+
let passcode = config.options[OPTION_PASSCODE.longName];
|
|
14
13
|
if (!passcode) {
|
|
15
|
-
passcode = await config[
|
|
14
|
+
passcode = await config[CONFIG_PASSCODE_FUNCTION]();
|
|
16
15
|
if (!passcode) {
|
|
17
16
|
throw new Error(`provided passcode function did not return a passcode. returned value was ${passcode}`);
|
|
18
17
|
}
|
|
19
|
-
|
|
18
|
+
set({ passcode });
|
|
20
19
|
}
|
|
21
20
|
};
|
|
22
|
-
exports.create = create;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../../../types";
|
|
1
|
+
import { Handler } from "../../../../types.js";
|
|
2
2
|
export declare const create: () => Handler;
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if ((0, core_1.getAuthenticationMethods)().includes(constants_1.AuthenticationMethod.passcode)) {
|
|
15
|
-
return (0, next_1.create)("commands.handler.authentication.passcode", (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)("commands.handler.authentication.passcode$value", (0, function_1.create)(), (0, input_1.create)()), (0, setPasscode_1.create)());
|
|
1
|
+
import { create as createOrHandler } from "../../or.js";
|
|
2
|
+
import { create as createNextHandler } from "../../next.js";
|
|
3
|
+
import { create as createFailHandler } from "../../fail.js";
|
|
4
|
+
import { create as createCheckOptionsExistence } from "../../checkOptionsExistence.js";
|
|
5
|
+
import { create as createInputHandler } from "./input.js";
|
|
6
|
+
import { create as createFunctionHandler } from "./function.js";
|
|
7
|
+
import { create as createSetPasscodeHandler } from "./setPasscode.js";
|
|
8
|
+
import { AuthenticationMethod, OPTION_ACCESS_TOKEN, OPTION_CLIENT_ID, OPTION_SECRETS_FILE, } from "../../../../constants.js";
|
|
9
|
+
import { getAuthenticationMethods } from "../../../../config/core.js";
|
|
10
|
+
/* jscpd:ignore-end */
|
|
11
|
+
export const create = () => {
|
|
12
|
+
if (getAuthenticationMethods().includes(AuthenticationMethod.passcode)) {
|
|
13
|
+
return createNextHandler("commands.handler.authentication.passcode", createCheckOptionsExistence(OPTION_CLIENT_ID), createCheckOptionsExistence(OPTION_ACCESS_TOKEN), createCheckOptionsExistence(OPTION_SECRETS_FILE), createOrHandler("commands.handler.authentication.passcode$value", createFunctionHandler(), createInputHandler()), createSetPasscodeHandler());
|
|
16
14
|
}
|
|
17
|
-
return (
|
|
15
|
+
return createFailHandler();
|
|
18
16
|
};
|
|
19
|
-
exports.create = create;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../../../types";
|
|
1
|
+
import { Handler } from "../../../../types.js";
|
|
2
2
|
export declare const create: () => Handler;
|
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const config_1 = require("../../../../config");
|
|
9
|
-
const constants_1 = require("../../../../constants");
|
|
10
|
-
const utils_1 = require("../../options/utils");
|
|
11
|
-
const openUtils_1 = require("../../../../utils/openUtils");
|
|
12
|
-
const create = () => async (command) => {
|
|
13
|
-
await (0, utils_1.checkOptions)(constants_1.OPTION_PASSCODE, command);
|
|
1
|
+
import prompts from "prompts";
|
|
2
|
+
import { get, set } from "../../../../config/index.js";
|
|
3
|
+
import { OPTION_PASSCODE } from "../../../../constants.js";
|
|
4
|
+
import { checkOptions } from "../../options/utils.js";
|
|
5
|
+
import { openUrlInBrowser } from "../../../../utils/openUtils.js";
|
|
6
|
+
export const create = () => async (command) => {
|
|
7
|
+
await checkOptions(OPTION_PASSCODE, command);
|
|
14
8
|
return async () => {
|
|
15
|
-
const config =
|
|
16
|
-
let passcode = config.options[
|
|
9
|
+
const config = get();
|
|
10
|
+
let passcode = config.options[OPTION_PASSCODE.longName];
|
|
17
11
|
if (!passcode) {
|
|
18
12
|
if (!config.passcodeUrl) {
|
|
19
13
|
throw new Error("passcode url is not available");
|
|
20
14
|
}
|
|
21
|
-
const res = await
|
|
15
|
+
const res = await prompts.prompt({
|
|
22
16
|
type: "confirm",
|
|
23
17
|
initial: true,
|
|
24
18
|
message: `Do you want to retrieve a temporary authentication code from ${config.passcodeUrl}?`,
|
|
25
19
|
name: "value",
|
|
26
20
|
});
|
|
27
21
|
if (res.value) {
|
|
28
|
-
await
|
|
29
|
-
passcode = (await
|
|
22
|
+
await openUrlInBrowser(config.passcodeUrl);
|
|
23
|
+
passcode = (await prompts.prompt({
|
|
30
24
|
type: "password",
|
|
31
25
|
message: "Enter your temporary authentication code:",
|
|
32
26
|
name: "value",
|
|
@@ -36,7 +30,6 @@ const create = () => async (command) => {
|
|
|
36
30
|
if (!passcode) {
|
|
37
31
|
throw new Error("no passcode");
|
|
38
32
|
}
|
|
39
|
-
|
|
33
|
+
set({ passcode });
|
|
40
34
|
};
|
|
41
35
|
};
|
|
42
|
-
exports.create = create;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Handler } from "../../../../types";
|
|
1
|
+
import { Handler } from "../../../../types.js";
|
|
2
2
|
export declare const create: () => Handler;
|