feat: release 2.7.1
This commit is contained in:
+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