ask-cli
Version:
Alexa Skills Kit (ASK) Command Line Interfaces
42 lines (41 loc) • 2.27 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCLICompatibleDefaultRegion = exports.getAWSProfile = void 0;
const shared_ini_file_loader_1 = require("@smithy/shared-ini-file-loader");
const fs_extra_1 = __importDefault(require("fs-extra"));
const os_1 = __importDefault(require("os"));
const path_1 = __importDefault(require("path"));
const ramda_1 = __importDefault(require("ramda"));
const constants_1 = __importDefault(require("../../utils/constants"));
/**
* Returns the associated aws profile name to a ask profile
* @param {string} askProfile cli profile name
*/
function getAWSProfile(askProfile) {
if (askProfile === constants_1.default.PLACEHOLDER.ENVIRONMENT_VAR.PROFILE_NAME) {
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) {
throw new Error("Environmental variables AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY not defined.");
}
return constants_1.default.PLACEHOLDER.ENVIRONMENT_VAR.AWS_CREDENTIALS;
}
const askConfig = fs_extra_1.default.readJSONSync(path_1.default.join(os_1.default.homedir(), ".ask", "cli_config"));
return ramda_1.default.view(ramda_1.default.lensPath(["profiles", askProfile, "aws_profile"]), askConfig);
}
exports.getAWSProfile = getAWSProfile;
/**
* Returns the default aws region or global default aws region if available.
* @param {string} awsProfile aws profile name
*/
async function getCLICompatibleDefaultRegion(awsProfile) {
const profile = awsProfile || process.env.AWS_PROFILE || process.env.AWS_DEFAULT_PROFILE || shared_ini_file_loader_1.DEFAULT_PROFILE;
let region = process.env.AWS_REGION || process.env.AMAZON_REGION || process.env.AWS_DEFAULT_REGION || process.env.AMAZON_DEFAULT_REGION;
if (!region) {
const config = await (0, shared_ini_file_loader_1.parseKnownFiles)({}).catch(() => undefined);
region = config && config[profile] && config[profile].region;
}
return region || constants_1.default.AWS_SKILL_INFRASTRUCTURE_DEFAULT_REGION;
}
exports.getCLICompatibleDefaultRegion = getCLICompatibleDefaultRegion;