feat: release 2.7.1
This commit is contained in:
+37
-8
@@ -67,6 +67,7 @@ export function createLoginPrompt(
|
||||
});
|
||||
class KuberBasicAuth extends Auth {
|
||||
private submitting = false;
|
||||
private cancelling = false;
|
||||
|
||||
override async initialize() {
|
||||
await super.initialize();
|
||||
@@ -84,6 +85,33 @@ export function createLoginPrompt(
|
||||
await super.submit();
|
||||
}
|
||||
|
||||
override async cancel() {
|
||||
// Bun may close readline while processing Ctrl+C before Enquirer emits
|
||||
// cancel. Enquirer's close handler must therefore run only once.
|
||||
if (this.cancelling || this.state.closed) return;
|
||||
this.cancelling = true;
|
||||
const stop = (this as unknown as { stop?: () => void }).stop;
|
||||
if (stop) {
|
||||
(
|
||||
this as unknown as {
|
||||
removeListener(event: string, listener: () => void): void;
|
||||
}
|
||||
).removeListener("close", stop);
|
||||
try {
|
||||
// Bun's readline may already be closed by Ctrl+C. Enquirer's stop
|
||||
// restores raw mode and removes its keypress handler before calling
|
||||
// pause/close, which would otherwise throw ERR_USE_AFTER_CLOSE.
|
||||
stop();
|
||||
} catch (error) {
|
||||
// The terminal cleanup above has run; Bun can report
|
||||
// ERR_USE_AFTER_CLOSE because readline was closed by Ctrl+C.
|
||||
if ((error as { code?: string }).code !== "ERR_USE_AFTER_CLOSE")
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
await super.cancel();
|
||||
}
|
||||
|
||||
override async render() {
|
||||
if (this.state.submitted) {
|
||||
// FormPrompt skips choice.format on submission and cancellation.
|
||||
@@ -100,8 +128,9 @@ export function createLoginPrompt(
|
||||
let session: LoginResponse;
|
||||
try {
|
||||
session = await super.run();
|
||||
} catch {
|
||||
throw new Error("Login cancelled");
|
||||
} catch (error) {
|
||||
if (this.state.cancelled) throw new Error("Login cancelled");
|
||||
throw error;
|
||||
}
|
||||
if (failure !== undefined) throw failure;
|
||||
return session;
|
||||
@@ -136,7 +165,7 @@ export async function loginUser(
|
||||
/** Share the CLI's credential prompt with onboarding without exposing passwords. */
|
||||
export async function interactiveLogin(
|
||||
username = "",
|
||||
persistent = false,
|
||||
persistent: boolean | undefined = true,
|
||||
dependencies: {
|
||||
isTTY?: boolean;
|
||||
prompt?: typeof createLoginPrompt;
|
||||
@@ -148,7 +177,7 @@ export async function interactiveLogin(
|
||||
);
|
||||
const session = await (dependencies.prompt ?? createLoginPrompt)(
|
||||
username.trim(),
|
||||
persistent,
|
||||
persistent ?? true,
|
||||
).run();
|
||||
console.log(`Logged in as ${session.user.username}`);
|
||||
return session;
|
||||
@@ -157,16 +186,16 @@ export async function interactiveLogin(
|
||||
export const login = defineCommand({
|
||||
meta: {
|
||||
name: "login",
|
||||
description: "Log in to kuber.astrxl.dev",
|
||||
description: "Log in to the cluster",
|
||||
},
|
||||
args: {
|
||||
persist: {
|
||||
session: {
|
||||
type: "boolean",
|
||||
description: "Keep the login across reboots",
|
||||
description: "Use a temporary session for this runtime",
|
||||
},
|
||||
},
|
||||
async run({ args }) {
|
||||
await interactiveLogin(String(args._[0] ?? ""), Boolean(args.persist));
|
||||
await interactiveLogin(String(args._[0] ?? ""), !Boolean(args.session));
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
+5
-7
@@ -30,12 +30,12 @@ export function getDatabaseCredentials(
|
||||
const list = defineCommand({
|
||||
meta: {
|
||||
name: "ls",
|
||||
description: "List managed postgres claims",
|
||||
description: "List database volumes used by this project",
|
||||
},
|
||||
async run() {
|
||||
const claims = getComposePostgresClaims(await ctx().compose());
|
||||
if (claims.length === 0) {
|
||||
console.log("No managed postgres volumes declared");
|
||||
console.log("No database volumes declared");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ const list = defineCommand({
|
||||
const creds = defineCommand({
|
||||
meta: {
|
||||
name: "creds",
|
||||
description: "Print postgres credentials for a service",
|
||||
description: "Print database credentials for a service",
|
||||
},
|
||||
async run({ args }) {
|
||||
const service = args._[0];
|
||||
@@ -66,9 +66,7 @@ const creds = defineCommand({
|
||||
(entry) => entry.service === service,
|
||||
);
|
||||
if (!claim) {
|
||||
throw new Error(
|
||||
`Service ${service} does not declare a managed postgres volume.`,
|
||||
);
|
||||
throw new Error(`Service ${service} does not declare a database volume.`);
|
||||
}
|
||||
|
||||
const credentials = await getDatabaseCredentials(context.project, claim);
|
||||
@@ -93,7 +91,7 @@ const creds = defineCommand({
|
||||
export const db = defineCommand({
|
||||
meta: {
|
||||
name: "db",
|
||||
description: "Inspect managed postgres databases",
|
||||
description: "View project databases and credentials",
|
||||
},
|
||||
subCommands: {
|
||||
creds,
|
||||
|
||||
+28
-11
@@ -3,6 +3,7 @@ import { wrapCommandErrors } from "../lib/error";
|
||||
|
||||
function lazyCommand<T extends object>(
|
||||
load: () => Promise<T>,
|
||||
options: { hidden?: boolean } = {},
|
||||
): () => Promise<T> {
|
||||
let pending: Promise<T> | undefined;
|
||||
return () =>
|
||||
@@ -11,6 +12,12 @@ function lazyCommand<T extends object>(
|
||||
// Keep the exported command objects pristine: tests and callers may
|
||||
// import them directly while the CLI needs wrapped handlers.
|
||||
const cliCommand = cloneCommand(command);
|
||||
if (options.hidden) {
|
||||
const definition = cliCommand as T & {
|
||||
meta?: Record<string, unknown>;
|
||||
};
|
||||
definition.meta = { ...definition.meta, hidden: true };
|
||||
}
|
||||
wrapCommandErrors(cliCommand);
|
||||
return cliCommand;
|
||||
})
|
||||
@@ -37,8 +44,8 @@ function cloneCommand<T extends object>(command: T): T {
|
||||
export const main = defineCommand({
|
||||
meta: {
|
||||
name: "kuber",
|
||||
version: "2.7.0",
|
||||
description: "Docker Compose -> K8s translation layer",
|
||||
version: "2.7.1",
|
||||
description: "Deploy and manage projects on Kubernetes",
|
||||
},
|
||||
args: {
|
||||
config: {
|
||||
@@ -48,21 +55,27 @@ export const main = defineCommand({
|
||||
},
|
||||
subCommands: {
|
||||
add: lazyCommand(() => import("./add").then((m) => m.add)),
|
||||
audit: lazyCommand(() => import("./audit").then((m) => m.audit)),
|
||||
ci: lazyCommand(() => import("./ci").then((m) => m.ci)),
|
||||
audit: lazyCommand(() => import("./audit").then((m) => m.audit), {
|
||||
hidden: true,
|
||||
}),
|
||||
ci: lazyCommand(() => import("./ci").then((m) => m.ci), { hidden: true }),
|
||||
db: lazyCommand(() => import("./db").then((m) => m.db)),
|
||||
down: lazyCommand(() => import("./down").then((m) => m.down)),
|
||||
export: lazyCommand(() => import("./export").then((m) => m.exportCommand)),
|
||||
exec: lazyCommand(() => import("./exec").then((m) => m.exec)),
|
||||
init: lazyCommand(() => import("./init").then((m) => m.init)),
|
||||
logs: lazyCommand(() => import("./logs").then((m) => m.logs)),
|
||||
maintenance: lazyCommand(() =>
|
||||
import("./maintenance").then((m) => m.maintenance),
|
||||
maintenance: lazyCommand(
|
||||
() => import("./maintenance").then((m) => m.maintenance),
|
||||
{ hidden: true },
|
||||
),
|
||||
login: lazyCommand(() => import("./auth").then((m) => m.login)),
|
||||
logout: lazyCommand(() => import("./auth").then((m) => m.logout)),
|
||||
operations: lazyCommand(() =>
|
||||
import("./operations").then((m) => m.operations),
|
||||
logout: lazyCommand(() => import("./auth").then((m) => m.logout), {
|
||||
hidden: true,
|
||||
}),
|
||||
operations: lazyCommand(
|
||||
() => import("./operations").then((m) => m.operations),
|
||||
{ hidden: true },
|
||||
),
|
||||
ps: lazyCommand(() => import("./ps").then((m) => m.ps)),
|
||||
restart: lazyCommand(() => import("./restart").then((m) => m.restart)),
|
||||
@@ -71,9 +84,13 @@ export const main = defineCommand({
|
||||
start: lazyCommand(() => import("./start").then((m) => m.start)),
|
||||
stop: lazyCommand(() => import("./stop").then((m) => m.stop)),
|
||||
up: lazyCommand(() => import("./up").then((m) => m.up)),
|
||||
users: lazyCommand(() => import("./users").then((m) => m.users)),
|
||||
users: lazyCommand(() => import("./users").then((m) => m.users), {
|
||||
hidden: true,
|
||||
}),
|
||||
trust: lazyCommand(() => import("./trust").then((m) => m.trust)),
|
||||
whoami: lazyCommand(() => import("./auth").then((m) => m.whoami)),
|
||||
whoami: lazyCommand(() => import("./auth").then((m) => m.whoami), {
|
||||
hidden: true,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ export async function runMaintenance(
|
||||
export const maintenance = defineCommand({
|
||||
meta: {
|
||||
name: "maintenance",
|
||||
description: "Toggle a global hostname maintenance override",
|
||||
description: "Toggle maintenance page on hostnames",
|
||||
},
|
||||
args: {
|
||||
host: { type: "positional", required: true, description: "DNS hostname" },
|
||||
|
||||
+2
-2
@@ -26,12 +26,12 @@ export function runRestart(
|
||||
export const restart = defineCommand({
|
||||
meta: {
|
||||
name: "restart",
|
||||
description: "Roll out a restart for managed deployments",
|
||||
description: "Restart deployments",
|
||||
},
|
||||
args: {
|
||||
deployment: {
|
||||
type: "positional",
|
||||
description: "Deployment name to restart (defaults to all managed)",
|
||||
description: "Deployment name to restart (defaults to all deployments)",
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ export const rollback = defineCommand({
|
||||
args: {
|
||||
deployment: {
|
||||
type: "positional",
|
||||
description: "Deployment name to roll back (defaults to all managed)",
|
||||
description: "Deployment name to roll back (defaults to all deployments)",
|
||||
required: false,
|
||||
},
|
||||
},
|
||||
|
||||
+8
-6
@@ -31,7 +31,9 @@ async function getServiceClaim(service: string): Promise<S3Claim> {
|
||||
(entry) => entry.service === service,
|
||||
);
|
||||
if (!claim) {
|
||||
throw new Error(`Service ${service} does not declare a managed S3 volume.`);
|
||||
throw new Error(
|
||||
`Service ${service} does not declare an object storage volume.`,
|
||||
);
|
||||
}
|
||||
return claim;
|
||||
}
|
||||
@@ -39,12 +41,12 @@ async function getServiceClaim(service: string): Promise<S3Claim> {
|
||||
const list = defineCommand({
|
||||
meta: {
|
||||
name: "ls",
|
||||
description: "List managed S3 claims",
|
||||
description: "List object storage volumes used by this project",
|
||||
},
|
||||
async run() {
|
||||
const claims = getComposeS3Claims(await ctx().compose());
|
||||
if (claims.length === 0) {
|
||||
console.log("No managed S3 volumes declared");
|
||||
console.log("No object storage volumes declared");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -63,7 +65,7 @@ const list = defineCommand({
|
||||
const creds = defineCommand({
|
||||
meta: {
|
||||
name: "creds",
|
||||
description: "Print S3 environment variables for a service",
|
||||
description: "Print object storage environment variables for a service",
|
||||
},
|
||||
async run({ args }) {
|
||||
const service = args._[0];
|
||||
@@ -82,7 +84,7 @@ const creds = defineCommand({
|
||||
const ui = defineCommand({
|
||||
meta: {
|
||||
name: "ui",
|
||||
description: "Print the Garage UI URL for a service bucket",
|
||||
description: "Print the object storage browser URL for a service bucket",
|
||||
},
|
||||
async run({ args }) {
|
||||
const service = args._[0];
|
||||
@@ -95,7 +97,7 @@ const ui = defineCommand({
|
||||
export const s3 = defineCommand({
|
||||
meta: {
|
||||
name: "s3",
|
||||
description: "Inspect managed S3 storage",
|
||||
description: "View project object storage settings",
|
||||
},
|
||||
subCommands: {
|
||||
creds,
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ export function runStop(
|
||||
export const stop = defineCommand({
|
||||
meta: {
|
||||
name: "stop",
|
||||
description: "Scale managed deployments to zero",
|
||||
description: "Stop all deployments",
|
||||
},
|
||||
async run() {
|
||||
await new Listr([
|
||||
|
||||
+9
-5
@@ -668,7 +668,11 @@ function resourceOperationTaskTitle(
|
||||
resource: ResourceOperationTarget,
|
||||
): string {
|
||||
const action =
|
||||
phase === "apply" ? "Apply" : phase === "wait" ? "Wait for" : "Delete";
|
||||
phase === "apply"
|
||||
? "Applying"
|
||||
: phase === "wait"
|
||||
? "Waiting for"
|
||||
: "Deleting";
|
||||
return `${action} ${resource.kind}/${resource.name}`;
|
||||
}
|
||||
|
||||
@@ -980,13 +984,13 @@ export async function runUp(
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Reconcile backing services",
|
||||
title: "Set up backing services",
|
||||
rendererOptions: { bottomBar: 1, persistentOutput: true },
|
||||
task: (taskCtx, task) =>
|
||||
task.newListr(
|
||||
[
|
||||
{
|
||||
title: "Reconcile databases",
|
||||
title: "Set up databases",
|
||||
enabled: () =>
|
||||
getComposePostgresClaims(taskCtx.compose!).length > 0,
|
||||
task: async (_ctx, child) => {
|
||||
@@ -1008,7 +1012,7 @@ export async function runUp(
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Reconcile S3 storage",
|
||||
title: "Set up object storage",
|
||||
enabled: () => getComposeS3Claims(taskCtx.compose!).length > 0,
|
||||
task: async (_ctx, child) => {
|
||||
let response: Record<string, unknown>;
|
||||
@@ -1054,7 +1058,7 @@ export async function runUp(
|
||||
},
|
||||
},
|
||||
{
|
||||
title: "Reconcile resources",
|
||||
title: "Apply resources",
|
||||
task: async (taskCtx, task) => {
|
||||
taskCtx.plan = await planResources(
|
||||
project,
|
||||
|
||||
+34
-11
@@ -342,7 +342,8 @@ const keys = defineCommand({
|
||||
ls: defineCommand({
|
||||
meta: {
|
||||
name: "ls",
|
||||
description: "List all API keys (optional positional username filters the results)",
|
||||
description:
|
||||
"List all API keys (optional positional username filters the results)",
|
||||
},
|
||||
async run({ args }) {
|
||||
console.log(await listApiKeys(args._[0]));
|
||||
@@ -352,7 +353,7 @@ const keys = defineCommand({
|
||||
meta: {
|
||||
name: "create",
|
||||
description:
|
||||
"Create an API key for a user (e.g. kuber users keys create alice --capabilities kubernetes:read --expires-days none)",
|
||||
"Create an API key (e.g. kuber users keys create --capabilities kubernetes:write --workspace kuber-server --expireDays=none dmgnr; or kuber users keys create -w kuber-server -e none dmgnr kubernetes:write,kubernetes:read)",
|
||||
},
|
||||
args: {
|
||||
username: {
|
||||
@@ -362,25 +363,47 @@ const keys = defineCommand({
|
||||
},
|
||||
capabilities: {
|
||||
type: "string",
|
||||
required: true,
|
||||
alias: "c",
|
||||
description:
|
||||
"Comma-separated capabilities, e.g. kubernetes:read,kubernetes:write (also kubernetes:exec, users:read, users:write, sessions:revoke, platform:adopt)",
|
||||
"Comma-separated capabilities via --capabilities, or as the second positional argument; e.g. kubernetes:read,kubernetes:write (also kubernetes:exec, users:read, users:write, sessions:revoke, platform:adopt)",
|
||||
position: 1,
|
||||
},
|
||||
workspace: {
|
||||
type: "string",
|
||||
alias: "w",
|
||||
description: "Restrict the key to a workspace",
|
||||
},
|
||||
"expires-days": {
|
||||
type: "string",
|
||||
default: "90",
|
||||
description: "Expiry in days (1-365), or none for a non-expiring key",
|
||||
alias: "e",
|
||||
description:
|
||||
"Expiry in days (1-365), or none for a non-expiring key (also --expireDays)",
|
||||
},
|
||||
expireDays: {
|
||||
type: "string",
|
||||
description: "Alias for --expires-days",
|
||||
},
|
||||
},
|
||||
async run({ args }) {
|
||||
const days =
|
||||
args["expires-days"] === "none"
|
||||
? undefined
|
||||
: Number(args["expires-days"]);
|
||||
if (args.expireDays !== undefined && args["expires-days"] !== undefined)
|
||||
throw new Error(
|
||||
"Provide only one of --expires-days and --expireDays",
|
||||
);
|
||||
const expiry = args.expireDays ?? args["expires-days"] ?? "90";
|
||||
const positionalCapabilities = args._?.[1];
|
||||
if (
|
||||
args.capabilities !== undefined &&
|
||||
positionalCapabilities !== undefined
|
||||
)
|
||||
throw new Error(
|
||||
"Provide capabilities either with --capabilities or as the second positional argument, not both",
|
||||
);
|
||||
const capabilities = args.capabilities ?? positionalCapabilities;
|
||||
if (typeof capabilities !== "string" || !capabilities.trim())
|
||||
throw new Error(
|
||||
"Provide capabilities with --capabilities or as the second positional argument",
|
||||
);
|
||||
const days = expiry === "none" ? undefined : Number(expiry);
|
||||
if (
|
||||
days !== undefined &&
|
||||
(!Number.isSafeInteger(days) || days < 1 || days > 365)
|
||||
@@ -389,7 +412,7 @@ const keys = defineCommand({
|
||||
"--expires-days must be an integer from 1 to 365, or none",
|
||||
);
|
||||
const key = await createApiKey(requireUsername(args.username), {
|
||||
capabilities: parseCapabilities(args.capabilities),
|
||||
capabilities: parseCapabilities(capabilities),
|
||||
...(args.workspace && { workspace: args.workspace }),
|
||||
...(days !== undefined && {
|
||||
expiresAt: new Date(
|
||||
|
||||
Reference in New Issue
Block a user