@sap/cli-core
Version:
Command-Line Interface (CLI) Core Module
36 lines (35 loc) • 1.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.create = exports.updateAuthorization = void 0;
const config_1 = require("../../../../../config");
const constants_1 = require("../../../../../constants");
const logger_1 = require("../../../../../logger");
const options_1 = require("../../../../../utils/options");
const utils_1 = require("../../../options/utils");
const utils_2 = require("../../../utils");
const utils_3 = require("../../utils");
const SecretsStorageSingleton_1 = require("../../../../../cache/secrets/SecretsStorageSingleton");
const updateAuthorization = async () => {
const { info: logInfo, debug } = (0, logger_1.get)("commands.handler.authentication.oauth.tokenProvider.setAuthorization");
logInfo("setting authorization using access token");
const config = (0, config_1.get)();
const secrets = await SecretsStorageSingleton_1.SecretsStorageSingleton.SINGLETON.getDefaultSecret();
const accessToken = secrets.access_token ||
(0, options_1.getOptionValueFromConfigGracefully)(constants_1.OPTION_ACCESS_TOKEN);
if (accessToken) {
debug("access token found");
(0, utils_3.setAuthorization)({ authorization: `Bearer ${accessToken}` });
(0, utils_2.setTargetHost)(`${config.tenantUrl}`);
(0, utils_2.setAuthenticationMethod)(constants_1.AuthenticationMethod.oauth);
}
else {
debug("no access token found");
throw new Error("cannot set authorization: no access token found in configuration");
}
};
exports.updateAuthorization = updateAuthorization;
const create = () => async (command) => {
await (0, utils_1.checkOptions)(constants_1.OPTION_ACCESS_TOKEN, command);
return exports.updateAuthorization;
};
exports.create = create;