@sixb/cli 0.1.5 → 0.1.7
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/README.md +125 -18
- package/dist/commands/init.d.ts +0 -1
- package/dist/commands/init.d.ts.map +1 -1
- package/dist/commands/login.d.ts +8 -0
- package/dist/commands/login.d.ts.map +1 -0
- package/dist/commands/logout.d.ts +6 -0
- package/dist/commands/logout.d.ts.map +1 -0
- package/dist/commands/profile.d.ts +7 -0
- package/dist/commands/profile.d.ts.map +1 -0
- package/dist/commands/service-account.d.ts +1 -0
- package/dist/commands/service-account.d.ts.map +1 -1
- package/dist/commands/status.d.ts +8 -0
- package/dist/commands/status.d.ts.map +1 -0
- package/dist/commands/token.d.ts +1 -0
- package/dist/commands/token.d.ts.map +1 -1
- package/dist/lib/api-client.d.ts +0 -11
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/command-line.d.ts +176 -0
- package/dist/lib/command-line.d.ts.map +1 -0
- package/dist/lib/errors.d.ts +6 -0
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/instance-command.d.ts +3 -0
- package/dist/lib/instance-command.d.ts.map +1 -0
- package/dist/lib/loadSixb.d.ts.map +1 -1
- package/dist/lib/profile-api-client.d.ts +6 -0
- package/dist/lib/profile-api-client.d.ts.map +1 -0
- package/dist/lib/profiles.d.ts +34 -0
- package/dist/lib/profiles.d.ts.map +1 -0
- package/dist/lib/runtime.d.ts.map +1 -1
- package/dist/lib/worker-registry.d.ts.map +1 -1
- package/dist/ui/index.d.ts +5 -5
- package/dist/ui/index.d.ts.map +1 -1
- package/package.json +15 -14
- package/src/commands/init.tsx +1 -13
- package/src/commands/login.tsx +196 -0
- package/src/commands/logout.tsx +36 -0
- package/src/commands/profile.tsx +101 -0
- package/src/commands/service-account.tsx +18 -15
- package/src/commands/status.tsx +93 -0
- package/src/commands/token.tsx +11 -8
- package/src/index.tsx +134 -156
- package/src/lib/api-client.ts +4 -65
- package/src/lib/command-line.ts +743 -0
- package/src/lib/errors.ts +13 -0
- package/src/lib/instance-command.ts +80 -0
- package/src/lib/loadSixb.ts +0 -2
- package/src/lib/profile-api-client.ts +38 -0
- package/src/lib/profiles.ts +262 -0
- package/src/lib/runtime.ts +7 -1
- package/src/lib/worker-registry.ts +7 -1
- package/src/ui/index.tsx +39 -140
- package/dist/commands/auth.d.ts +0 -8
- package/dist/commands/auth.d.ts.map +0 -1
- package/src/commands/auth.tsx +0 -96
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
|
+
import { type CliHelp } from "../lib/command-line";
|
|
2
3
|
export declare function renderStatic(view: React.ReactNode): Promise<void>;
|
|
3
4
|
export declare function renderPersistent(view: React.ReactNode): import("ink").Instance;
|
|
4
5
|
/**
|
|
@@ -43,6 +44,10 @@ export declare function LoadingView({ title, subtitle, status, }: {
|
|
|
43
44
|
export declare function HelpView({ errorMessage }: {
|
|
44
45
|
errorMessage?: string;
|
|
45
46
|
}): import("react/jsx-runtime").JSX.Element;
|
|
47
|
+
export declare function CommandHelpView({ help, errorMessage }: {
|
|
48
|
+
help: CliHelp;
|
|
49
|
+
errorMessage?: string;
|
|
50
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
46
51
|
export declare function VersionView({ version }: {
|
|
47
52
|
version: string;
|
|
48
53
|
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -152,11 +157,6 @@ export declare function LakeCleanupView({ projectId, report, }: {
|
|
|
152
157
|
projectId: string;
|
|
153
158
|
report: LakeCleanupReport;
|
|
154
159
|
}): import("react/jsx-runtime").JSX.Element;
|
|
155
|
-
export declare function CreateView({ name, targetDir, commands, }: {
|
|
156
|
-
name: string;
|
|
157
|
-
targetDir: string;
|
|
158
|
-
commands: readonly string[];
|
|
159
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
160
160
|
export declare function InitView({ name, targetDir, files, commands, }: {
|
|
161
161
|
name: string;
|
|
162
162
|
targetDir: string;
|
package/dist/ui/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAgB,KAAK,OAAO,EAAa,MAAM,qBAAqB,CAAA;AAK3E,wBAAsB,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,iBAOvD;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,SAAS,0BAErD;AAED;;;GAGG;AACH,wBAAsB,cAAc,CAClC,KAAK,EAAE,OAAO,EACd,OAAO,GAAE;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CAAO,GAC9E,OAAO,CAAC,IAAI,CAAC,CASf;AAmBD,MAAM,MAAM,YAAY,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAsF3D,wBAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,QAAQ,EACR,KAAK,EACL,UAAoB,EACpB,OAAO,GACR,EAAE;IACD,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,SAAS,YAAY,EAAE,CAAA;IAC9B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,2CAiBA;AAED,wBAAgB,eAAe,CAAC,EAC9B,KAAK,EACL,QAAQ,EACR,OAAO,EACP,IAAI,EACJ,YAAY,GACb,EAAE;IACD,KAAK,EAA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AK,EACL,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,EAAE,CAAA;IACf,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;CAC5B,2CAgBA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Command-line interface for Sixb projects",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -29,19 +29,20 @@
|
|
|
29
29
|
"prepack": "bun run build"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@sixb/action-worker": "0.1.
|
|
33
|
-
"@sixb/agent-worker": "0.1.
|
|
34
|
-
"@sixb/app": "^0.1.
|
|
35
|
-
"@sixb/atlas": "^0.1.
|
|
36
|
-
"@sixb/client": "^0.1.
|
|
37
|
-
"@sixb/core": "0.1.
|
|
38
|
-
"@sixb/
|
|
39
|
-
"@sixb/
|
|
40
|
-
"@sixb/
|
|
41
|
-
"@sixb/
|
|
42
|
-
"@sixb/
|
|
43
|
-
"@sixb/
|
|
44
|
-
"@sixb/
|
|
32
|
+
"@sixb/action-worker": "0.1.7",
|
|
33
|
+
"@sixb/agent-worker": "0.1.7",
|
|
34
|
+
"@sixb/app": "^0.1.5",
|
|
35
|
+
"@sixb/atlas": "^0.1.6",
|
|
36
|
+
"@sixb/client": "^0.1.7",
|
|
37
|
+
"@sixb/core": "0.1.7",
|
|
38
|
+
"@sixb/cli-core": "^0.1.4",
|
|
39
|
+
"@sixb/orchestrator": "0.1.7",
|
|
40
|
+
"@sixb/pipeline-worker": "0.1.7",
|
|
41
|
+
"@sixb/projection-worker": "0.1.7",
|
|
42
|
+
"@sixb/rules-worker": "0.1.7",
|
|
43
|
+
"@sixb/server": "0.1.7",
|
|
44
|
+
"@sixb/sync-worker": "0.1.7",
|
|
45
|
+
"@sixb/workflow-worker": "0.1.7",
|
|
45
46
|
"create-sixb": "^0.1.2",
|
|
46
47
|
"ink": "^6.0.0",
|
|
47
48
|
"react": "^19.0.0",
|
package/src/commands/init.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { relative, sep } from "node:path"
|
|
2
2
|
import { scaffoldProject } from "create-sixb/scaffold"
|
|
3
|
-
import {
|
|
3
|
+
import { InitView, renderStatic } from "../ui"
|
|
4
4
|
|
|
5
5
|
export async function runInit(dir?: string): Promise<void> {
|
|
6
6
|
const result = await scaffoldProject(dir ?? ".", { allowExisting: true })
|
|
@@ -15,18 +15,6 @@ export async function runInit(dir?: string): Promise<void> {
|
|
|
15
15
|
)
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export async function runCreate(name: string): Promise<void> {
|
|
19
|
-
const result = await scaffoldProject(name)
|
|
20
|
-
|
|
21
|
-
await renderStatic(
|
|
22
|
-
<CreateView
|
|
23
|
-
name={result.name}
|
|
24
|
-
targetDir={result.targetDir}
|
|
25
|
-
commands={nextStepsFor(result.targetDir)}
|
|
26
|
-
/>
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
18
|
function nextStepsFor(targetDir: string): string[] {
|
|
31
19
|
const target = relative(process.cwd(), targetDir)
|
|
32
20
|
const commands: string[] = []
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { CliError, createInstanceApiClient, writeJson } from "@sixb/cli-core"
|
|
2
|
+
import { normalizeApiUrl } from "../lib/api-client"
|
|
3
|
+
import { assertProfileName, updateConfig } from "../lib/profiles"
|
|
4
|
+
import { KeyValueResultView, renderStatic } from "../ui"
|
|
5
|
+
|
|
6
|
+
export interface LoginCommandOptions {
|
|
7
|
+
readonly apiUrl?: string
|
|
8
|
+
readonly profile?: string
|
|
9
|
+
readonly tokenStdin?: boolean
|
|
10
|
+
readonly json?: boolean
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export async function runLogin(options: LoginCommandOptions = {}): Promise<void> {
|
|
14
|
+
if (!options.apiUrl?.trim()) {
|
|
15
|
+
throw new Error("Usage: sixb login <api-url> [--profile <name>] [--token-stdin]")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const apiUrl = normalizeApiUrl(options.apiUrl)
|
|
19
|
+
let token: string | undefined
|
|
20
|
+
let projectId: string
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
projectId = await fetchProject(apiUrl)
|
|
24
|
+
} catch (error) {
|
|
25
|
+
if (!isAuthorizationError(error)) throw error
|
|
26
|
+
token = options.tokenStdin
|
|
27
|
+
? await readTokenFromStdin()
|
|
28
|
+
: await authorizeDevice(apiUrl, options.profile?.trim() || "sixb CLI")
|
|
29
|
+
projectId = await fetchProject(apiUrl, token)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const profile = options.profile?.trim() || projectId
|
|
33
|
+
assertProfileName(profile)
|
|
34
|
+
await updateConfig((config) => ({
|
|
35
|
+
version: 1,
|
|
36
|
+
currentProfile: profile,
|
|
37
|
+
profiles: {
|
|
38
|
+
...config.profiles,
|
|
39
|
+
[profile]: { apiUrl, projectId, ...(token ? { token } : {}) },
|
|
40
|
+
},
|
|
41
|
+
}))
|
|
42
|
+
|
|
43
|
+
const result = { profile, projectId, apiUrl, authenticated: Boolean(token) }
|
|
44
|
+
if (options.json) {
|
|
45
|
+
writeJson(result)
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
await renderStatic(
|
|
50
|
+
<KeyValueResultView
|
|
51
|
+
title={`Logged in with profile "${profile}"`}
|
|
52
|
+
items={[
|
|
53
|
+
{ label: "Project", value: projectId },
|
|
54
|
+
{ label: "API", value: apiUrl },
|
|
55
|
+
{ label: "Authentication", value: token ? "stored token" : "not required" },
|
|
56
|
+
]}
|
|
57
|
+
/>
|
|
58
|
+
)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
interface DeviceAuthorizationStart {
|
|
62
|
+
readonly deviceCode: string
|
|
63
|
+
readonly userCode: string
|
|
64
|
+
readonly verificationUriComplete: string
|
|
65
|
+
readonly expiresAt: string
|
|
66
|
+
readonly interval: number
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function authorizeDevice(apiUrl: string, tokenName: string): Promise<string> {
|
|
70
|
+
const api = createInstanceApiClient({ kind: "local", baseUrl: apiUrl })
|
|
71
|
+
const start = parseDeviceAuthorizationStart(
|
|
72
|
+
await api.post("/api/auth/device-authorizations", {
|
|
73
|
+
clientName: "sixb CLI",
|
|
74
|
+
tokenName,
|
|
75
|
+
expiresIn: "90d",
|
|
76
|
+
}),
|
|
77
|
+
apiUrl
|
|
78
|
+
)
|
|
79
|
+
process.stderr.write(`Opening ${start.verificationUriComplete}\n`)
|
|
80
|
+
process.stderr.write(`Confirm code: ${start.userCode}\n`)
|
|
81
|
+
await openBrowser(start.verificationUriComplete)
|
|
82
|
+
process.stderr.write("Waiting for browser authorization...\n")
|
|
83
|
+
|
|
84
|
+
const serverDeadline = new Date(start.expiresAt).getTime()
|
|
85
|
+
const deadline = Math.min(serverDeadline, Date.now() + 15 * 60 * 1000)
|
|
86
|
+
const intervalMs = Math.max(1, Math.min(10, start.interval)) * 1000
|
|
87
|
+
while (Date.now() < deadline) {
|
|
88
|
+
const result = await api.post("/api/auth/device-authorizations/token", {
|
|
89
|
+
deviceCode: start.deviceCode,
|
|
90
|
+
})
|
|
91
|
+
if (!isRecord(result) || typeof result.status !== "string") {
|
|
92
|
+
throw new Error("[SixbCLI] The Sixb API returned an invalid device authorization response.")
|
|
93
|
+
}
|
|
94
|
+
if (result.status === "approved" && typeof result.accessToken === "string") {
|
|
95
|
+
return requireToken(result.accessToken)
|
|
96
|
+
}
|
|
97
|
+
if (result.status === "denied") {
|
|
98
|
+
throw new Error("[SixbCLI] Browser authorization was denied.")
|
|
99
|
+
}
|
|
100
|
+
if (result.status === "expired") {
|
|
101
|
+
throw new Error("[SixbCLI] Browser authorization expired. Run `sixb login` again.")
|
|
102
|
+
}
|
|
103
|
+
if (result.status !== "pending") {
|
|
104
|
+
throw new Error("[SixbCLI] The Sixb API returned an unknown authorization status.")
|
|
105
|
+
}
|
|
106
|
+
await Bun.sleep(intervalMs)
|
|
107
|
+
}
|
|
108
|
+
throw new Error("[SixbCLI] Browser authorization expired. Run `sixb login` again.")
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function parseDeviceAuthorizationStart(value: unknown, apiUrl: string): DeviceAuthorizationStart {
|
|
112
|
+
if (
|
|
113
|
+
!isRecord(value) ||
|
|
114
|
+
typeof value.deviceCode !== "string" ||
|
|
115
|
+
!value.deviceCode ||
|
|
116
|
+
value.deviceCode.length > 1_024 ||
|
|
117
|
+
typeof value.userCode !== "string" ||
|
|
118
|
+
!value.userCode ||
|
|
119
|
+
typeof value.verificationUriComplete !== "string" ||
|
|
120
|
+
typeof value.expiresAt !== "string" ||
|
|
121
|
+
typeof value.interval !== "number" ||
|
|
122
|
+
!Number.isFinite(value.interval) ||
|
|
123
|
+
!Number.isFinite(new Date(value.expiresAt).getTime())
|
|
124
|
+
) {
|
|
125
|
+
throw new Error("[SixbCLI] The Sixb API returned an invalid device authorization.")
|
|
126
|
+
}
|
|
127
|
+
const verificationUrl = new URL(value.verificationUriComplete)
|
|
128
|
+
if (
|
|
129
|
+
verificationUrl.origin !== new URL(apiUrl).origin ||
|
|
130
|
+
(verificationUrl.protocol !== "http:" && verificationUrl.protocol !== "https:")
|
|
131
|
+
) {
|
|
132
|
+
throw new Error("[SixbCLI] The device verification URL does not match the Sixb API origin.")
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
deviceCode: value.deviceCode,
|
|
136
|
+
userCode: value.userCode,
|
|
137
|
+
verificationUriComplete: value.verificationUriComplete,
|
|
138
|
+
expiresAt: value.expiresAt,
|
|
139
|
+
interval: value.interval,
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async function openBrowser(url: string): Promise<void> {
|
|
144
|
+
if (process.env.SIXB_CLI_NO_BROWSER === "1") return
|
|
145
|
+
const command =
|
|
146
|
+
process.platform === "darwin"
|
|
147
|
+
? ["open", url]
|
|
148
|
+
: process.platform === "win32"
|
|
149
|
+
? ["cmd.exe", "/c", "start", "", url]
|
|
150
|
+
: ["xdg-open", url]
|
|
151
|
+
try {
|
|
152
|
+
const process = Bun.spawn({ cmd: command, stdout: "ignore", stderr: "ignore" })
|
|
153
|
+
await process.exited
|
|
154
|
+
} catch {
|
|
155
|
+
// The URL and confirmation code were printed, so manual completion remains available.
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
async function fetchProject(apiUrl: string, token?: string): Promise<string> {
|
|
160
|
+
const api = createInstanceApiClient({
|
|
161
|
+
kind: "local",
|
|
162
|
+
baseUrl: apiUrl,
|
|
163
|
+
...(token ? { token } : {}),
|
|
164
|
+
})
|
|
165
|
+
const result = await api.get("/api/project")
|
|
166
|
+
if (!isRecord(result) || typeof result.id !== "string" || !result.id.trim()) {
|
|
167
|
+
throw new Error("[SixbCLI] The Sixb API returned project metadata without a project id.")
|
|
168
|
+
}
|
|
169
|
+
return result.id.trim()
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function isAuthorizationError(error: unknown): boolean {
|
|
173
|
+
return error instanceof CliError && (error.body.status === 401 || error.body.status === 403)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
async function readTokenFromStdin(): Promise<string> {
|
|
177
|
+
let value = ""
|
|
178
|
+
for await (const chunk of process.stdin) {
|
|
179
|
+
value += chunk.toString()
|
|
180
|
+
if (value.length > 16_384) {
|
|
181
|
+
throw new Error("[SixbCLI] The token read from stdin is too large.")
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return requireToken(value)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function requireToken(value: string): string {
|
|
188
|
+
const token = value.trim()
|
|
189
|
+
if (!token) throw new Error("[SixbCLI] API token cannot be empty.")
|
|
190
|
+
if (/\s/.test(token)) throw new Error("[SixbCLI] API token cannot contain whitespace.")
|
|
191
|
+
return token
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
195
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
196
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { writeJson } from "@sixb/cli-core"
|
|
2
|
+
import { readConfig, requireProfile, updateConfig } from "../lib/profiles"
|
|
3
|
+
import { KeyValueResultView, renderStatic } from "../ui"
|
|
4
|
+
|
|
5
|
+
export interface LogoutCommandOptions {
|
|
6
|
+
readonly profile?: string
|
|
7
|
+
readonly json?: boolean
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export async function runLogout(options: LogoutCommandOptions = {}): Promise<void> {
|
|
11
|
+
const current = await readConfig()
|
|
12
|
+
const name = options.profile?.trim() || current.currentProfile
|
|
13
|
+
if (!name) throw new Error("[SixbCLI] No current profile to remove.")
|
|
14
|
+
requireProfile(current, name)
|
|
15
|
+
|
|
16
|
+
await updateConfig((config) => {
|
|
17
|
+
const profiles = { ...config.profiles }
|
|
18
|
+
delete profiles[name]
|
|
19
|
+
return {
|
|
20
|
+
version: 1,
|
|
21
|
+
...(config.currentProfile !== name ? { currentProfile: config.currentProfile } : {}),
|
|
22
|
+
profiles,
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
if (options.json) {
|
|
27
|
+
writeJson({ removedProfile: name })
|
|
28
|
+
return
|
|
29
|
+
}
|
|
30
|
+
await renderStatic(
|
|
31
|
+
<KeyValueResultView
|
|
32
|
+
title={`Removed profile "${name}"`}
|
|
33
|
+
items={[{ label: "Profile", value: name }]}
|
|
34
|
+
/>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { writeJson } from "@sixb/cli-core"
|
|
2
|
+
import { readConfig, requireProfile, updateConfig } from "../lib/profiles"
|
|
3
|
+
import { KeyValueResultView, renderStatic, TableResultView } from "../ui"
|
|
4
|
+
|
|
5
|
+
export interface ProfileCommandOptions {
|
|
6
|
+
readonly action?: string
|
|
7
|
+
readonly name?: string
|
|
8
|
+
readonly json?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export async function runProfile(options: ProfileCommandOptions = {}): Promise<void> {
|
|
12
|
+
const action = options.action
|
|
13
|
+
if (action === "list") return listProfiles(options)
|
|
14
|
+
if (action === "show") return showProfile(options)
|
|
15
|
+
if (action === "use") return selectProfile(options)
|
|
16
|
+
throw new Error("Usage: sixb profile <list|show|use> [name]")
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function listProfiles(options: ProfileCommandOptions): Promise<void> {
|
|
20
|
+
const config = await readConfig()
|
|
21
|
+
const profiles = Object.entries(config.profiles)
|
|
22
|
+
.sort(([left], [right]) => left.localeCompare(right))
|
|
23
|
+
.map(([name, profile]) => ({
|
|
24
|
+
name,
|
|
25
|
+
current: name === config.currentProfile,
|
|
26
|
+
projectId: profile.projectId,
|
|
27
|
+
apiUrl: profile.apiUrl,
|
|
28
|
+
authenticated: Boolean(profile.token),
|
|
29
|
+
}))
|
|
30
|
+
|
|
31
|
+
if (options.json) {
|
|
32
|
+
writeJson({ currentProfile: config.currentProfile ?? null, profiles })
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
await renderStatic(
|
|
37
|
+
<TableResultView
|
|
38
|
+
title="Sixb profiles"
|
|
39
|
+
headers={["Current", "Profile", "Project", "API", "Token"]}
|
|
40
|
+
rows={profiles.map((profile) => [
|
|
41
|
+
profile.current ? "*" : "",
|
|
42
|
+
profile.name,
|
|
43
|
+
profile.projectId,
|
|
44
|
+
profile.apiUrl,
|
|
45
|
+
profile.authenticated ? "yes" : "no",
|
|
46
|
+
])}
|
|
47
|
+
emptyMessage="No profiles. Run `sixb login <api-url>`."
|
|
48
|
+
/>
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function showProfile(options: ProfileCommandOptions): Promise<void> {
|
|
53
|
+
const config = await readConfig()
|
|
54
|
+
const name = options.name?.trim() || config.currentProfile
|
|
55
|
+
if (!name) throw new Error("[SixbCLI] No current profile. Run `sixb login <api-url>`.")
|
|
56
|
+
const profile = requireProfile(config, name)
|
|
57
|
+
const result = {
|
|
58
|
+
name,
|
|
59
|
+
current: name === config.currentProfile,
|
|
60
|
+
projectId: profile.projectId,
|
|
61
|
+
apiUrl: profile.apiUrl,
|
|
62
|
+
authenticated: Boolean(profile.token),
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (options.json) {
|
|
66
|
+
writeJson(result)
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
await renderStatic(
|
|
71
|
+
<KeyValueResultView
|
|
72
|
+
title={`Profile "${name}"`}
|
|
73
|
+
items={[
|
|
74
|
+
{ label: "Current", value: result.current ? "yes" : "no" },
|
|
75
|
+
{ label: "Project", value: result.projectId },
|
|
76
|
+
{ label: "API", value: result.apiUrl },
|
|
77
|
+
{ label: "Stored token", value: result.authenticated ? "yes" : "no" },
|
|
78
|
+
]}
|
|
79
|
+
/>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async function selectProfile(options: ProfileCommandOptions): Promise<void> {
|
|
84
|
+
const name = options.name?.trim()
|
|
85
|
+
if (!name) throw new Error("Usage: sixb profile use <name>")
|
|
86
|
+
await updateConfig((config) => {
|
|
87
|
+
requireProfile(config, name)
|
|
88
|
+
return { ...config, currentProfile: name }
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
if (options.json) {
|
|
92
|
+
writeJson({ currentProfile: name })
|
|
93
|
+
return
|
|
94
|
+
}
|
|
95
|
+
await renderStatic(
|
|
96
|
+
<KeyValueResultView
|
|
97
|
+
title={`Using profile "${name}"`}
|
|
98
|
+
items={[{ label: "Profile", value: name }]}
|
|
99
|
+
/>
|
|
100
|
+
)
|
|
101
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { writeJson } from "@sixb/cli-core"
|
|
1
2
|
import {
|
|
2
3
|
createAuthServiceAccount,
|
|
3
4
|
createAuthServiceAccountAccessToken,
|
|
@@ -7,7 +8,8 @@ import {
|
|
|
7
8
|
listAuthServiceAccounts,
|
|
8
9
|
revokeAuthServiceAccountAccessToken,
|
|
9
10
|
} from "@sixb/client"
|
|
10
|
-
import { createCliSixbClient,
|
|
11
|
+
import { createCliSixbClient, unwrapSixbApiResult } from "../lib/api-client"
|
|
12
|
+
import { resolveProfileApiClientConfig } from "../lib/profile-api-client"
|
|
11
13
|
import { KeyValueResultView, renderStatic, SecretResultView, TableResultView } from "../ui"
|
|
12
14
|
import {
|
|
13
15
|
formatDate,
|
|
@@ -22,6 +24,7 @@ export interface ServiceAccountCommandOptions {
|
|
|
22
24
|
readonly positionals?: readonly string[]
|
|
23
25
|
readonly apiUrl?: string
|
|
24
26
|
readonly token?: string
|
|
27
|
+
readonly profile?: string
|
|
25
28
|
readonly id?: string
|
|
26
29
|
readonly name?: string
|
|
27
30
|
readonly description?: string
|
|
@@ -32,7 +35,7 @@ export interface ServiceAccountCommandOptions {
|
|
|
32
35
|
}
|
|
33
36
|
|
|
34
37
|
export async function runServiceAccount(options: ServiceAccountCommandOptions = {}) {
|
|
35
|
-
const command = options.positionals?.[0]
|
|
38
|
+
const command = options.positionals?.[0]
|
|
36
39
|
if (command === "token") {
|
|
37
40
|
await runServiceAccountToken(options)
|
|
38
41
|
return
|
|
@@ -57,11 +60,11 @@ export async function runServiceAccount(options: ServiceAccountCommandOptions =
|
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
async function listServiceAccounts(options: ServiceAccountCommandOptions) {
|
|
60
|
-
const client = createCliSixbClient(
|
|
63
|
+
const client = createCliSixbClient(await resolveProfileApiClientConfig(options))
|
|
61
64
|
const result = unwrapSixbApiResult(await listAuthServiceAccounts({ client }))
|
|
62
65
|
|
|
63
66
|
if (options.json) {
|
|
64
|
-
|
|
67
|
+
writeJson(result)
|
|
65
68
|
return
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -85,7 +88,7 @@ async function createServiceAccount(options: ServiceAccountCommandOptions) {
|
|
|
85
88
|
const id = options.id?.trim()
|
|
86
89
|
const description = options.description?.trim()
|
|
87
90
|
const groupIds = normalizeGroupIds(options.groupIds)
|
|
88
|
-
const client = createCliSixbClient(
|
|
91
|
+
const client = createCliSixbClient(await resolveProfileApiClientConfig(options))
|
|
89
92
|
const result = unwrapSixbApiResult(
|
|
90
93
|
await createAuthServiceAccount({
|
|
91
94
|
client,
|
|
@@ -99,7 +102,7 @@ async function createServiceAccount(options: ServiceAccountCommandOptions) {
|
|
|
99
102
|
)
|
|
100
103
|
|
|
101
104
|
if (options.json) {
|
|
102
|
-
|
|
105
|
+
writeJson(result)
|
|
103
106
|
return
|
|
104
107
|
}
|
|
105
108
|
|
|
@@ -122,7 +125,7 @@ async function disableServiceAccount(options: ServiceAccountCommandOptions) {
|
|
|
122
125
|
throw new Error("Usage: sixb service-account disable <service-account-id>")
|
|
123
126
|
}
|
|
124
127
|
|
|
125
|
-
const client = createCliSixbClient(
|
|
128
|
+
const client = createCliSixbClient(await resolveProfileApiClientConfig(options))
|
|
126
129
|
const result = unwrapSixbApiResult(
|
|
127
130
|
await disableAuthServiceAccount({
|
|
128
131
|
client,
|
|
@@ -131,7 +134,7 @@ async function disableServiceAccount(options: ServiceAccountCommandOptions) {
|
|
|
131
134
|
)
|
|
132
135
|
|
|
133
136
|
if (options.json) {
|
|
134
|
-
|
|
137
|
+
writeJson(result)
|
|
135
138
|
return
|
|
136
139
|
}
|
|
137
140
|
|
|
@@ -148,7 +151,7 @@ async function disableServiceAccount(options: ServiceAccountCommandOptions) {
|
|
|
148
151
|
}
|
|
149
152
|
|
|
150
153
|
async function runServiceAccountToken(options: ServiceAccountCommandOptions) {
|
|
151
|
-
const action = options.positionals?.[1]
|
|
154
|
+
const action = options.positionals?.[1]
|
|
152
155
|
if (action === "list") {
|
|
153
156
|
await listServiceAccountTokens(options)
|
|
154
157
|
return
|
|
@@ -172,7 +175,7 @@ async function listServiceAccountTokens(options: ServiceAccountCommandOptions) {
|
|
|
172
175
|
options,
|
|
173
176
|
"Usage: sixb service-account token list <service-account-id>"
|
|
174
177
|
)
|
|
175
|
-
const client = createCliSixbClient(
|
|
178
|
+
const client = createCliSixbClient(await resolveProfileApiClientConfig(options))
|
|
176
179
|
const result = unwrapSixbApiResult(
|
|
177
180
|
await listAuthServiceAccountAccessTokens({
|
|
178
181
|
client,
|
|
@@ -181,7 +184,7 @@ async function listServiceAccountTokens(options: ServiceAccountCommandOptions) {
|
|
|
181
184
|
)
|
|
182
185
|
|
|
183
186
|
if (options.json) {
|
|
184
|
-
|
|
187
|
+
writeJson(result)
|
|
185
188
|
return
|
|
186
189
|
}
|
|
187
190
|
|
|
@@ -215,7 +218,7 @@ async function createServiceAccountToken(options: ServiceAccountCommandOptions)
|
|
|
215
218
|
|
|
216
219
|
const expiresAt = resolveExpiration(options)
|
|
217
220
|
const groupIds = normalizeGroupIds(options.groupIds)
|
|
218
|
-
const client = createCliSixbClient(
|
|
221
|
+
const client = createCliSixbClient(await resolveProfileApiClientConfig(options))
|
|
219
222
|
const result = unwrapSixbApiResult(
|
|
220
223
|
await createAuthServiceAccountAccessToken({
|
|
221
224
|
client,
|
|
@@ -229,7 +232,7 @@ async function createServiceAccountToken(options: ServiceAccountCommandOptions)
|
|
|
229
232
|
)
|
|
230
233
|
|
|
231
234
|
if (options.json) {
|
|
232
|
-
|
|
235
|
+
writeJson(result)
|
|
233
236
|
return
|
|
234
237
|
}
|
|
235
238
|
|
|
@@ -258,7 +261,7 @@ async function revokeServiceAccountToken(options: ServiceAccountCommandOptions)
|
|
|
258
261
|
throw new Error("Usage: sixb service-account token revoke <service-account-id> <token-id>")
|
|
259
262
|
}
|
|
260
263
|
|
|
261
|
-
const client = createCliSixbClient(
|
|
264
|
+
const client = createCliSixbClient(await resolveProfileApiClientConfig(options))
|
|
262
265
|
const result = unwrapSixbApiResult(
|
|
263
266
|
await revokeAuthServiceAccountAccessToken({
|
|
264
267
|
client,
|
|
@@ -267,7 +270,7 @@ async function revokeServiceAccountToken(options: ServiceAccountCommandOptions)
|
|
|
267
270
|
)
|
|
268
271
|
|
|
269
272
|
if (options.json) {
|
|
270
|
-
|
|
273
|
+
writeJson(result)
|
|
271
274
|
return
|
|
272
275
|
}
|
|
273
276
|
|