@secretenvs/cli 1.6.0 → 1.7.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/README.md +13 -13
- package/dist/index.js +124 -7
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -6,19 +6,19 @@ are bundled into the build, so the packed tarball installs on its own.
|
|
|
6
6
|
|
|
7
7
|
## Commands
|
|
8
8
|
|
|
9
|
-
| Command | What it does
|
|
10
|
-
| -------------------------------------------------------------------------------------- |
|
|
11
|
-
| `secretenvs login [--url <baseUrl>]`
|
|
12
|
-
| `secretenvs logout` | Deletes the stored credentials.
|
|
13
|
-
| `secretenvs whoami` | Shows the server, account and token prefix, and checks the token still works.
|
|
14
|
-
| `secretenvs projects` | Lists accessible projects (slug, role, name).
|
|
15
|
-
| `secretenvs envs -p <project>` | Lists the environments of a project.
|
|
16
|
-
| `secretenvs list -p <project> -e <env> [--reveal]` | Lists keys and their source (`env` / `shared`). Values are masked.
|
|
17
|
-
| `secretenvs set KEY=VALUE -p <project> -e <env>` | Creates or updates an environment variable (needs EDITOR).
|
|
18
|
-
| `secretenvs history KEY -p <project> -e <env> [--shared] [--limit]` | Lists versions: number, change, author, time. Values are never shown.
|
|
19
|
-
| `secretenvs rollback KEY --to <n> -p <project> -e <env> [--shared] [--yes]` | Restores version `n` as a **new** version (needs EDITOR). Asks to confirm.
|
|
20
|
-
| `secretenvs pull -p <project> -e <env> [--out .env] [--format dotenv\|json] [--force]` | Writes the resolved variables to a file (mode `0600`).
|
|
21
|
-
| `secretenvs run -p <project> -e <env> -- <command...>` | Runs a command with the variables injected into its environment.
|
|
9
|
+
| Command | What it does |
|
|
10
|
+
| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
11
|
+
| `secretenvs login [--url <baseUrl>] [--token]` | Prompts for email and password (hidden), plus a 2FA code if the account has it on; stores an API token. With `--token`, asks for an API token you created in the web app instead (for accounts that sign in through SIAM). |
|
|
12
|
+
| `secretenvs logout` | Deletes the stored credentials. |
|
|
13
|
+
| `secretenvs whoami` | Shows the server, account and token prefix, and checks the token still works. |
|
|
14
|
+
| `secretenvs projects` | Lists accessible projects (slug, role, name). |
|
|
15
|
+
| `secretenvs envs -p <project>` | Lists the environments of a project. |
|
|
16
|
+
| `secretenvs list -p <project> -e <env> [--reveal]` | Lists keys and their source (`env` / `shared`). Values are masked. |
|
|
17
|
+
| `secretenvs set KEY=VALUE -p <project> -e <env>` | Creates or updates an environment variable (needs EDITOR). |
|
|
18
|
+
| `secretenvs history KEY -p <project> -e <env> [--shared] [--limit]` | Lists versions: number, change, author, time. Values are never shown. |
|
|
19
|
+
| `secretenvs rollback KEY --to <n> -p <project> -e <env> [--shared] [--yes]` | Restores version `n` as a **new** version (needs EDITOR). Asks to confirm. |
|
|
20
|
+
| `secretenvs pull -p <project> -e <env> [--out .env] [--format dotenv\|json] [--force]` | Writes the resolved variables to a file (mode `0600`). |
|
|
21
|
+
| `secretenvs run -p <project> -e <env> -- <command...>` | Runs a command with the variables injected into its environment. |
|
|
22
22
|
|
|
23
23
|
Every command supports `--help`. Failures print a message to stderr and exit
|
|
24
24
|
with a non-zero code. `run` exits with the code of the command it started.
|
package/dist/index.js
CHANGED
|
@@ -46,6 +46,7 @@ var MAX_PASSWORD_LENGTH = 256;
|
|
|
46
46
|
var MAX_VERSIONS_LIMIT = 100;
|
|
47
47
|
var CSRF_HEADER_NAME = "x-requested-with";
|
|
48
48
|
var CSRF_HEADER_VALUE = "secretenvs-web";
|
|
49
|
+
var TOKEN_PREFIX = "svt_";
|
|
49
50
|
var MAX_AUTH_CODE_LENGTH = 32;
|
|
50
51
|
var ProjectRole = z.enum(["OWNER", "ADMIN", "EDITOR", "VIEWER"]);
|
|
51
52
|
var TokenAccess = z.enum(["READ", "READ_WRITE"]);
|
|
@@ -93,7 +94,18 @@ var UserDto = z2.object({
|
|
|
93
94
|
// Name the user gave the authenticator app at setup; null while 2FA is off.
|
|
94
95
|
twoFactorAppName: z2.string().nullable(),
|
|
95
96
|
// Whether the account may use the /admin pages (set directly in the database).
|
|
96
|
-
isSuperAdmin: z2.boolean()
|
|
97
|
+
isSuperAdmin: z2.boolean(),
|
|
98
|
+
// Linked to a SIAM account: name and email follow SIAM, so they are not edited here.
|
|
99
|
+
managedBySiam: z2.boolean(),
|
|
100
|
+
// Has a password of its own. Accounts created through SIAM do not, and SIAM handles their
|
|
101
|
+
// password and two-factor authentication.
|
|
102
|
+
hasPassword: z2.boolean()
|
|
103
|
+
}).strict();
|
|
104
|
+
var AuthOptionsDto = z2.object({
|
|
105
|
+
// Sign-in through SIAM is configured on this server.
|
|
106
|
+
siam: z2.boolean(),
|
|
107
|
+
// Where people manage their SIAM account; null when it is not configured or SIAM is off.
|
|
108
|
+
profileUrl: z2.string().nullable()
|
|
97
109
|
}).strict();
|
|
98
110
|
var TwoFactorSetupDto = z2.object({ secret: z2.string(), otpauthUri: z2.string() }).strict();
|
|
99
111
|
var TwoFactorSetupInput = z2.object({ password: z2.string().min(1).max(MAX_PASSWORD_LENGTH) }).strict();
|
|
@@ -258,6 +270,8 @@ var AdminUserDto = z2.object({
|
|
|
258
270
|
// Null while the account is enabled.
|
|
259
271
|
disabledAt: isoDate.nullable(),
|
|
260
272
|
isSuperAdmin: z2.boolean(),
|
|
273
|
+
// Linked to a SIAM account: its name and email belong to SIAM and cannot be edited here.
|
|
274
|
+
managedBySiam: z2.boolean(),
|
|
261
275
|
projectCount: z2.number().int().min(0)
|
|
262
276
|
}).strict();
|
|
263
277
|
var AdminUserDetailDto = AdminUserDto.extend({
|
|
@@ -324,10 +338,46 @@ var apiEnvironmentSchema = z3.object({
|
|
|
324
338
|
TRUST_PROXY: z3.coerce.number().int().min(0).max(10).default(0),
|
|
325
339
|
// Shared secret for the daily expiry-reminder call (see docs/DEPLOYMENT.md). Unset turns
|
|
326
340
|
// that endpoint off.
|
|
327
|
-
CRON_SECRET: z3.string().min(32).max(256).optional()
|
|
328
|
-
|
|
341
|
+
CRON_SECRET: z3.string().min(32).max(256).optional(),
|
|
342
|
+
// Sign-in through SIAM (https://siam.ankityadav.net.in/docs). The four IAM_* values go
|
|
343
|
+
// together: leave them all unset to keep SIAM sign-in off.
|
|
344
|
+
IAM_BASE_URL: z3.url().optional(),
|
|
345
|
+
IAM_CLIENT_ID: z3.string().min(1).max(256).optional(),
|
|
346
|
+
IAM_CLIENT_SECRET: z3.string().min(1).max(512).optional(),
|
|
347
|
+
IAM_REDIRECT_URI: z3.url().optional(),
|
|
348
|
+
// The page where people manage their SIAM account (name, email, password, two-factor). The
|
|
349
|
+
// account page links to it. Optional: without it the page just says to use SIAM.
|
|
350
|
+
IAM_PROFILE_URL: z3.url().refine(
|
|
351
|
+
(value) => ["http:", "https:"].includes(new URL(value).protocol),
|
|
352
|
+
"Expected an HTTP(S) URL"
|
|
353
|
+
).optional(),
|
|
354
|
+
// A SIAM permission the user must hold to get in (e.g. `secretenvs.access`). Unset: any
|
|
355
|
+
// active SIAM account may sign in. A SIAM superadmin always may.
|
|
356
|
+
IAM_REQUIRED_PERMISSION: z3.string().min(1).max(128).optional(),
|
|
357
|
+
// Link a SIAM sign-in to an existing local account with the same email. Off by default,
|
|
358
|
+
// because it is only safe when SIAM verifies that people own the email they sign up with.
|
|
359
|
+
IAM_LINK_BY_EMAIL: z3.enum(["true", "false"]).optional()
|
|
360
|
+
}).strict().superRefine((environment, context) => {
|
|
361
|
+
const names = [
|
|
362
|
+
"IAM_BASE_URL",
|
|
363
|
+
"IAM_CLIENT_ID",
|
|
364
|
+
"IAM_CLIENT_SECRET",
|
|
365
|
+
"IAM_REDIRECT_URI"
|
|
366
|
+
];
|
|
367
|
+
const missing = names.filter((name2) => environment[name2] === void 0);
|
|
368
|
+
if (missing.length > 0 && missing.length < names.length) {
|
|
369
|
+
for (const name2 of missing) {
|
|
370
|
+
context.addIssue({
|
|
371
|
+
code: "custom",
|
|
372
|
+
path: [name2],
|
|
373
|
+
message: "Required when any other IAM_* value is set"
|
|
374
|
+
});
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}).transform((environment) => ({
|
|
329
378
|
...environment,
|
|
330
|
-
COOKIE_SECURE: environment.COOKIE_SECURE === void 0 ? environment.NODE_ENV === "production" : environment.COOKIE_SECURE === "true"
|
|
379
|
+
COOKIE_SECURE: environment.COOKIE_SECURE === void 0 ? environment.NODE_ENV === "production" : environment.COOKIE_SECURE === "true",
|
|
380
|
+
IAM_LINK_BY_EMAIL: environment.IAM_LINK_BY_EMAIL === "true"
|
|
331
381
|
}));
|
|
332
382
|
|
|
333
383
|
// ../sdk/dist/index.js
|
|
@@ -654,6 +704,19 @@ async function send(fetchFn, baseUrl, request, parse) {
|
|
|
654
704
|
if (status === 404) throw new SecretEnvsNotFoundError(message, status, code);
|
|
655
705
|
throw new SecretEnvsApiError(message, status, code);
|
|
656
706
|
}
|
|
707
|
+
async function siamOffered(options) {
|
|
708
|
+
try {
|
|
709
|
+
const result = await send(
|
|
710
|
+
options.fetch,
|
|
711
|
+
options.baseUrl,
|
|
712
|
+
{ method: "GET", path: "/api/v1/auth/options" },
|
|
713
|
+
(body) => AuthOptionsDto.parse(body)
|
|
714
|
+
);
|
|
715
|
+
return result.siam;
|
|
716
|
+
} catch {
|
|
717
|
+
return false;
|
|
718
|
+
}
|
|
719
|
+
}
|
|
657
720
|
function cliLogin(options) {
|
|
658
721
|
return send(
|
|
659
722
|
options.fetch,
|
|
@@ -995,6 +1058,41 @@ var out = (deps, text) => {
|
|
|
995
1058
|
deps.stdout.write(`${text}
|
|
996
1059
|
`);
|
|
997
1060
|
};
|
|
1061
|
+
var MAX_TOKEN_LENGTH = 256;
|
|
1062
|
+
async function loginWithToken(deps, baseUrl) {
|
|
1063
|
+
out(
|
|
1064
|
+
deps,
|
|
1065
|
+
"Create an API token with read and write access in the web app (Settings > API tokens), then paste it here."
|
|
1066
|
+
);
|
|
1067
|
+
const token = (await deps.prompts.password({ message: "API token" })).trim();
|
|
1068
|
+
if (!token.startsWith(TOKEN_PREFIX) || token.length > MAX_TOKEN_LENGTH) {
|
|
1069
|
+
throw new CliError(
|
|
1070
|
+
`That does not look like a SecretEnvs API token (they start with ${TOKEN_PREFIX}).`
|
|
1071
|
+
);
|
|
1072
|
+
}
|
|
1073
|
+
const sdk = new SecretEnvs({ token, baseUrl, fetch: deps.fetch, env: {} });
|
|
1074
|
+
let projects;
|
|
1075
|
+
try {
|
|
1076
|
+
projects = await sdk.listProjects();
|
|
1077
|
+
} catch (error) {
|
|
1078
|
+
if (error instanceof SecretEnvsAuthError) {
|
|
1079
|
+
throw new CliError(
|
|
1080
|
+
"The server did not accept that token. Check that you copied all of it, and that it has not expired or been revoked."
|
|
1081
|
+
);
|
|
1082
|
+
}
|
|
1083
|
+
throw error;
|
|
1084
|
+
}
|
|
1085
|
+
const prefix = token.slice(0, 8);
|
|
1086
|
+
await writeCredentials(credentialsPath(deps.homeDir), {
|
|
1087
|
+
baseUrl,
|
|
1088
|
+
token,
|
|
1089
|
+
prefix
|
|
1090
|
+
});
|
|
1091
|
+
out(
|
|
1092
|
+
deps,
|
|
1093
|
+
`Logged in with API token ${prefix}... on ${baseUrl} (${projects.length} accessible ${projects.length === 1 ? "project" : "projects"})`
|
|
1094
|
+
);
|
|
1095
|
+
}
|
|
998
1096
|
async function login(deps, options) {
|
|
999
1097
|
if (!deps.interactive) {
|
|
1000
1098
|
throw new CliError("`secretenvs login` needs an interactive terminal.");
|
|
@@ -1013,6 +1111,15 @@ async function login(deps, options) {
|
|
|
1013
1111
|
error instanceof SecretEnvsError ? error.message : "Invalid server URL"
|
|
1014
1112
|
);
|
|
1015
1113
|
}
|
|
1114
|
+
let useToken = options.token === true;
|
|
1115
|
+
const siam = useToken ? false : await siamOffered({ fetch: deps.fetch, baseUrl });
|
|
1116
|
+
if (siam) {
|
|
1117
|
+
useToken = await deps.prompts.confirm({
|
|
1118
|
+
message: "This server signs people in through SIAM. Log in with an API token instead of email and password? (Needed for SIAM accounts)",
|
|
1119
|
+
default: false
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
if (useToken) return loginWithToken(deps, baseUrl);
|
|
1016
1123
|
const email2 = (await deps.prompts.input({ message: "Email" })).trim();
|
|
1017
1124
|
const password3 = await deps.prompts.password({ message: "Password" });
|
|
1018
1125
|
const attempt = (code) => cliLogin({
|
|
@@ -1032,7 +1139,10 @@ async function login(deps, options) {
|
|
|
1032
1139
|
throw error;
|
|
1033
1140
|
}).catch((error) => {
|
|
1034
1141
|
if (error instanceof SecretEnvsAuthError) {
|
|
1035
|
-
throw new CliError(
|
|
1142
|
+
throw new CliError(
|
|
1143
|
+
siam ? `${error.message}
|
|
1144
|
+
If you sign in to SecretEnvs through SIAM, run \`secretenvs login --token\` instead.` : error.message
|
|
1145
|
+
);
|
|
1036
1146
|
}
|
|
1037
1147
|
throw error;
|
|
1038
1148
|
});
|
|
@@ -1327,14 +1437,21 @@ async function runCommand(deps, command, flags) {
|
|
|
1327
1437
|
}
|
|
1328
1438
|
|
|
1329
1439
|
// src/program.ts
|
|
1330
|
-
var VERSION = true ? "1.
|
|
1440
|
+
var VERSION = true ? "1.7.0" : "dev";
|
|
1331
1441
|
function buildProgram(deps, setExitCode) {
|
|
1332
1442
|
const program = new Command().name("secretenvs").description("Read and manage SecretEnvs variables from the terminal").version(VERSION).configureOutput({
|
|
1333
1443
|
writeOut: (text) => deps.stdout.write(text),
|
|
1334
1444
|
writeErr: (text) => deps.stderr.write(text)
|
|
1335
1445
|
}).exitOverride();
|
|
1336
1446
|
const target = (command) => command.option("-p, --project <slug>", "project slug (or SECRETENVS_PROJECT)").option("-e, --env <slug>", "environment slug (or SECRETENVS_ENV)");
|
|
1337
|
-
program.command("login").description(
|
|
1447
|
+
program.command("login").description(
|
|
1448
|
+
"Log in with email and password, or with an API token, and store it"
|
|
1449
|
+
).option("--url <baseUrl>", "server URL, e.g. https://vault.example.com").option(
|
|
1450
|
+
"--token",
|
|
1451
|
+
"paste an API token created in the web app (for accounts that sign in through SIAM)"
|
|
1452
|
+
).action(
|
|
1453
|
+
(options) => login(deps, options)
|
|
1454
|
+
);
|
|
1338
1455
|
program.command("logout").description("Delete the stored credentials").action(() => logout(deps));
|
|
1339
1456
|
program.command("whoami").description("Show the current server, account and token").action(() => whoami(deps));
|
|
1340
1457
|
program.command("projects").description("List accessible projects").action(() => listProjects(deps));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@secretenvs/cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Command-line client for reading and managing SecretEnvs variables.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/ankityadavpurson/secretenvs#readme",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"zod": "^4.1.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@secretenvs/contracts": "1.
|
|
48
|
-
"@secretenvs/sdk": "1.
|
|
47
|
+
"@secretenvs/contracts": "1.7.0",
|
|
48
|
+
"@secretenvs/sdk": "1.7.0",
|
|
49
49
|
"@types/cross-spawn": "^6.0.6",
|
|
50
50
|
"tsup": "^8.5.0",
|
|
51
51
|
"typescript": "~5.9.3",
|