esa-cli 1.0.8-beta.1 → 1.0.8-beta.3
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/dist/commands/login/index.js +4 -103
- package/dist/commands/logout.js +1 -8
- package/dist/commands/utils.js +10 -11
- package/dist/i18n/locales.json +0 -24
- package/dist/libs/api.js +7 -4
- package/dist/libs/apiService.js +14 -8
- package/dist/utils/checkVersion.js +14 -1
- package/dist/utils/fileUtils/index.js +3 -5
- package/dist/utils/validateCredentials.js +16 -12
- package/package.json +1 -1
|
@@ -13,42 +13,11 @@ import t from '../../i18n/index.js';
|
|
|
13
13
|
import logger from '../../libs/logger.js';
|
|
14
14
|
import { getCliConfig, updateCliConfigFile, generateDefaultConfig } from '../../utils/fileUtils/index.js';
|
|
15
15
|
import { validateCredentials } from '../../utils/validateCredentials.js';
|
|
16
|
-
/** Parse STS token string: "AccessKeyId,AccessKeySecret,SecurityToken" or JSON */
|
|
17
|
-
function parseStsToken(raw) {
|
|
18
|
-
var _a, _b, _c;
|
|
19
|
-
const s = raw.trim();
|
|
20
|
-
if (!s)
|
|
21
|
-
return null;
|
|
22
|
-
if (s.startsWith('{')) {
|
|
23
|
-
try {
|
|
24
|
-
const o = JSON.parse(s);
|
|
25
|
-
const accessKeyId = (_a = o.AccessKeyId) !== null && _a !== void 0 ? _a : o.accessKeyId;
|
|
26
|
-
const accessKeySecret = (_b = o.AccessKeySecret) !== null && _b !== void 0 ? _b : o.accessKeySecret;
|
|
27
|
-
const securityToken = (_c = o.SecurityToken) !== null && _c !== void 0 ? _c : o.securityToken;
|
|
28
|
-
if (accessKeyId && accessKeySecret && securityToken) {
|
|
29
|
-
return { accessKeyId, accessKeySecret, securityToken };
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (_d) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
}
|
|
37
|
-
const parts = s.split(',').map((p) => p.trim());
|
|
38
|
-
if (parts.length >= 3) {
|
|
39
|
-
return {
|
|
40
|
-
accessKeyId: parts[0],
|
|
41
|
-
accessKeySecret: parts[1],
|
|
42
|
-
securityToken: parts.slice(2).join(',').trim()
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
16
|
const login = {
|
|
48
17
|
command: 'login',
|
|
49
18
|
describe: `🔑 ${t('login_describe').d('Login to the server')}`,
|
|
50
19
|
builder: (yargs) => {
|
|
51
|
-
var _a, _b
|
|
20
|
+
var _a, _b;
|
|
52
21
|
return yargs
|
|
53
22
|
.option('access-key-id', {
|
|
54
23
|
alias: 'ak',
|
|
@@ -59,10 +28,6 @@ const login = {
|
|
|
59
28
|
alias: 'sk',
|
|
60
29
|
describe: (_b = t('login_option_access_key_secret')) === null || _b === void 0 ? void 0 : _b.d('AccessKey Secret'),
|
|
61
30
|
type: 'string'
|
|
62
|
-
})
|
|
63
|
-
.option('sts-token', {
|
|
64
|
-
describe: (_c = t('login_option_sts_token')) === null || _c === void 0 ? void 0 : _c.d('STS token: AccessKeyId,AccessKeySecret,SecurityToken (comma-separated, one-shot)'),
|
|
65
|
-
type: 'string'
|
|
66
31
|
});
|
|
67
32
|
},
|
|
68
33
|
handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -73,10 +38,8 @@ export default login;
|
|
|
73
38
|
export function handleLogin(argv) {
|
|
74
39
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
40
|
generateDefaultConfig();
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
process.env.ESA_ACCESS_KEY_SECRET) {
|
|
79
|
-
const result = yield validateCredentials(process.env.ESA_ACCESS_KEY_ID, process.env.ESA_ACCESS_KEY_SECRET, envSecurityToken);
|
|
41
|
+
if (process.env.ESA_ACCESS_KEY_ID && process.env.ESA_ACCESS_KEY_SECRET) {
|
|
42
|
+
const result = yield validateCredentials(process.env.ESA_ACCESS_KEY_ID, process.env.ESA_ACCESS_KEY_SECRET);
|
|
80
43
|
if (result.valid) {
|
|
81
44
|
logger.log(t('login_get_credentials_from_environment_variables').d('Get credentials from environment variables'));
|
|
82
45
|
logger.success(t('login_success').d('Login success!'));
|
|
@@ -86,27 +49,6 @@ export function handleLogin(argv) {
|
|
|
86
49
|
}
|
|
87
50
|
return;
|
|
88
51
|
}
|
|
89
|
-
const stsTokenRaw = argv === null || argv === void 0 ? void 0 : argv['sts-token'];
|
|
90
|
-
if (stsTokenRaw) {
|
|
91
|
-
const parsed = parseStsToken(stsTokenRaw);
|
|
92
|
-
if (!parsed) {
|
|
93
|
-
logger.error(t('login_sts_token_format_invalid').d('Invalid STS token format. Use: AccessKeyId,AccessKeySecret,SecurityToken'));
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
const result = yield validateCredentials(parsed.accessKeyId, parsed.accessKeySecret, parsed.securityToken);
|
|
97
|
-
if (result.valid) {
|
|
98
|
-
logger.success(t('login_success').d('Login success!'));
|
|
99
|
-
updateCliConfigFile(Object.assign({ auth: {
|
|
100
|
-
accessKeyId: parsed.accessKeyId,
|
|
101
|
-
accessKeySecret: parsed.accessKeySecret,
|
|
102
|
-
securityToken: parsed.securityToken
|
|
103
|
-
} }, (result.endpoint ? { endpoint: result.endpoint } : {})));
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
logger.error(result.message || 'Login failed');
|
|
107
|
-
}
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
52
|
const accessKeyId = argv === null || argv === void 0 ? void 0 : argv['access-key-id'];
|
|
111
53
|
const accessKeySecret = argv === null || argv === void 0 ? void 0 : argv['access-key-secret'];
|
|
112
54
|
if (accessKeyId && accessKeySecret) {
|
|
@@ -131,7 +73,7 @@ export function handleLogin(argv) {
|
|
|
131
73
|
cliConfig.auth &&
|
|
132
74
|
cliConfig.auth.accessKeyId &&
|
|
133
75
|
cliConfig.auth.accessKeySecret) {
|
|
134
|
-
const loginStatus = yield validateCredentials(cliConfig.auth.accessKeyId, cliConfig.auth.accessKeySecret
|
|
76
|
+
const loginStatus = yield validateCredentials(cliConfig.auth.accessKeyId, cliConfig.auth.accessKeySecret);
|
|
135
77
|
if (loginStatus.valid) {
|
|
136
78
|
logger.warn(t('login_already').d('You are already logged in.'));
|
|
137
79
|
const selected = (yield clackSelect({
|
|
@@ -157,47 +99,6 @@ export function handleLogin(argv) {
|
|
|
157
99
|
}
|
|
158
100
|
export function interactiveLogin() {
|
|
159
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
-
const loginMethod = (yield clackSelect({
|
|
161
|
-
message: t('login_method_select').d('Choose login method'),
|
|
162
|
-
options: [
|
|
163
|
-
{
|
|
164
|
-
label: t('login_method_aksk').d('AK/SK (AccessKey ID + AccessKey Secret)'),
|
|
165
|
-
value: 'aksk'
|
|
166
|
-
},
|
|
167
|
-
{
|
|
168
|
-
label: t('login_method_sts').d('STS Token (one-shot: AccessKeyId,AccessKeySecret,SecurityToken)'),
|
|
169
|
-
value: 'sts'
|
|
170
|
-
}
|
|
171
|
-
]
|
|
172
|
-
}));
|
|
173
|
-
if (isCancel(loginMethod)) {
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (loginMethod === 'sts') {
|
|
177
|
-
const stsInput = (yield clackText({
|
|
178
|
-
message: t('login_sts_token_prompt').d('Enter STS token (AccessKeyId,AccessKeySecret,SecurityToken):')
|
|
179
|
-
}));
|
|
180
|
-
if (isCancel(stsInput))
|
|
181
|
-
return;
|
|
182
|
-
const parsed = parseStsToken(stsInput);
|
|
183
|
-
if (!parsed) {
|
|
184
|
-
logger.error(t('login_sts_token_format_invalid').d('Invalid STS token format. Use: AccessKeyId,AccessKeySecret,SecurityToken'));
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const loginStatus = yield validateCredentials(parsed.accessKeyId, parsed.accessKeySecret, parsed.securityToken);
|
|
188
|
-
if (loginStatus.valid) {
|
|
189
|
-
yield updateCliConfigFile(Object.assign({ auth: {
|
|
190
|
-
accessKeyId: parsed.accessKeyId,
|
|
191
|
-
accessKeySecret: parsed.accessKeySecret,
|
|
192
|
-
securityToken: parsed.securityToken
|
|
193
|
-
} }, (loginStatus.endpoint ? { endpoint: loginStatus.endpoint } : {})));
|
|
194
|
-
logger.success(t('login_success').d('Login success!'));
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
logger.error(loginStatus.message || 'Login failed');
|
|
198
|
-
}
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
102
|
const styledUrl = chalk.underline.blue('https://ram.console.aliyun.com/manage/ak');
|
|
202
103
|
logger.log(`🔑 ${chalk.underline(t('login_get_ak_sk').d(`Please go to the following link to get your account's AccessKey ID and AccessKey Secret`))}`);
|
|
203
104
|
logger.log(`👉 ${styledUrl}`);
|
package/dist/commands/logout.js
CHANGED
|
@@ -28,18 +28,11 @@ export function handleLogout() {
|
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
if (!cliConfig.auth) {
|
|
31
|
-
cliConfig.auth = {
|
|
32
|
-
accessKeyId: '',
|
|
33
|
-
accessKeySecret: '',
|
|
34
|
-
securityToken: ''
|
|
35
|
-
};
|
|
31
|
+
cliConfig.auth = { accessKeyId: '', accessKeySecret: '' };
|
|
36
32
|
}
|
|
37
33
|
else {
|
|
38
34
|
cliConfig.auth.accessKeyId = '';
|
|
39
35
|
cliConfig.auth.accessKeySecret = '';
|
|
40
|
-
if ('securityToken' in cliConfig.auth) {
|
|
41
|
-
cliConfig.auth.securityToken = '';
|
|
42
|
-
}
|
|
43
36
|
}
|
|
44
37
|
yield updateCliConfigFile(cliConfig);
|
|
45
38
|
logger.success(t('logout_success').d('Logout successfully'));
|
package/dist/commands/utils.js
CHANGED
|
@@ -78,27 +78,26 @@ export function validDomain(domain) {
|
|
|
78
78
|
}
|
|
79
79
|
export function checkIsLoginSuccess() {
|
|
80
80
|
return __awaiter(this, void 0, void 0, function* () {
|
|
81
|
-
var _a, _b
|
|
81
|
+
var _a, _b;
|
|
82
82
|
const cliConfig = getCliConfig();
|
|
83
83
|
let accessKeyId = process.env.ESA_ACCESS_KEY_ID || ((_a = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId);
|
|
84
84
|
let accessKeySecret = process.env.ESA_ACCESS_KEY_SECRET || ((_b = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret);
|
|
85
|
-
const securityToken = process.env.ESA_SECURITY_TOKEN || ((_c = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.auth) === null || _c === void 0 ? void 0 : _c.securityToken);
|
|
86
85
|
if (accessKeyId && accessKeySecret) {
|
|
87
|
-
const result = yield validateCredentials(accessKeyId, accessKeySecret
|
|
86
|
+
const result = yield validateCredentials(accessKeyId, accessKeySecret);
|
|
88
87
|
const server = yield ApiService.getInstance();
|
|
89
88
|
if (result.valid) {
|
|
90
|
-
const auth = {
|
|
91
|
-
accessKeyId,
|
|
92
|
-
accessKeySecret
|
|
93
|
-
};
|
|
94
|
-
if (securityToken)
|
|
95
|
-
auth.securityToken = securityToken;
|
|
96
89
|
server.updateConfig({
|
|
97
|
-
auth
|
|
90
|
+
auth: {
|
|
91
|
+
accessKeyId,
|
|
92
|
+
accessKeySecret
|
|
93
|
+
},
|
|
98
94
|
endpoint: result.endpoint
|
|
99
95
|
});
|
|
100
96
|
api.updateConfig({
|
|
101
|
-
auth
|
|
97
|
+
auth: {
|
|
98
|
+
accessKeyId,
|
|
99
|
+
accessKeySecret
|
|
100
|
+
},
|
|
102
101
|
endpoint: result.endpoint
|
|
103
102
|
});
|
|
104
103
|
return true;
|
package/dist/i18n/locales.json
CHANGED
|
@@ -1075,30 +1075,6 @@
|
|
|
1075
1075
|
"en": "AccessKey Secret (SK)",
|
|
1076
1076
|
"zh_CN": "AccessKey Secret (SK)"
|
|
1077
1077
|
},
|
|
1078
|
-
"login_option_sts_token": {
|
|
1079
|
-
"en": "STS token: AccessKeyId,AccessKeySecret,SecurityToken (comma-separated, one-shot)",
|
|
1080
|
-
"zh_CN": "STS 临时凭证:AccessKeyId,AccessKeySecret,SecurityToken(逗号分隔,一次性输入)"
|
|
1081
|
-
},
|
|
1082
|
-
"login_sts_token_prompt": {
|
|
1083
|
-
"en": "Enter STS token (AccessKeyId,AccessKeySecret,SecurityToken):",
|
|
1084
|
-
"zh_CN": "请输入 STS 凭证(AccessKeyId,AccessKeySecret,SecurityToken):"
|
|
1085
|
-
},
|
|
1086
|
-
"login_sts_token_format_invalid": {
|
|
1087
|
-
"en": "Invalid STS token format. Use: AccessKeyId,AccessKeySecret,SecurityToken",
|
|
1088
|
-
"zh_CN": "STS 凭证格式错误,请使用:AccessKeyId,AccessKeySecret,SecurityToken"
|
|
1089
|
-
},
|
|
1090
|
-
"login_method_select": {
|
|
1091
|
-
"en": "Choose login method",
|
|
1092
|
-
"zh_CN": "选择登录方式"
|
|
1093
|
-
},
|
|
1094
|
-
"login_method_aksk": {
|
|
1095
|
-
"en": "AK/SK (AccessKey ID + AccessKey Secret)",
|
|
1096
|
-
"zh_CN": "AK/SK(AccessKey ID + AccessKey Secret)"
|
|
1097
|
-
},
|
|
1098
|
-
"login_method_sts": {
|
|
1099
|
-
"en": "STS Token (one-shot: AccessKeyId,AccessKeySecret,SecurityToken)",
|
|
1100
|
-
"zh_CN": "STS 临时凭证(一次性输入:AccessKeyId,AccessKeySecret,SecurityToken)"
|
|
1101
|
-
},
|
|
1102
1078
|
"login_option_skip_login": {
|
|
1103
1079
|
"en": "Skip login",
|
|
1104
1080
|
"zh_CN": "跳过登录"
|
package/dist/libs/api.js
CHANGED
|
@@ -74,10 +74,13 @@ class Client {
|
|
|
74
74
|
this.client = Client.createClient(config);
|
|
75
75
|
}
|
|
76
76
|
static createClient(config) {
|
|
77
|
-
var _a, _b
|
|
78
|
-
const apiConfig = new $OpenApi.Config(
|
|
79
|
-
|
|
80
|
-
:
|
|
77
|
+
var _a, _b;
|
|
78
|
+
const apiConfig = new $OpenApi.Config({
|
|
79
|
+
accessKeyId: (_a = config.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
|
|
80
|
+
accessKeySecret: (_b = config.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
|
|
81
|
+
endpoint: config.endpoint,
|
|
82
|
+
userAgent: CLI_USER_AGENT
|
|
83
|
+
});
|
|
81
84
|
return new ESA.default(apiConfig);
|
|
82
85
|
}
|
|
83
86
|
updateConfig(config) {
|
package/dist/libs/apiService.js
CHANGED
|
@@ -16,10 +16,13 @@ import { CLI_USER_AGENT } from './constants.js';
|
|
|
16
16
|
import { Environment } from './interface.js';
|
|
17
17
|
export class ApiService {
|
|
18
18
|
constructor(cliConfig) {
|
|
19
|
-
var _a, _b
|
|
20
|
-
let apiConfig = new $OpenApi.Config(
|
|
21
|
-
|
|
22
|
-
:
|
|
19
|
+
var _a, _b;
|
|
20
|
+
let apiConfig = new $OpenApi.Config({
|
|
21
|
+
accessKeyId: (_a = cliConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
|
|
22
|
+
accessKeySecret: (_b = cliConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
|
|
23
|
+
endpoint: cliConfig.endpoint,
|
|
24
|
+
userAgent: CLI_USER_AGENT
|
|
25
|
+
});
|
|
23
26
|
this.client = new $OpenApi.default.default(apiConfig);
|
|
24
27
|
}
|
|
25
28
|
static getInstance() {
|
|
@@ -32,10 +35,13 @@ export class ApiService {
|
|
|
32
35
|
});
|
|
33
36
|
}
|
|
34
37
|
updateConfig(newConfig) {
|
|
35
|
-
var _a, _b
|
|
36
|
-
let apiConfig = new $OpenApi.Config(
|
|
37
|
-
|
|
38
|
-
:
|
|
38
|
+
var _a, _b;
|
|
39
|
+
let apiConfig = new $OpenApi.Config({
|
|
40
|
+
accessKeyId: (_a = newConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
|
|
41
|
+
accessKeySecret: (_b = newConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret,
|
|
42
|
+
endpoint: newConfig.endpoint,
|
|
43
|
+
userAgent: CLI_USER_AGENT
|
|
44
|
+
});
|
|
39
45
|
this.client = new $OpenApi.default.default(apiConfig);
|
|
40
46
|
}
|
|
41
47
|
/**
|
|
@@ -36,13 +36,26 @@ export function handleCheckVersion() {
|
|
|
36
36
|
*/
|
|
37
37
|
export function checkCLIVersion(currentCommand) {
|
|
38
38
|
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
if (process.env.ESA_NO_UPDATE_CHECK) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
39
42
|
try {
|
|
40
43
|
const __dirname = getDirName(import.meta.url);
|
|
41
44
|
const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
|
|
42
45
|
const jsonString = yield fs.readFile(packageJsonPath, 'utf-8');
|
|
43
46
|
const packageJson = JSON.parse(jsonString);
|
|
44
47
|
const currentVersion = packageJson.version;
|
|
45
|
-
const
|
|
48
|
+
const controller = new AbortController();
|
|
49
|
+
const fetchTimeout = setTimeout(() => controller.abort(), 5000);
|
|
50
|
+
let response;
|
|
51
|
+
try {
|
|
52
|
+
response = yield fetch('https://registry.npmjs.org/esa-cli/latest', {
|
|
53
|
+
signal: controller.signal
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
clearTimeout(fetchTimeout);
|
|
58
|
+
}
|
|
46
59
|
if (!response.ok) {
|
|
47
60
|
return true;
|
|
48
61
|
}
|
|
@@ -260,13 +260,12 @@ export function getDevOpenBrowserUrl() {
|
|
|
260
260
|
return `http://localhost:${port}`;
|
|
261
261
|
}
|
|
262
262
|
export const getApiConfig = () => {
|
|
263
|
-
var _a, _b
|
|
263
|
+
var _a, _b;
|
|
264
264
|
const [cliConfig, projectConfig] = getConfigurations();
|
|
265
265
|
let defaultConfig = {
|
|
266
266
|
auth: {
|
|
267
267
|
accessKeyId: '',
|
|
268
|
-
accessKeySecret: ''
|
|
269
|
-
securityToken: undefined
|
|
268
|
+
accessKeySecret: ''
|
|
270
269
|
},
|
|
271
270
|
endpoint: `esa.cn-hangzhou.aliyuncs.com`
|
|
272
271
|
};
|
|
@@ -274,8 +273,7 @@ export const getApiConfig = () => {
|
|
|
274
273
|
const config = {
|
|
275
274
|
auth: {
|
|
276
275
|
accessKeyId: (_a = combinedConfig.auth) === null || _a === void 0 ? void 0 : _a.accessKeyId,
|
|
277
|
-
accessKeySecret: (_b = combinedConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret
|
|
278
|
-
securityToken: (_c = combinedConfig.auth) === null || _c === void 0 ? void 0 : _c.securityToken
|
|
276
|
+
accessKeySecret: (_b = combinedConfig.auth) === null || _b === void 0 ? void 0 : _b.accessKeySecret
|
|
279
277
|
},
|
|
280
278
|
endpoint: combinedConfig.endpoint
|
|
281
279
|
};
|
|
@@ -14,14 +14,15 @@ const DOMESTIC_ENDPOINT = 'esa.cn-hangzhou.aliyuncs.com';
|
|
|
14
14
|
const INTERNATIONAL_ENDPOINT = 'esa.ap-southeast-1.aliyuncs.com';
|
|
15
15
|
/**
|
|
16
16
|
* Validate credentials for a single endpoint
|
|
17
|
-
* @param securityToken - Optional STS SecurityToken; when provided, uses STS auth
|
|
18
17
|
*/
|
|
19
|
-
function validateEndpoint(accessKeyId, accessKeySecret, endpoint
|
|
18
|
+
function validateEndpoint(accessKeyId, accessKeySecret, endpoint) {
|
|
20
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
21
20
|
try {
|
|
22
|
-
const apiConfig = new $OpenApi.Config(
|
|
21
|
+
const apiConfig = new $OpenApi.Config({
|
|
22
|
+
accessKeyId,
|
|
23
23
|
accessKeySecret,
|
|
24
|
-
endpoint
|
|
24
|
+
endpoint
|
|
25
|
+
});
|
|
25
26
|
const client = new $OpenApi.default.default(apiConfig);
|
|
26
27
|
const params = {
|
|
27
28
|
action: 'GetErService',
|
|
@@ -79,24 +80,25 @@ function validateEndpoint(accessKeyId, accessKeySecret, endpoint, securityToken)
|
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
/**
|
|
82
|
-
* Validate if AK/SK/endpoint are valid
|
|
83
|
+
* Validate if AK/SK/endpoint are valid
|
|
83
84
|
*
|
|
84
85
|
* @param accessKeyId - AccessKey ID
|
|
85
86
|
* @param accessKeySecret - AccessKey Secret
|
|
86
|
-
* @param securityToken - Optional STS SecurityToken for temporary credentials
|
|
87
87
|
* @returns Validation result, including whether valid, site type and endpoint
|
|
88
88
|
*/
|
|
89
|
-
export function validateCredentials(accessKeyId, accessKeySecret
|
|
89
|
+
export function validateCredentials(accessKeyId, accessKeySecret) {
|
|
90
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
const withToken = (ep) => validateEndpoint(accessKeyId, accessKeySecret, ep, securityToken);
|
|
92
91
|
if (process.env.CUSTOM_ENDPOINT) {
|
|
93
|
-
const result = yield
|
|
92
|
+
const result = yield validateEndpoint(accessKeyId, accessKeySecret, process.env.CUSTOM_ENDPOINT);
|
|
94
93
|
if (result.valid) {
|
|
95
94
|
return { valid: true, endpoint: process.env.CUSTOM_ENDPOINT };
|
|
96
95
|
}
|
|
97
|
-
|
|
96
|
+
else {
|
|
97
|
+
return { valid: false, message: result.message };
|
|
98
|
+
}
|
|
98
99
|
}
|
|
99
|
-
|
|
100
|
+
// First validate domestic site
|
|
101
|
+
const domesticResult = yield validateEndpoint(accessKeyId, accessKeySecret, DOMESTIC_ENDPOINT);
|
|
100
102
|
if (domesticResult.valid) {
|
|
101
103
|
return {
|
|
102
104
|
valid: true,
|
|
@@ -104,7 +106,8 @@ export function validateCredentials(accessKeyId, accessKeySecret, securityToken)
|
|
|
104
106
|
endpoint: DOMESTIC_ENDPOINT
|
|
105
107
|
};
|
|
106
108
|
}
|
|
107
|
-
|
|
109
|
+
// If domestic site validation fails, validate international site
|
|
110
|
+
const internationalResult = yield validateEndpoint(accessKeyId, accessKeySecret, INTERNATIONAL_ENDPOINT);
|
|
108
111
|
if (internationalResult.valid) {
|
|
109
112
|
return {
|
|
110
113
|
valid: true,
|
|
@@ -112,6 +115,7 @@ export function validateCredentials(accessKeyId, accessKeySecret, securityToken)
|
|
|
112
115
|
endpoint: INTERNATIONAL_ENDPOINT
|
|
113
116
|
};
|
|
114
117
|
}
|
|
118
|
+
// Both failed, return failure result
|
|
115
119
|
return {
|
|
116
120
|
valid: false,
|
|
117
121
|
message: domesticResult.message ||
|