in commands/run.js [210:275]
async run(argv) {
const { full, short, rest } = parse(argv);
const parsed = this.validOptions(full, short);
const config = await loadConfig();
if (!config) {
console.error(`No any configurations.`);
process.exit(1);
}
let profile;
if (parsed.has('profile')) {
const profileName = parsed.get('profile');
if (!profileName) {
console.error(`Please input a valid profile name.`);
process.exit(1);
}
profile = loadProfile(config, profileName);
if (!profile) {
console.error(`Can not find profile '${profileName}'.`);
process.exit(1);
}
} else {
// load default profile
profile = loadCurrentProfile(config);
}
const credential = await getCredential(profile, config);
if (!credential) {
console.error(`the mode '${profile.mode}' is not supported currently.`);
process.exit(1);
}
if (rest && rest.length > 0) {
const [cmd, ...args] = rest;
const child = spawn(cmd, args, {
env: {
...process.env,
// ak & sk & security token
...credential.toEnv()
},
cwd: process.cwd(),
shell: true, // add it for Windows
stdio: 'inherit'
});
const code = await onExit(child);
process.exit(code);
} else {
console.log(`export ALIBABACLOUD_ACCESS_KEY_ID=${credential.getAccessKeyId()}`);
console.log(`export ALIBABA_CLOUD_ACCESS_KEY_ID=${credential.getAccessKeyId()}`);
console.log(`export ALICLOUD_ACCESS_KEY_ID=${credential.getAccessKeyId()}`);
console.log(`export ALIBABACLOUD_ACCESS_KEY_SECRET=${credential.getAccessKeySecret()}`);
console.log(`export ALIBABA_CLOUD_ACCESS_KEY_SECRET=${credential.getAccessKeySecret()}`);
console.log(`export ALICLOUD_ACCESS_KEY_SECRET=${credential.getAccessKeySecret()}`);
if (credential.getSecurityToken()) {
console.log(`export ALIBABACLOUD_SECURITY_TOKEN=${credential.getSecurityToken()}`);
console.log(`export ALIBABA_CLOUD_SECURITY_TOKEN=${credential.getSecurityToken()}`);
console.log(`export ALICLOUD_SECURITY_TOKEN=${credential.getSecurityToken()}`);
console.log(`export SECURITY_TOKEN=${credential.getSecurityToken()}`);
} else {
console.log(`unset ALIBABACLOUD_SECURITY_TOKEN`);
console.log(`unset ALIBABA_CLOUD_SECURITY_TOKEN`);
console.log(`unset ALICLOUD_SECURITY_TOKEN`);
console.log(`unset SECURITY_TOKEN`);
}
}
}