huaweicloud-devkit 1.0.2-dev.9 → 1.0.2-next.0
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/.agents/plugins/marketplace.json +20 -20
- package/LICENSE +201 -201
- package/README.md +163 -138
- package/README.zh-CN.md +161 -138
- package/bin/setup.cjs +8 -8
- package/integrations/opencode/commands/huaweicloud-doctor.md +14 -14
- package/integrations/opencode/opencode.json +14 -14
- package/integrations/opencode/skills/huaweicloud-core/SKILL.md +32 -32
- package/package.json +46 -44
- package/plugins/huaweicloud-core/.claude-plugin/plugin.json +44 -44
- package/plugins/huaweicloud-core/.codex-plugin/plugin.json +43 -43
- package/plugins/huaweicloud-core/.cursor-plugin/plugin.json +44 -44
- package/plugins/huaweicloud-core/.mcp.json +15 -15
- package/plugins/huaweicloud-core/.workbuddy-plugin/plugin.json +44 -44
- package/plugins/huaweicloud-core/hooks/hooks.json +26 -26
- package/plugins/huaweicloud-core/hooks/huaweicloud-safety.py +136 -136
- package/plugins/huaweicloud-core/safety/policy.json +99 -99
- package/plugins/huaweicloud-core/safety/rules/cloud-risk-rules.json +199 -199
- package/plugins/huaweicloud-core/skills/huawei-apig/SKILL.md +164 -164
- package/plugins/huaweicloud-core/skills/huawei-billing/SKILL.md +48 -48
- package/plugins/huaweicloud-core/skills/huawei-cbr/SKILL.md +50 -50
- package/plugins/huaweicloud-core/skills/huawei-cce/SKILL.md +101 -101
- package/plugins/huaweicloud-core/skills/huawei-cloud-eye/SKILL.md +90 -90
- package/plugins/huaweicloud-core/skills/huawei-cloud-find-skills/SKILL.md +190 -190
- package/plugins/huaweicloud-core/skills/huawei-cloud-find-skills/scripts/search-skills.mjs +124 -124
- package/plugins/huaweicloud-core/skills/huawei-cts/SKILL.md +55 -55
- package/plugins/huaweicloud-core/skills/huawei-dds-dcs/SKILL.md +70 -70
- package/plugins/huaweicloud-core/skills/huawei-deployment/SKILL.md +56 -56
- package/plugins/huaweicloud-core/skills/huawei-dew/SKILL.md +97 -97
- package/plugins/huaweicloud-core/skills/huawei-dew/references/csms-usage.md +29 -29
- package/plugins/huaweicloud-core/skills/huawei-dew/references/kms-usage.md +23 -23
- package/plugins/huaweicloud-core/skills/huawei-ecs/SKILL.md +185 -185
- package/plugins/huaweicloud-core/skills/huawei-ecs/references/create-instance.md +133 -133
- package/plugins/huaweicloud-core/skills/huawei-ecs/references/evs.md +31 -31
- package/plugins/huaweicloud-core/skills/huawei-ecs/references/flavors.md +55 -55
- package/plugins/huaweicloud-core/skills/huawei-ecs/references/troubleshooting.md +52 -52
- package/plugins/huaweicloud-core/skills/huawei-functiongraph/SKILL.md +131 -131
- package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/apig-event-format.md +58 -58
- package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/create-function.md +71 -71
- package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/deploy-workflow.md +119 -119
- package/plugins/huaweicloud-core/skills/huawei-functiongraph/references/triggers.md +142 -142
- package/plugins/huaweicloud-core/skills/huawei-gaussdb/SKILL.md +56 -56
- package/plugins/huaweicloud-core/skills/huawei-getting-started/SKILL.md +65 -65
- package/plugins/huaweicloud-core/skills/huawei-iam/SKILL.md +111 -111
- package/plugins/huaweicloud-core/skills/huawei-iam/references/policy-examples.md +122 -122
- package/plugins/huaweicloud-core/skills/huawei-iam/references/quick-ref.md +56 -56
- package/plugins/huaweicloud-core/skills/huawei-modelarts/SKILL.md +65 -65
- package/plugins/huaweicloud-core/skills/huawei-obs/SKILL.md +133 -127
- package/plugins/huaweicloud-core/skills/huawei-obs/references/bucket-create.md +49 -49
- package/plugins/huaweicloud-core/skills/huawei-obs/references/bucket-lifecycle.md +26 -26
- package/plugins/huaweicloud-core/skills/huawei-obs/references/common-pitfalls.md +100 -100
- package/plugins/huaweicloud-core/skills/huawei-obs/references/single-file-share.md +40 -40
- package/plugins/huaweicloud-core/skills/huawei-obs/references/static-website.md +56 -56
- package/plugins/huaweicloud-core/skills/huawei-rds/SKILL.md +224 -224
- package/plugins/huaweicloud-core/skills/huawei-sandbox/SKILL.md +135 -134
- package/plugins/huaweicloud-core/skills/huawei-smn-dms/SKILL.md +69 -69
- package/plugins/huaweicloud-core/skills/huawei-vpc/SKILL.md +84 -84
- package/plugins/huaweicloud-core/skills/huawei-vpc/references/network.md +76 -76
- package/plugins/huaweicloud-core/skills/huawei-vpc/references/security-group.md +59 -59
- package/plugins/huaweicloud-core/skills/huawei-vpc/references/subnet.md +50 -50
- package/plugins/huaweicloud-core/skills/huawei-waf-aad/SKILL.md +63 -63
- package/plugins/huaweicloud-core/skills/huaweicloud-api-and-sdk/SKILL.md +56 -56
- package/plugins/huaweicloud-core/skills/huaweicloud-api-and-sdk/agents/openai.yaml +4 -4
- package/plugins/huaweicloud-core/skills/huaweicloud-capability-discovery/SKILL.md +51 -47
- package/plugins/huaweicloud-core/skills/huaweicloud-capability-discovery/agents/openai.yaml +4 -4
- package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/SKILL.md +128 -128
- package/plugins/huaweicloud-core/skills/huaweicloud-cli-and-auth/agents/openai.yaml +4 -4
- package/plugins/huaweicloud-core/skills/huaweicloud-core/SKILL.md +110 -95
- package/plugins/huaweicloud-core/skills/huaweicloud-core/agents/openai.yaml +4 -4
- package/plugins/huaweicloud-core/skills/huaweicloud-core/references/report-issue.md +19 -19
- package/plugins/huaweicloud-core/skills/huaweicloud-core/references/select.md +27 -27
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/SKILL.md +60 -60
- package/plugins/huaweicloud-core/skills/huaweicloud-safety/agents/openai.yaml +4 -4
- package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/SKILL.md +83 -83
- package/plugins/huaweicloud-core/skills/huaweicloud-troubleshooting/agents/openai.yaml +4 -4
- package/plugins/huaweicloud-core/src/auth/agent-registration.mjs +105 -87
- package/plugins/huaweicloud-core/src/auth/credentials.mjs +95 -95
- package/plugins/huaweicloud-core/src/auth/service.mjs +63 -63
- package/plugins/huaweicloud-core/src/hcloud-cli.mjs +265 -265
- package/plugins/huaweicloud-core/src/mcp-server.mjs +129 -129
- package/plugins/huaweicloud-core/src/proxy/proxy-agent.mjs +155 -0
- package/plugins/huaweicloud-core/src/proxy/proxy-config.mjs +87 -0
- package/plugins/huaweicloud-core/src/risk-rule-engine.mjs +137 -137
- package/plugins/huaweicloud-core/src/safety-policy.mjs +302 -302
- package/plugins/huaweicloud-core/src/sandbox/hdkitservice-api.mjs +91 -87
- package/plugins/huaweicloud-core/src/sandbox/hwlink-api.mjs +162 -153
- package/plugins/huaweicloud-core/src/sandbox/session-manager.mjs +112 -105
- package/plugins/huaweicloud-core/src/search-market.mjs +174 -169
- package/plugins/huaweicloud-core/src/setup-cli.mjs +2017 -1594
- package/plugins/huaweicloud-core/src/tools.mjs +1008 -993
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-exec-client.js +427 -427
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-fair-queue.js +132 -132
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-multiplexer.js +227 -227
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-packet.js +202 -202
- package/plugins/huaweicloud-core/src/ws-exec/hwlink-terminal-channel.js +158 -158
- package/plugins/huaweicloud-core/src/ws-exec/index.js +19 -19
- package/plugins/huaweicloud-core/src/ws-exec/ws-exec-client.js +338 -338
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
-
import { dirname, join } from 'node:path';
|
|
3
|
-
import { homedir } from 'node:os';
|
|
4
|
-
|
|
5
|
-
// Verify a credential file ended up with 0600. On Windows-mounted drives inside WSL
|
|
6
|
-
// (drvfs/9p) chmod is silently ignored, so the file can be world-readable (0777).
|
|
7
|
-
// Native Windows has no POSIX modes (statSync always reports 0666), so skip the check there.
|
|
8
|
-
function ensurePrivateMode(path) {
|
|
9
|
-
if (process.platform === 'win32') return;
|
|
10
|
-
try { chmodSync(path, 0o600); } catch {}
|
|
11
|
-
try {
|
|
12
|
-
const mode = statSync(path).mode & 0o777;
|
|
13
|
-
if (mode !== 0o600) {
|
|
14
|
-
console.warn(`\x1b[33m[WARN]\x1b[0m Could not set 0600 on ${path} (current mode ${mode.toString(8)}). Credentials may be readable by other users.`);
|
|
15
|
-
console.warn(`\x1b[33m If running under WSL, move the credential home to the Linux filesystem:\x1b[0m`);
|
|
16
|
-
console.warn(`\x1b[33m export HUAWEICLOUD_HOME=$HOME (then re-run auth init)\x1b[0m`);
|
|
17
|
-
console.warn(`\x1b[33m Or skip file storage entirely with HW_ACCESS_KEY/HW_SECRET_KEY environment variables.\x1b[0m`);
|
|
18
|
-
}
|
|
19
|
-
} catch {}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function baseHome() {
|
|
23
|
-
return process.env.HUAWEICLOUD_HOME || homedir();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function globalCredentialsPath() {
|
|
27
|
-
return join(baseHome(), '.config', 'huaweicloud', 'credentials.json');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export function obsConfigPath() {
|
|
31
|
-
return join(baseHome(), '.obsutilconfig');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function readGlobalCredentials() {
|
|
35
|
-
const path = globalCredentialsPath();
|
|
36
|
-
if (!existsSync(path)) return null;
|
|
37
|
-
try {
|
|
38
|
-
return JSON.parse(readFileSync(path, 'utf8'));
|
|
39
|
-
} catch {
|
|
40
|
-
return null;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function writeGlobalCredentials(credentials = {}) {
|
|
45
|
-
const path = globalCredentialsPath();
|
|
46
|
-
mkdirSync(dirname(path), { recursive: true });
|
|
47
|
-
const payload = {
|
|
48
|
-
ak: String(credentials.ak || ''),
|
|
49
|
-
sk: String(credentials.sk || ''),
|
|
50
|
-
securityToken: String(credentials.securityToken || ''),
|
|
51
|
-
region: String(credentials.region || ''),
|
|
52
|
-
};
|
|
53
|
-
writeFileSync(path, JSON.stringify(payload, null, 2), { encoding: 'utf8', mode: 0o600 });
|
|
54
|
-
ensurePrivateMode(path);
|
|
55
|
-
return path;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
export function writeObsConfig(credentials = {}) {
|
|
59
|
-
const region = String(credentials.region || '');
|
|
60
|
-
const ak = String(credentials.ak || '');
|
|
61
|
-
const sk = String(credentials.sk || '');
|
|
62
|
-
const securityToken = String(credentials.securityToken || '');
|
|
63
|
-
if (!region || !ak || !sk) {
|
|
64
|
-
throw new Error('region, ak, and sk are required to write OBS config');
|
|
65
|
-
}
|
|
66
|
-
const path = obsConfigPath();
|
|
67
|
-
const endpoint = credentials.endpoint || `https://obs.${region}.myhuaweicloud.com`;
|
|
68
|
-
// Flat key=value format (no [default] section) as written by KooCLI 7.x `hcloud OBS config`.
|
|
69
|
-
const content = `endpoint=${endpoint}\nak=${ak}\nsk=${sk}${securityToken ? `\ntoken=${securityToken}` : ''}\n`;
|
|
70
|
-
writeFileSync(path, content, { encoding: 'utf8', mode: 0o600 });
|
|
71
|
-
ensurePrivateMode(path);
|
|
72
|
-
return { path, endpoint };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export function resolveCredentials(options = {}) {
|
|
76
|
-
let ak = process.env.HW_ACCESS_KEY;
|
|
77
|
-
let sk = process.env.HW_SECRET_KEY;
|
|
78
|
-
let securityToken = process.env.HW_SECURITY_TOKEN;
|
|
79
|
-
let region = process.env.HW_REGION || process.env.HUAWEICLOUD_REGION || '';
|
|
80
|
-
|
|
81
|
-
const stored = readGlobalCredentials();
|
|
82
|
-
if (stored) {
|
|
83
|
-
if (!ak && stored.ak) ak = stored.ak;
|
|
84
|
-
if (!sk && stored.sk) sk = stored.sk;
|
|
85
|
-
if (!securityToken && stored.securityToken) securityToken = stored.securityToken;
|
|
86
|
-
if (!region && stored.region) region = stored.region;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
if (!ak || !sk) {
|
|
90
|
-
if (options.allowMissing) return null;
|
|
91
|
-
throw new Error('Huawei Cloud credentials are not configured. Run "npx huaweicloud-devkit auth init" or set HW_ACCESS_KEY/HW_SECRET_KEY.');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return { ak, sk, securityToken, region };
|
|
95
|
-
}
|
|
1
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
|
|
5
|
+
// Verify a credential file ended up with 0600. On Windows-mounted drives inside WSL
|
|
6
|
+
// (drvfs/9p) chmod is silently ignored, so the file can be world-readable (0777).
|
|
7
|
+
// Native Windows has no POSIX modes (statSync always reports 0666), so skip the check there.
|
|
8
|
+
function ensurePrivateMode(path) {
|
|
9
|
+
if (process.platform === 'win32') return;
|
|
10
|
+
try { chmodSync(path, 0o600); } catch {}
|
|
11
|
+
try {
|
|
12
|
+
const mode = statSync(path).mode & 0o777;
|
|
13
|
+
if (mode !== 0o600) {
|
|
14
|
+
console.warn(`\x1b[33m[WARN]\x1b[0m Could not set 0600 on ${path} (current mode ${mode.toString(8)}). Credentials may be readable by other users.`);
|
|
15
|
+
console.warn(`\x1b[33m If running under WSL, move the credential home to the Linux filesystem:\x1b[0m`);
|
|
16
|
+
console.warn(`\x1b[33m export HUAWEICLOUD_HOME=$HOME (then re-run auth init)\x1b[0m`);
|
|
17
|
+
console.warn(`\x1b[33m Or skip file storage entirely with HW_ACCESS_KEY/HW_SECRET_KEY environment variables.\x1b[0m`);
|
|
18
|
+
}
|
|
19
|
+
} catch {}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function baseHome() {
|
|
23
|
+
return process.env.HUAWEICLOUD_HOME || homedir();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function globalCredentialsPath() {
|
|
27
|
+
return join(baseHome(), '.config', 'huaweicloud', 'credentials.json');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function obsConfigPath() {
|
|
31
|
+
return join(baseHome(), '.obsutilconfig');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function readGlobalCredentials() {
|
|
35
|
+
const path = globalCredentialsPath();
|
|
36
|
+
if (!existsSync(path)) return null;
|
|
37
|
+
try {
|
|
38
|
+
return JSON.parse(readFileSync(path, 'utf8'));
|
|
39
|
+
} catch {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function writeGlobalCredentials(credentials = {}) {
|
|
45
|
+
const path = globalCredentialsPath();
|
|
46
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
47
|
+
const payload = {
|
|
48
|
+
ak: String(credentials.ak || ''),
|
|
49
|
+
sk: String(credentials.sk || ''),
|
|
50
|
+
securityToken: String(credentials.securityToken || ''),
|
|
51
|
+
region: String(credentials.region || ''),
|
|
52
|
+
};
|
|
53
|
+
writeFileSync(path, JSON.stringify(payload, null, 2), { encoding: 'utf8', mode: 0o600 });
|
|
54
|
+
ensurePrivateMode(path);
|
|
55
|
+
return path;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function writeObsConfig(credentials = {}) {
|
|
59
|
+
const region = String(credentials.region || '');
|
|
60
|
+
const ak = String(credentials.ak || '');
|
|
61
|
+
const sk = String(credentials.sk || '');
|
|
62
|
+
const securityToken = String(credentials.securityToken || '');
|
|
63
|
+
if (!region || !ak || !sk) {
|
|
64
|
+
throw new Error('region, ak, and sk are required to write OBS config');
|
|
65
|
+
}
|
|
66
|
+
const path = obsConfigPath();
|
|
67
|
+
const endpoint = credentials.endpoint || `https://obs.${region}.myhuaweicloud.com`;
|
|
68
|
+
// Flat key=value format (no [default] section) as written by KooCLI 7.x `hcloud OBS config`.
|
|
69
|
+
const content = `endpoint=${endpoint}\nak=${ak}\nsk=${sk}${securityToken ? `\ntoken=${securityToken}` : ''}\n`;
|
|
70
|
+
writeFileSync(path, content, { encoding: 'utf8', mode: 0o600 });
|
|
71
|
+
ensurePrivateMode(path);
|
|
72
|
+
return { path, endpoint };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function resolveCredentials(options = {}) {
|
|
76
|
+
let ak = process.env.HW_ACCESS_KEY;
|
|
77
|
+
let sk = process.env.HW_SECRET_KEY;
|
|
78
|
+
let securityToken = process.env.HW_SECURITY_TOKEN;
|
|
79
|
+
let region = process.env.HW_REGION || process.env.HUAWEICLOUD_REGION || '';
|
|
80
|
+
|
|
81
|
+
const stored = readGlobalCredentials();
|
|
82
|
+
if (stored) {
|
|
83
|
+
if (!ak && stored.ak) ak = stored.ak;
|
|
84
|
+
if (!sk && stored.sk) sk = stored.sk;
|
|
85
|
+
if (!securityToken && stored.securityToken) securityToken = stored.securityToken;
|
|
86
|
+
if (!region && stored.region) region = stored.region;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (!ak || !sk) {
|
|
90
|
+
if (options.allowMissing) return null;
|
|
91
|
+
throw new Error('Huawei Cloud credentials are not configured. Run "npx huaweicloud-devkit auth init" or set HW_ACCESS_KEY/HW_SECRET_KEY.');
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return { ak, sk, securityToken, region };
|
|
95
|
+
}
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { spawnSync } from 'node:child_process';
|
|
3
|
-
import { getAgentRegistrationStatuses } from './agent-registration.mjs';
|
|
4
|
-
import { globalCredentialsPath, obsConfigPath, readGlobalCredentials, writeObsConfig } from './credentials.mjs';
|
|
5
|
-
|
|
6
|
-
function hcloudInstalled() {
|
|
7
|
-
const bin = process.env.HCLOUD_BIN || 'hcloud';
|
|
8
|
-
try {
|
|
9
|
-
const r = spawnSync(`"${bin}" version`, [], {
|
|
10
|
-
shell: true,
|
|
11
|
-
windowsHide: true,
|
|
12
|
-
stdio: 'pipe',
|
|
13
|
-
timeout: 5000,
|
|
14
|
-
});
|
|
15
|
-
const out = `${r.stdout || ''}${r.stderr || ''}`;
|
|
16
|
-
return r.status === 0 && /KooCLI|Current.*version|当前KooCLI/i.test(out);
|
|
17
|
-
} catch {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function getAuthStatus(target = 'all') {
|
|
23
|
-
const credentials = readGlobalCredentials();
|
|
24
|
-
return {
|
|
25
|
-
target,
|
|
26
|
-
credentialsConfigured: Boolean(credentials?.ak && credentials?.sk),
|
|
27
|
-
credentialsPath: globalCredentialsPath(),
|
|
28
|
-
obsConfigured: existsSync(obsConfigPath()),
|
|
29
|
-
obsConfigPath: obsConfigPath(),
|
|
30
|
-
kooCliInstalled: hcloudInstalled(),
|
|
31
|
-
agents: getAgentRegistrationStatuses(target).agents,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function syncAuth(target = 'all') {
|
|
36
|
-
const credentials = readGlobalCredentials();
|
|
37
|
-
if (!credentials?.ak || !credentials?.sk) {
|
|
38
|
-
return {
|
|
39
|
-
ok: false,
|
|
40
|
-
error: 'Global credentials are not configured.',
|
|
41
|
-
nextStep: 'Run "npx huaweicloud-devkit auth init" first.',
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
let obs = null;
|
|
46
|
-
try {
|
|
47
|
-
obs = writeObsConfig(credentials);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
return {
|
|
50
|
-
ok: false,
|
|
51
|
-
error: error.message,
|
|
52
|
-
nextStep: 'Run "npx huaweicloud-devkit auth init" to refresh credentials and region.',
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return {
|
|
57
|
-
ok: true,
|
|
58
|
-
obs: { configured: true, path: obs.path, endpoint: obs.endpoint },
|
|
59
|
-
credentialsConfigured: true,
|
|
60
|
-
agents: getAgentRegistrationStatuses(target).agents,
|
|
61
|
-
note: 'OBS credentials were synced from the global credential vault. Agent MCP registration is managed by "npx huaweicloud-devkit install --target <agent>".',
|
|
62
|
-
};
|
|
63
|
-
}
|
|
1
|
+
import { existsSync } from 'node:fs';
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { getAgentRegistrationStatuses } from './agent-registration.mjs';
|
|
4
|
+
import { globalCredentialsPath, obsConfigPath, readGlobalCredentials, writeObsConfig } from './credentials.mjs';
|
|
5
|
+
|
|
6
|
+
function hcloudInstalled() {
|
|
7
|
+
const bin = process.env.HCLOUD_BIN || 'hcloud';
|
|
8
|
+
try {
|
|
9
|
+
const r = spawnSync(`"${bin}" version`, [], {
|
|
10
|
+
shell: true,
|
|
11
|
+
windowsHide: true,
|
|
12
|
+
stdio: 'pipe',
|
|
13
|
+
timeout: 5000,
|
|
14
|
+
});
|
|
15
|
+
const out = `${r.stdout || ''}${r.stderr || ''}`;
|
|
16
|
+
return r.status === 0 && /KooCLI|Current.*version|当前KooCLI/i.test(out);
|
|
17
|
+
} catch {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getAuthStatus(target = 'all') {
|
|
23
|
+
const credentials = readGlobalCredentials();
|
|
24
|
+
return {
|
|
25
|
+
target,
|
|
26
|
+
credentialsConfigured: Boolean(credentials?.ak && credentials?.sk),
|
|
27
|
+
credentialsPath: globalCredentialsPath(),
|
|
28
|
+
obsConfigured: existsSync(obsConfigPath()),
|
|
29
|
+
obsConfigPath: obsConfigPath(),
|
|
30
|
+
kooCliInstalled: hcloudInstalled(),
|
|
31
|
+
agents: getAgentRegistrationStatuses(target).agents,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function syncAuth(target = 'all') {
|
|
36
|
+
const credentials = readGlobalCredentials();
|
|
37
|
+
if (!credentials?.ak || !credentials?.sk) {
|
|
38
|
+
return {
|
|
39
|
+
ok: false,
|
|
40
|
+
error: 'Global credentials are not configured.',
|
|
41
|
+
nextStep: 'Run "npx huaweicloud-devkit auth init" first.',
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let obs = null;
|
|
46
|
+
try {
|
|
47
|
+
obs = writeObsConfig(credentials);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
return {
|
|
50
|
+
ok: false,
|
|
51
|
+
error: error.message,
|
|
52
|
+
nextStep: 'Run "npx huaweicloud-devkit auth init" to refresh credentials and region.',
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return {
|
|
57
|
+
ok: true,
|
|
58
|
+
obs: { configured: true, path: obs.path, endpoint: obs.endpoint },
|
|
59
|
+
credentialsConfigured: true,
|
|
60
|
+
agents: getAgentRegistrationStatuses(target).agents,
|
|
61
|
+
note: 'OBS credentials were synced from the global credential vault. Agent MCP registration is managed by "npx huaweicloud-devkit install --target <agent>".',
|
|
62
|
+
};
|
|
63
|
+
}
|