Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug for user defined account_id and access_config #103

Merged
merged 1 commit into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 23 additions & 11 deletions commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,25 @@ export default class Login {
[accountId, accessConfigurationId] = cache.profiles[profile].split(':');
} else {
const accounts = await portal.listAllAccounts();

if (accounts.length === 0) {
console.error(`You don't have access to any account.`);
process.exit(-1);
}

if (ctx.account_id) {
// use user defined accountId
accountId = ctx.account_id;
if (!accounts.find((d) => d.AccountId === accountId)) {
console.error(`The account '${accountId}' does not exist in your account list.`);
const sa = accounts.find((d) => {
return d.AccountId === ctx.account_id;
});

if (!sa) {
console.error(`The account '${ctx.account_id}' does not exist in your account list.`);
process.exit(-1);
}
}
else {

accountId = sa.AccountId;
console.log(`Used account: ${sa.DisplayName}(${accountId})`);
} else {
let sa;
if (accounts.length > 1) {
// 有多个账号时启动选择
Expand All @@ -156,8 +160,9 @@ export default class Login {
}

accountId = sa.AccountId;
console.log(`used account: ${sa.DisplayName}(${accountId})`);
console.log(`Used account: ${sa.DisplayName}(${accountId})`);
}

const configs = await portal.listAllAccessConfigurations({
accountId: accountId
});
Expand All @@ -170,8 +175,7 @@ export default class Login {
console.error(`The access configuration '${ctx.access_config}' does not exist in your account.`);
process.exit(-1);
}
}
else if (configs.length > 1) {
} else if (configs.length > 1) {
const choices = configs.map((d) => {
return {
name: `${d.AccessConfigurationName}(${d.AccessConfigurationId})`,
Expand All @@ -190,7 +194,7 @@ export default class Login {
}

accessConfigurationId = selectedConfig.AccessConfigurationId;
console.log(`used access configuration: ${selectedConfig.AccessConfigurationName}(${accessConfigurationId})`);
console.log(`Used access configuration: ${selectedConfig.AccessConfigurationName}(${accessConfigurationId})`);
}

const credential = await portal.createCloudCredential({
Expand Down Expand Up @@ -250,7 +254,15 @@ export default class Login {
process.exit(-1);
}

const ctx = { cache, config, signinUrl: new URL(signinUrl), profile };
const ctx = {
cache,
config,
signinUrl: new URL(signinUrl),
profile,
// argv 默认解析为了 number
account_id: String(argv.account_id),
access_config: argv.access_config
};

if (!argv.force) {
// 没有强制登录,优先检查缓存
Expand Down
Loading