@theholocron/holocron-plugin-1password 5.0.0-alpha.54 → 5.0.0-alpha.541
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 +15 -13
- package/dist/index.d.mts +108 -42
- package/dist/index.mjs +413 -50
- package/package.json +26 -23
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
<!-- alex disable fire -->
|
|
2
|
+
|
|
1
3
|
<!-- editorconfig-checker-disable-file -->
|
|
2
4
|
|
|
3
5
|
# `@theholocron/holocron-plugin-1password`
|
|
@@ -5,7 +7,7 @@
|
|
|
5
7
|
1Password plugin for [Holocron](../cli). Implements the `vault`
|
|
6
8
|
capability via shell-out to the `op` CLI
|
|
7
9
|
(<https://developer.1password.com/docs/cli>). Also exports
|
|
8
|
-
`verifyToken` + `AUTH_HINT` for use by `holocron
|
|
10
|
+
`verifyToken` + `AUTH_HINT` for use by `holocron check token`.
|
|
9
11
|
|
|
10
12
|
## One of several vault providers
|
|
11
13
|
|
|
@@ -15,7 +17,7 @@ so you can swap by editing one config line. Peer plugins:
|
|
|
15
17
|
|
|
16
18
|
- **[`@theholocron/holocron-plugin-doppler`](../holocron-plugin-doppler)**
|
|
17
19
|
— REST-transport, Doppler-CLI-managed auth via the OS keychain
|
|
18
|
-
(`doppler login` → `holocron
|
|
20
|
+
(`doppler login` → `holocron new token doppler …`). This repo's
|
|
19
21
|
own default since `2.0.0-alpha.4`.
|
|
20
22
|
- **`@theholocron/holocron-plugin-infisical`** — planned (see [#97](https://github.com/theholocron/holocron/issues/97)),
|
|
21
23
|
will use the same REST + keyring shape.
|
|
@@ -89,12 +91,12 @@ found.
|
|
|
89
91
|
|
|
90
92
|
This plugin does NOT store a bearer token — the `op` CLI manages
|
|
91
93
|
its own auth via the 1Password desktop app (biometric unlock on
|
|
92
|
-
laptops) or `OP_SERVICE_ACCOUNT_TOKEN` on CI. `holocron
|
|
94
|
+
laptops) or `OP_SERVICE_ACCOUNT_TOKEN` on CI. `holocron new token
|
|
93
95
|
1password` will accept a token, but since the plugin doesn't read
|
|
94
96
|
the keyring, storing one has no runtime effect. The `AUTH_HINT`
|
|
95
|
-
export makes this explicit in `holocron
|
|
97
|
+
export makes this explicit in `holocron check token` output.
|
|
96
98
|
|
|
97
|
-
`holocron
|
|
99
|
+
`holocron check token 1password` runs `op whoami --format=json` to
|
|
98
100
|
confirm you're signed in — a useful validation independent of
|
|
99
101
|
holocron.
|
|
100
102
|
|
|
@@ -116,7 +118,7 @@ holocron.
|
|
|
116
118
|
|
|
117
119
|
```
|
|
118
120
|
|
|
119
|
-
- `vault` (
|
|
121
|
+
- `vault` (optional) — the 1Password vault name items live in. `list()` needs it, or an `environment` (see below) (`read` and `write` take the vault from the `op://` reference), and Environments are not in a vault, so a project that only reads an Environment can leave it out.
|
|
120
122
|
- `account` (optional) — 1P account UUID. Passes `--account <UUID>`
|
|
121
123
|
on every `op` call so the integration targets a specific account
|
|
122
124
|
even when the developer has multiple signed in (e.g., work +
|
|
@@ -124,13 +126,13 @@ holocron.
|
|
|
124
126
|
|
|
125
127
|
## What's implemented
|
|
126
128
|
|
|
127
|
-
| Method
|
|
128
|
-
|
|
|
129
|
-
| `read(reference)`
|
|
130
|
-
| `write(reference, v)`
|
|
131
|
-
| `list()`
|
|
132
|
-
| `
|
|
133
|
-
| `readEnvironment(id)` | `op environment
|
|
129
|
+
| Method | What it does |
|
|
130
|
+
| ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
131
|
+
| `read(reference)` | `op read <reference>` — resolves `op://Vault/Item/field`. `--no-newline`. |
|
|
132
|
+
| `write(reference, v)` | Probe + `op item edit` if exists, else `op item create --category=API Credential`. |
|
|
133
|
+
| `list()` | `op item list --vault=<vault> --format=json` — names of items in the vault; with only an `environment` set, the variable names of that Environment (`setup` calls it). Neither is an error. |
|
|
134
|
+
| `readSecret(name)` | Reads one variable of the Environment named by the `environment` option, through the same `op environment secret list`; refuses without that option. Lets a caller (the `comlink deliver` probe) ask for a secret by its bare name. |
|
|
135
|
+
| `readEnvironment(name or id)` | `op environment secret list <name or id> --reveal --format=dotenv` — parses the variables into a record (a multi-line PEM key, which `op` prints unquoted, is read whole). `op environment read` takes only an id, so this reads through `secret list`, which takes either. |
|
|
134
136
|
|
|
135
137
|
Plugin-level exports (not capability methods, per the auth-bootstrap
|
|
136
138
|
convention):
|
package/dist/index.d.mts
CHANGED
|
@@ -1,18 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@theholocron/holocron-plugin-1password` — entrypoint.
|
|
3
|
+
*
|
|
4
|
+
* Implements the `vault` capability via `op` CLI shell-out. See
|
|
5
|
+
* README for the why-shell-out reasoning + prerequisites.
|
|
6
|
+
*/
|
|
7
|
+
import { Credentials, CredentialsInspection, EnvironmentEntry, Vault, VerifyTokenFailure, VerifyTokenResult, VerifyTokenResult as VerifyTokenResult$1, VerifyTokenSuccess } from "@theholocron/cli";
|
|
1
8
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
9
|
+
/** Thrown when the 1Password `op` CLI is missing or does not run. */
|
|
10
|
+
export declare class AuthError extends Error {
|
|
11
|
+
/** Error name; always `"AuthError"`. */
|
|
5
12
|
name: string;
|
|
6
13
|
}
|
|
7
|
-
|
|
14
|
+
/** Inputs for checking that the `op` binary is installed. */
|
|
15
|
+
export interface VerifyInput {
|
|
8
16
|
/** Override the spawn function in tests. */
|
|
9
17
|
spawn?: typeof spawnSync;
|
|
10
18
|
/** Path to the op binary. Defaults to "op". */
|
|
11
19
|
binary?: string;
|
|
12
20
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
//#region src/shell.d.ts
|
|
21
|
+
/** Runs `op --version` and throws `AuthError` when the binary is not found or exits non-zero. */
|
|
22
|
+
export declare function verifyOpInstalled(input?: VerifyInput): void;
|
|
16
23
|
interface OpResult {
|
|
17
24
|
ok: boolean;
|
|
18
25
|
stdout: string;
|
|
@@ -29,10 +36,15 @@ interface OpShellOptions {
|
|
|
29
36
|
interface RunOptions {
|
|
30
37
|
/** Skip `--account` injection for commands that operate above the account level (e.g., `account list`). */
|
|
31
38
|
skipAccount?: boolean;
|
|
39
|
+
/** Stop waiting for `op` after this many milliseconds. `op` can wait on the desktop app (a Touch ID prompt) without end. */
|
|
40
|
+
timeoutMs?: number;
|
|
32
41
|
}
|
|
33
|
-
|
|
42
|
+
/** Thin wrapper around `spawnSync` that runs the `op` CLI and returns a uniform result. */
|
|
43
|
+
export declare class OpShell {
|
|
34
44
|
private readonly spawnImpl;
|
|
45
|
+
/** The `op` binary this wrapper runs; defaults to `"op"`. */
|
|
35
46
|
readonly binary: string;
|
|
47
|
+
/** The 1Password account UUID passed as `--account` on each call, when one is set. */
|
|
36
48
|
readonly account?: string;
|
|
37
49
|
constructor(opts?: OpShellOptions);
|
|
38
50
|
/** Run `op <args>`, returning a uniform result. */
|
|
@@ -40,65 +52,119 @@ declare class OpShell {
|
|
|
40
52
|
/** Run + throw if non-zero. Mirrors REST clients' `request<T>` ergonomic. */
|
|
41
53
|
runOrThrow(args: string[], context: string, opts?: RunOptions): string;
|
|
42
54
|
}
|
|
43
|
-
|
|
44
|
-
|
|
55
|
+
/** `credentials` capability for 1Password, implemented by shelling out to `op environment secret list`. */
|
|
56
|
+
export declare class OpCredentials implements Credentials {
|
|
57
|
+
private readonly shell;
|
|
58
|
+
/** Capability key; always `"credentials"`. */
|
|
59
|
+
readonly key: "credentials";
|
|
60
|
+
/** Provider name; always `"1password"`. */
|
|
61
|
+
readonly providerName = "1password";
|
|
62
|
+
constructor(shell: OpShell);
|
|
63
|
+
/**
|
|
64
|
+
* Every variable of the Environment, with values. Tries {@link spellings} of the name until `op` finds one;
|
|
65
|
+
* any other failure (not signed in, a prompt that timed out) is thrown at once.
|
|
66
|
+
*/
|
|
67
|
+
read(environment: string): Promise<Record<string, string>>;
|
|
68
|
+
/**
|
|
69
|
+
* The Environment as `op` spells it, the names of its variables and which of them are visible, asked without
|
|
70
|
+
* `--reveal` so no value is printed or kept: `op` shows a placeholder for each value, which is not read, and the
|
|
71
|
+
* `concealed` flag that says secret from variable. Tries the same spellings as `read`.
|
|
72
|
+
*/
|
|
73
|
+
inspect(environment: string): Promise<CredentialsInspection>;
|
|
74
|
+
private list;
|
|
75
|
+
}
|
|
45
76
|
interface OpVaultOptions {
|
|
46
|
-
/**
|
|
47
|
-
|
|
77
|
+
/**
|
|
78
|
+
* 1P vault name items live in. `list()` needs it; `read` and `write` take it from the `op://` reference, and
|
|
79
|
+
* Environments are not in a vault, so a project that only reads an Environment can leave it out.
|
|
80
|
+
*/
|
|
81
|
+
vault?: string;
|
|
82
|
+
/**
|
|
83
|
+
* The 1Password Environment `readSecret` looks a variable up in. An app keeps its secrets in one Environment, so
|
|
84
|
+
* its config names it here and a caller can ask for a variable by its bare name.
|
|
85
|
+
*/
|
|
86
|
+
environment?: string;
|
|
48
87
|
}
|
|
49
|
-
|
|
88
|
+
/** `vault` capability for 1Password, implemented by shelling out to the `op` CLI against one vault. */
|
|
89
|
+
export declare class OpVault implements Vault {
|
|
50
90
|
private readonly shell;
|
|
91
|
+
/** Capability key; always `"vault"`. */
|
|
51
92
|
readonly key: "vault";
|
|
93
|
+
/** Provider name; always `"1password"`. */
|
|
52
94
|
readonly providerName = "1password";
|
|
53
95
|
private readonly vaultName;
|
|
54
|
-
|
|
96
|
+
private readonly environmentName;
|
|
97
|
+
constructor(shell: OpShell, opts?: OpVaultOptions);
|
|
55
98
|
read(reference: string): Promise<string>;
|
|
56
99
|
write(reference: string, value: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* The names this vault holds: the item titles of its `vault`, or, when only an `environment` is set (an Environment
|
|
102
|
+
* is not in a vault), that Environment's variable names. Values are read in memory and never returned.
|
|
103
|
+
*/
|
|
57
104
|
list(): Promise<string[]>;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
105
|
+
/**
|
|
106
|
+
* Every variable of a 1Password Environment, by its name or id. `op environment read` takes only an id, while
|
|
107
|
+
* `op environment secret list` takes either, so this reads through the latter with the values revealed. There is
|
|
108
|
+
* no `op` command that lists Environments, so this vault has no `environments()`.
|
|
109
|
+
*/
|
|
110
|
+
readEnvironment(environment: string): Promise<Record<string, string>>;
|
|
111
|
+
/**
|
|
112
|
+
* Every variable of an Environment with its `concealed` flag, from `--format=json`. The values are returned for an
|
|
113
|
+
* in-memory comparison and nothing here prints or logs them.
|
|
114
|
+
*/
|
|
115
|
+
readEnvironmentEntries(environment: string): Promise<EnvironmentEntry[]>;
|
|
116
|
+
/** One variable of the Environment this vault was set up with, by its bare name. */
|
|
117
|
+
readSecret(name: string): Promise<string>;
|
|
66
118
|
}
|
|
67
|
-
interface VerifyTokenFailure {
|
|
68
|
-
ok: false;
|
|
69
|
-
message: string;
|
|
70
|
-
}
|
|
71
|
-
type VerifyTokenResult = VerifyTokenSuccess | VerifyTokenFailure;
|
|
72
119
|
interface VerifyTokenOptions {
|
|
73
120
|
spawn?: typeof spawnSync;
|
|
74
121
|
binary?: string;
|
|
75
122
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
interface OpPluginOptions extends VerifyInput {
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
123
|
+
/** Checks that `op` is installed and signed in by running `op whoami`; the token argument is unused. */
|
|
124
|
+
export declare function verifyToken(_token: string, opts?: VerifyTokenOptions): Promise<VerifyTokenResult$1>;
|
|
125
|
+
/** Options for the 1Password plugin: the vault and account to use plus the `op` binary overrides. */
|
|
126
|
+
export interface OpPluginOptions extends VerifyInput {
|
|
127
|
+
/**
|
|
128
|
+
* 1P vault name items live in. Only listing a vault's items needs it; Environments are not in a vault, so a
|
|
129
|
+
* project that only reads an Environment can leave it out.
|
|
130
|
+
*/
|
|
131
|
+
vault?: string;
|
|
132
|
+
/** The Environment `readSecret` reads a variable from by its bare name; the one an app keeps its secrets in. */
|
|
133
|
+
environment?: string;
|
|
134
|
+
/** Optional 1P account UUID; passed as `--account` on every op call. Useful when several accounts are signed in. */
|
|
83
135
|
account?: string;
|
|
136
|
+
/** The repository root, handed in by the CLI: where `export-environment` writes `.credentials` and finds a layer word's remote. */
|
|
137
|
+
repoRoot?: string;
|
|
84
138
|
}
|
|
85
|
-
|
|
139
|
+
/** Shared state for one 1Password plugin instance: its options and the `op` shell wrapper. */
|
|
140
|
+
export interface PluginContext {
|
|
141
|
+
/** The options the plugin was created with. */
|
|
86
142
|
options: OpPluginOptions;
|
|
143
|
+
/** The wrapper that runs `op` commands. */
|
|
87
144
|
shell: OpShell;
|
|
88
145
|
}
|
|
89
|
-
|
|
90
|
-
declare function
|
|
91
|
-
|
|
146
|
+
/** Builds the plugin context; throws when the `op` binary is not installed. */
|
|
147
|
+
export declare function createContext(options: OpPluginOptions): PluginContext;
|
|
148
|
+
/** Builds the `vault` capability for the configured vault. */
|
|
149
|
+
export declare function vault(ctx: PluginContext): Vault;
|
|
150
|
+
/** Builds the `credentials` capability: the variables of a 1Password Environment, read for the token resolvers. */
|
|
151
|
+
export declare function credentials(ctx: PluginContext): Credentials;
|
|
152
|
+
/** Creates the 1Password plugin: its `connection` and `export-environment` probes and the `vault` and `credentials` capabilities. */
|
|
153
|
+
export declare function createPlugin(options?: OpPluginOptions): {
|
|
92
154
|
name: string;
|
|
155
|
+
probes: {
|
|
156
|
+
connection: import("@theholocron/cli").Probe;
|
|
157
|
+
"export-environment": import("@theholocron/cli").Probe;
|
|
158
|
+
};
|
|
93
159
|
capabilities: {
|
|
94
160
|
vault: () => Vault;
|
|
161
|
+
credentials: () => Credentials;
|
|
95
162
|
};
|
|
96
163
|
};
|
|
97
164
|
/**
|
|
98
|
-
* One-line hint printed by `holocron
|
|
165
|
+
* One-line hint printed by `holocron new token 1password` — 1P doesn't
|
|
99
166
|
* store a token in the holocron keyring; the `op` CLI manages its own
|
|
100
167
|
* auth. Directs the operator to the two paths that actually work.
|
|
101
168
|
*/
|
|
102
|
-
declare const AUTH_HINT: string;
|
|
103
|
-
|
|
104
|
-
export { AUTH_HINT, AuthError, OpPluginOptions, OpShell, OpVault, PluginContext, VerifyInput, type VerifyTokenFailure, type VerifyTokenResult, type VerifyTokenSuccess, createContext, createPlugin, vault, verifyOpInstalled, verifyToken };
|
|
169
|
+
export declare const AUTH_HINT: string;
|
|
170
|
+
export type { VerifyTokenFailure, VerifyTokenResult, VerifyTokenSuccess };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { ProviderApiError, connectionProbe, ignoreAdvice, resolveCredentialsFile, resolveEnvironmentId, stdoutKind } from "@theholocron/cli";
|
|
1
2
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import {
|
|
3
|
-
|
|
3
|
+
import { copyToClipboard, dotenvLine, finishCredentialsFile, isGitIgnored, shredFile, writeCredentialsFile } from "@theholocron/kyber/secrets";
|
|
4
|
+
// src/auth.ts
|
|
4
5
|
/**
|
|
5
6
|
* 1Password plugin "auth" is just verifying the `op` binary is on
|
|
6
7
|
* PATH — the CLI handles its own auth (keychain biometric unlock for
|
|
@@ -11,9 +12,12 @@ import { ProviderApiError } from "@theholocron/cli";
|
|
|
11
12
|
* a missing binary fails fast and clearly, not as a mystery error when
|
|
12
13
|
* the first `vault.read()` happens later.
|
|
13
14
|
*/
|
|
15
|
+
/** Thrown when the 1Password `op` CLI is missing or does not run. */
|
|
14
16
|
var AuthError = class extends Error {
|
|
17
|
+
/** Error name; always `"AuthError"`. */
|
|
15
18
|
name = "AuthError";
|
|
16
19
|
};
|
|
20
|
+
/** Runs `op --version` and throws `AuthError` when the binary is not found or exits non-zero. */
|
|
17
21
|
function verifyOpInstalled(input = {}) {
|
|
18
22
|
const spawnImpl = input.spawn ?? spawnSync;
|
|
19
23
|
const binary = input.binary ?? "op";
|
|
@@ -28,17 +32,186 @@ function verifyOpInstalled(input = {}) {
|
|
|
28
32
|
if (result.error) throw new AuthError(`1Password CLI (\`${binary}\`) not found on PATH. Install via \`brew install 1password-cli\` or see https://developer.1password.com/docs/cli/get-started.`);
|
|
29
33
|
if (result.status !== 0) throw new AuthError(`\`${binary} --version\` failed: ${(result.stderr ?? "").trim() || `exit ${result.status ?? "?"}`}`);
|
|
30
34
|
}
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
// src/parse-dotenv.ts
|
|
36
|
+
/**
|
|
37
|
+
* Parse dotenv text (`op environment secret list --format=dotenv`) into a record.
|
|
38
|
+
*
|
|
39
|
+
* Blank lines and `# comment` lines are skipped, as is a line with no `=`. A leading `export ` is dropped. A value
|
|
40
|
+
* in double quotes has `\n`, `\r`, `\t`, `\"` and `\\` unescaped and may run over several lines; a value in single
|
|
41
|
+
* quotes is taken as written; an unquoted value that opens a PEM block (`-----BEGIN …-----`) runs to its `-----END …-----`
|
|
42
|
+
* line, because `op` prints a multi-line key that way; anything else is the rest of the line, trimmed. Inline `#`
|
|
43
|
+
* comments are not stripped, because a token may contain one.
|
|
44
|
+
*/
|
|
45
|
+
function parseDotenv(text) {
|
|
46
|
+
const out = {};
|
|
47
|
+
const lines = text.split(/\r?\n/);
|
|
48
|
+
for (let i = 0; i < lines.length; i++) {
|
|
49
|
+
const line = lines[i].trim();
|
|
50
|
+
if (!line || line.startsWith("#")) continue;
|
|
51
|
+
const eq = line.indexOf("=");
|
|
52
|
+
if (eq < 0) continue;
|
|
53
|
+
const key = line.slice(0, eq).trim().replace(/^export\s+/, "");
|
|
54
|
+
if (!key) continue;
|
|
55
|
+
const value = line.slice(eq + 1).trim();
|
|
56
|
+
if (value.startsWith("\"")) {
|
|
57
|
+
let body = value.slice(1);
|
|
58
|
+
while (!hasClosingQuote(body) && i + 1 < lines.length) body += `\n${lines[++i]}`;
|
|
59
|
+
out[key] = unescapeDouble(body.slice(0, closingQuoteAt(body)));
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (value.startsWith("'") && value.endsWith("'") && value.length >= 2) {
|
|
63
|
+
out[key] = value.slice(1, -1);
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (/^-----BEGIN [^-]+-----/.test(value)) {
|
|
67
|
+
let block = value;
|
|
68
|
+
while (!/-----END [^-]+-----\s*$/.test(block) && i + 1 < lines.length) block += `\n${lines[++i].trim()}`;
|
|
69
|
+
out[key] = block;
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
out[key] = value;
|
|
73
|
+
}
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
/** The index of the first `"` not preceded by a backslash, or the whole length when there is none. */
|
|
77
|
+
function closingQuoteAt(body) {
|
|
78
|
+
for (let i = 0; i < body.length; i++) if (body[i] === "\\") i++;
|
|
79
|
+
else if (body[i] === "\"") return i;
|
|
80
|
+
return body.length;
|
|
81
|
+
}
|
|
82
|
+
function hasClosingQuote(body) {
|
|
83
|
+
return closingQuoteAt(body) < body.length;
|
|
84
|
+
}
|
|
85
|
+
function unescapeDouble(inner) {
|
|
86
|
+
return inner.replace(/\\([nrt"\\])/g, (_, c) => ({
|
|
87
|
+
n: "\n",
|
|
88
|
+
r: "\r",
|
|
89
|
+
t: " ",
|
|
90
|
+
"\"": "\"",
|
|
91
|
+
"\\": "\\"
|
|
92
|
+
})[c]);
|
|
93
|
+
}
|
|
94
|
+
// src/parse-environment-json.ts
|
|
95
|
+
/** The list in `op environment secret list --format=json`: a bare array, or an object that holds one. */
|
|
96
|
+
function entriesOf(parsed) {
|
|
97
|
+
if (Array.isArray(parsed)) return parsed;
|
|
98
|
+
if (parsed && typeof parsed === "object") {
|
|
99
|
+
const found = Object.values(parsed).find(Array.isArray);
|
|
100
|
+
if (found) return found;
|
|
101
|
+
}
|
|
102
|
+
throw new ProviderApiError("1Password returned an Environment listing in a shape this plugin does not know", 502, void 0);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Parse `op environment secret list --reveal --format=json` into entries that say whether each is concealed.
|
|
106
|
+
*
|
|
107
|
+
* Each entry carries a name (`name`, else `key`), a `value` and a boolean `concealed`. An entry with no name is
|
|
108
|
+
* skipped; a missing value is empty; a `concealed` that is not `false` counts as concealed, because the safe side
|
|
109
|
+
* of a comparison of secrets is to include it. The shape of `op`'s JSON is not documented here beyond those fields.
|
|
110
|
+
*/
|
|
111
|
+
function parseEnvironmentJson(text) {
|
|
112
|
+
let parsed;
|
|
113
|
+
try {
|
|
114
|
+
parsed = JSON.parse(text);
|
|
115
|
+
} catch {
|
|
116
|
+
throw new ProviderApiError("1Password returned an Environment listing that is not JSON", 502, void 0);
|
|
117
|
+
}
|
|
118
|
+
const out = [];
|
|
119
|
+
for (const raw of entriesOf(parsed)) {
|
|
120
|
+
if (!raw || typeof raw !== "object") continue;
|
|
121
|
+
const entry = raw;
|
|
122
|
+
const name = typeof entry.name === "string" ? entry.name : typeof entry.key === "string" ? entry.key : "";
|
|
123
|
+
if (!name) continue;
|
|
124
|
+
out.push({
|
|
125
|
+
name,
|
|
126
|
+
value: typeof entry.value === "string" ? entry.value : "",
|
|
127
|
+
concealed: entry.concealed !== false
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
// src/capabilities/credentials.ts
|
|
133
|
+
/** How long to wait for `op` (a Touch ID prompt included) before giving up on the environment. */
|
|
134
|
+
const READ_TIMEOUT_MS = 6e4;
|
|
135
|
+
/** `op` words a missing Environment as "environment couldn't be found". */
|
|
136
|
+
const NOT_FOUND = /couldn.?t be found|could not be found|not found/i;
|
|
137
|
+
/**
|
|
138
|
+
* The spellings of an Environment name to try, in order: as written, lowercase, Title case, UPPERCASE. `op` finds an
|
|
139
|
+
* Environment by its exact name and has no command that lists them, so the real spelling cannot be looked up.
|
|
140
|
+
*/
|
|
141
|
+
function spellings(name) {
|
|
142
|
+
const title = name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
|
|
143
|
+
return [.../* @__PURE__ */ new Set([
|
|
144
|
+
name,
|
|
145
|
+
name.toLowerCase(),
|
|
146
|
+
title,
|
|
147
|
+
name.toUpperCase()
|
|
148
|
+
])];
|
|
149
|
+
}
|
|
150
|
+
/** `credentials` capability for 1Password, implemented by shelling out to `op environment secret list`. */
|
|
151
|
+
var OpCredentials = class {
|
|
152
|
+
shell;
|
|
153
|
+
/** Capability key; always `"credentials"`. */
|
|
154
|
+
key = "credentials";
|
|
155
|
+
/** Provider name; always `"1password"`. */
|
|
156
|
+
providerName = "1password";
|
|
157
|
+
constructor(shell) {
|
|
158
|
+
this.shell = shell;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Every variable of the Environment, with values. Tries {@link spellings} of the name until `op` finds one;
|
|
162
|
+
* any other failure (not signed in, a prompt that timed out) is thrown at once.
|
|
163
|
+
*/
|
|
164
|
+
async read(environment) {
|
|
165
|
+
return parseDotenv((await this.list(environment, ["--reveal"])).stdout);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* The Environment as `op` spells it, the names of its variables and which of them are visible, asked without
|
|
169
|
+
* `--reveal` so no value is printed or kept: `op` shows a placeholder for each value, which is not read, and the
|
|
170
|
+
* `concealed` flag that says secret from variable. Tries the same spellings as `read`.
|
|
171
|
+
*/
|
|
172
|
+
async inspect(environment) {
|
|
173
|
+
const { name, stdout } = await this.list(environment, [], "json");
|
|
174
|
+
const entries = parseEnvironmentJson(stdout);
|
|
175
|
+
return {
|
|
176
|
+
environment: name,
|
|
177
|
+
names: entries.map((e) => e.name),
|
|
178
|
+
visible: entries.filter((e) => !e.concealed).map((e) => e.name)
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
async list(environment, flags, format = "dotenv") {
|
|
182
|
+
const tried = spellings(environment);
|
|
183
|
+
for (const name of tried) {
|
|
184
|
+
const result = this.shell.run([
|
|
185
|
+
"environment",
|
|
186
|
+
"secret",
|
|
187
|
+
"list",
|
|
188
|
+
name,
|
|
189
|
+
...flags,
|
|
190
|
+
`--format=${format}`
|
|
191
|
+
], { timeoutMs: READ_TIMEOUT_MS });
|
|
192
|
+
if (result.ok) return {
|
|
193
|
+
name,
|
|
194
|
+
stdout: result.stdout
|
|
195
|
+
};
|
|
196
|
+
if (!NOT_FOUND.test(result.stderr)) throw new ProviderApiError(`1Password environment secret list ${name} failed: ${result.stderr || "no stderr"}`, 0, result.stderr);
|
|
197
|
+
}
|
|
198
|
+
throw new ProviderApiError(`1Password has no Environment named "${environment}" (tried ${tried.map((n) => `"${n}"`).join(", ")}). Check the name, or use the Environment's id; names are matched exactly and \`op\` cannot list them.`, 404, void 0);
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
// src/capabilities/vault.ts
|
|
202
|
+
/** `vault` capability for 1Password, implemented by shelling out to the `op` CLI against one vault. */
|
|
33
203
|
var OpVault = class {
|
|
34
204
|
shell;
|
|
205
|
+
/** Capability key; always `"vault"`. */
|
|
35
206
|
key = "vault";
|
|
207
|
+
/** Provider name; always `"1password"`. */
|
|
36
208
|
providerName = "1password";
|
|
37
209
|
vaultName;
|
|
38
|
-
|
|
210
|
+
environmentName;
|
|
211
|
+
constructor(shell, opts = {}) {
|
|
39
212
|
this.shell = shell;
|
|
40
|
-
|
|
41
|
-
this.
|
|
213
|
+
this.vaultName = opts.vault || void 0;
|
|
214
|
+
this.environmentName = opts.environment || void 0;
|
|
42
215
|
}
|
|
43
216
|
async read(reference) {
|
|
44
217
|
return this.shell.runOrThrow([
|
|
@@ -74,7 +247,13 @@ var OpVault = class {
|
|
|
74
247
|
`${parsed.field}=${value}`
|
|
75
248
|
], `item create ${parsed.item}`);
|
|
76
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* The names this vault holds: the item titles of its `vault`, or, when only an `environment` is set (an Environment
|
|
252
|
+
* is not in a vault), that Environment's variable names. Values are read in memory and never returned.
|
|
253
|
+
*/
|
|
77
254
|
async list() {
|
|
255
|
+
if (!this.vaultName && this.environmentName) return Object.keys(await this.readEnvironment(this.environmentName));
|
|
256
|
+
if (!this.vaultName) throw new ProviderApiError("1Password `list` needs a `vault` or an `environment` in the plugin options: it lists the items in one vault, or the variable names of one Environment", 400, void 0);
|
|
78
257
|
const stdout = this.shell.runOrThrow([
|
|
79
258
|
"item",
|
|
80
259
|
"list",
|
|
@@ -84,21 +263,41 @@ var OpVault = class {
|
|
|
84
263
|
if (!stdout) return [];
|
|
85
264
|
return JSON.parse(stdout).map((i) => i.title);
|
|
86
265
|
}
|
|
87
|
-
|
|
88
|
-
|
|
266
|
+
/**
|
|
267
|
+
* Every variable of a 1Password Environment, by its name or id. `op environment read` takes only an id, while
|
|
268
|
+
* `op environment secret list` takes either, so this reads through the latter with the values revealed. There is
|
|
269
|
+
* no `op` command that lists Environments, so this vault has no `environments()`.
|
|
270
|
+
*/
|
|
271
|
+
async readEnvironment(environment) {
|
|
272
|
+
return parseDotenv(this.shell.runOrThrow([
|
|
89
273
|
"environment",
|
|
274
|
+
"secret",
|
|
90
275
|
"list",
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
276
|
+
environment,
|
|
277
|
+
"--reveal",
|
|
278
|
+
"--format=dotenv"
|
|
279
|
+
], `environment secret list ${environment}`));
|
|
95
280
|
}
|
|
96
|
-
|
|
97
|
-
|
|
281
|
+
/**
|
|
282
|
+
* Every variable of an Environment with its `concealed` flag, from `--format=json`. The values are returned for an
|
|
283
|
+
* in-memory comparison and nothing here prints or logs them.
|
|
284
|
+
*/
|
|
285
|
+
async readEnvironmentEntries(environment) {
|
|
286
|
+
return parseEnvironmentJson(this.shell.runOrThrow([
|
|
98
287
|
"environment",
|
|
99
|
-
"
|
|
100
|
-
|
|
101
|
-
|
|
288
|
+
"secret",
|
|
289
|
+
"list",
|
|
290
|
+
environment,
|
|
291
|
+
"--reveal",
|
|
292
|
+
"--format=json"
|
|
293
|
+
], `environment secret list ${environment}`));
|
|
294
|
+
}
|
|
295
|
+
/** One variable of the Environment this vault was set up with, by its bare name. */
|
|
296
|
+
async readSecret(name) {
|
|
297
|
+
if (!this.environmentName) throw new ProviderApiError("1Password `readSecret` needs an `environment` in the plugin options: it reads one variable of that Environment", 400, void 0);
|
|
298
|
+
const value = (await this.readEnvironment(this.environmentName))[name];
|
|
299
|
+
if (value === void 0) throw new ProviderApiError(`1Password Environment ${this.environmentName} has no variable ${name}`, 404, void 0);
|
|
300
|
+
return value;
|
|
102
301
|
}
|
|
103
302
|
};
|
|
104
303
|
/**
|
|
@@ -117,27 +316,169 @@ function parseReference(reference) {
|
|
|
117
316
|
field: fieldParts.join("/")
|
|
118
317
|
};
|
|
119
318
|
}
|
|
319
|
+
// src/probes/parse-export-args.ts
|
|
320
|
+
const USAGE = "usage: holocron probe 1password export-environment <environment> [--only NAME]... [--copy]";
|
|
321
|
+
/** Reads the words after `export-environment`: one Environment, any number of `--only NAME`, and `--copy`. */
|
|
322
|
+
function parseExportArgs(args) {
|
|
323
|
+
const only = [];
|
|
324
|
+
const positional = [];
|
|
325
|
+
let copy = false;
|
|
326
|
+
for (let i = 0; i < args.length; i++) {
|
|
327
|
+
const arg = args[i];
|
|
328
|
+
if (arg === "--copy") copy = true;
|
|
329
|
+
else if (arg === "--only") {
|
|
330
|
+
const name = args[++i];
|
|
331
|
+
if (name === void 0) throw new Error(`--only needs a variable name. ${USAGE}`);
|
|
332
|
+
only.push(name);
|
|
333
|
+
} else if (arg.startsWith("--only=")) only.push(arg.slice(7));
|
|
334
|
+
else if (arg.startsWith("--")) throw new Error(`unknown option ${arg}. ${USAGE}`);
|
|
335
|
+
else positional.push(arg);
|
|
336
|
+
}
|
|
337
|
+
if (positional.length !== 1) throw new Error(`name one Environment. ${USAGE}`);
|
|
338
|
+
return {
|
|
339
|
+
environment: positional[0],
|
|
340
|
+
only,
|
|
341
|
+
copy
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
// src/probes/export-environment.ts
|
|
345
|
+
/** The name of the file the lines go to (in `.holocron/.private/`), for the messages. */
|
|
346
|
+
const FILE_NAME = ".credentials";
|
|
347
|
+
/** Plain code-unit order: the same on every machine, whatever its locale. The names it sorts are all different. */
|
|
348
|
+
const compare = (a, b) => a < b ? -1 : 1;
|
|
349
|
+
/** Where the lines may go. Throws (with no value in the message) when nowhere is safe. */
|
|
350
|
+
function chooseDestination(deps, copy) {
|
|
351
|
+
if (copy) return "clipboard";
|
|
352
|
+
const kind = deps.outKind();
|
|
353
|
+
if (kind === "pipe") return "stdout";
|
|
354
|
+
if (kind === "other") throw new Error("refusing to write secrets to a redirected file: it would leave them on disk with no protection. Run it on a terminal for the private, short-lived .credentials file, or pipe the output to a tool, or use --copy");
|
|
355
|
+
if (deps.platform === "win32") throw new Error("cannot make the file private on Windows: its mode bits are not enforced, so other users may read it. Use --copy, or pipe the output to a tool");
|
|
356
|
+
if (!deps.interactive) throw new Error("the .credentials file is deleted once you confirm the import, which needs a terminal to ask on. Pipe the output to a tool, or use --copy");
|
|
357
|
+
return "file";
|
|
358
|
+
}
|
|
359
|
+
/** Writes the lines to the private file, waits for the import and deletes it. Registers the deletion for a failure or Ctrl-C. */
|
|
360
|
+
async function writeToFile(probe, deps, text) {
|
|
361
|
+
const { path } = resolveCredentialsFile(deps.repoRoot, void 0, deps.makeDir);
|
|
362
|
+
const git = deps.isIgnored(path);
|
|
363
|
+
if (git === "tracked" || git === "unknown") throw new Error(`refusing to write secrets to ${path}: ${git === "tracked" ? "git does not ignore it, so it could be committed" : "git could not say whether it ignores it"}; ${ignoreAdvice(true, "")}`);
|
|
364
|
+
let identity;
|
|
365
|
+
try {
|
|
366
|
+
identity = deps.writeFile(path, text, false);
|
|
367
|
+
} catch (err) {
|
|
368
|
+
const reason = err instanceof Error ? err.message : "unknown error";
|
|
369
|
+
throw new Error(`could not write ${path}: ${reason}. An existing file is never overwritten: delete it first`, { cause: err });
|
|
370
|
+
}
|
|
371
|
+
probe.cleanup(`the ${FILE_NAME} file`, async () => {
|
|
372
|
+
deps.shred(path, identity);
|
|
373
|
+
});
|
|
374
|
+
if (!await finishCredentialsFile({
|
|
375
|
+
path,
|
|
376
|
+
identity,
|
|
377
|
+
print: (line) => probe.say({
|
|
378
|
+
status: "info",
|
|
379
|
+
label: line
|
|
380
|
+
}),
|
|
381
|
+
holds: "the Environment's secrets",
|
|
382
|
+
importHint: "import it in the 1Password app: Developer, View Environments, the target Environment, Import .env file",
|
|
383
|
+
interactive: deps.interactive,
|
|
384
|
+
shred: deps.shred,
|
|
385
|
+
waitForImport: deps.waitForImport
|
|
386
|
+
})) probe.say({
|
|
387
|
+
status: "fail",
|
|
388
|
+
label: `${path} is still on disk and holds secrets in plain text: delete it`
|
|
389
|
+
});
|
|
390
|
+
}
|
|
120
391
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* a literal newline, that's a problem for the underlying environment,
|
|
125
|
-
* not this parser.
|
|
392
|
+
* The `export-environment` probe: reads one 1Password Environment in memory and writes its variables as `NAME=value`
|
|
393
|
+
* to a private `.credentials` file (deleted once the import into another Environment is done), a pipe or the clipboard.
|
|
394
|
+
* Names and counts are all it ever reports; a value is only ever in the text handed to the destination.
|
|
126
395
|
*/
|
|
127
|
-
function
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
396
|
+
function exportEnvironmentProbe(deps) {
|
|
397
|
+
return {
|
|
398
|
+
summary: "Read one 1Password Environment in memory and write its variables as NAME=value to a private .credentials file (deleted after the import), a pipe or the clipboard.",
|
|
399
|
+
writes: true,
|
|
400
|
+
reportsTo: "stderr",
|
|
401
|
+
async run(probe) {
|
|
402
|
+
const args = parseExportArgs(probe.args ?? []);
|
|
403
|
+
const destination = chooseDestination(deps, args.copy);
|
|
404
|
+
const environment = await deps.resolveId(args.environment, deps.repoRoot);
|
|
405
|
+
const all = await deps.read(environment);
|
|
406
|
+
const present = Object.keys(all);
|
|
407
|
+
const unknown = args.only.filter((name) => !present.includes(name));
|
|
408
|
+
if (unknown.length > 0) throw new Error(`${environment} has no variable named ${unknown.join(", ")}`);
|
|
409
|
+
const names = (args.only.length > 0 ? [...new Set(args.only)] : present).sort(compare);
|
|
410
|
+
if (names.length === 0) {
|
|
411
|
+
probe.say({
|
|
412
|
+
status: "info",
|
|
413
|
+
label: environment,
|
|
414
|
+
detail: "has no variables, so there is nothing to export"
|
|
415
|
+
});
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
const lines = [];
|
|
419
|
+
const exported = [];
|
|
420
|
+
for (const name of names) {
|
|
421
|
+
const value = all[name];
|
|
422
|
+
probe.secret(value);
|
|
423
|
+
const line = dotenvLine(name, value);
|
|
424
|
+
if (line === null) {
|
|
425
|
+
probe.say({
|
|
426
|
+
status: "fail",
|
|
427
|
+
label: name,
|
|
428
|
+
detail: "a value dotenv cannot carry unchanged, so add it by hand"
|
|
429
|
+
});
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
lines.push(line);
|
|
433
|
+
exported.push(name);
|
|
434
|
+
}
|
|
435
|
+
if (lines.length === 0) return;
|
|
436
|
+
const text = `${lines.join("\n")}\n`;
|
|
437
|
+
probe.say({
|
|
438
|
+
status: "heading",
|
|
439
|
+
label: `${environment}: ${exported.length} of ${names.length} variables`
|
|
440
|
+
});
|
|
441
|
+
for (const name of exported) probe.say({
|
|
442
|
+
status: "info",
|
|
443
|
+
label: name
|
|
444
|
+
});
|
|
445
|
+
const label = `write ${exported.length} variables to ${destination === "file" ? FILE_NAME : destination}`;
|
|
446
|
+
await probe.write(label, async () => {
|
|
447
|
+
if (destination === "clipboard") {
|
|
448
|
+
await deps.copy(text);
|
|
449
|
+
probe.say({
|
|
450
|
+
status: "ok",
|
|
451
|
+
label: "copied to the clipboard: paste it, then clear the clipboard"
|
|
452
|
+
});
|
|
453
|
+
} else if (destination === "stdout") {
|
|
454
|
+
deps.out(text);
|
|
455
|
+
probe.say({
|
|
456
|
+
status: "ok",
|
|
457
|
+
label: "wrote the variables to stdout"
|
|
458
|
+
});
|
|
459
|
+
} else await writeToFile(probe, deps, text);
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
}
|
|
464
|
+
// src/probes/export-environment-deps.ts
|
|
465
|
+
/** The real pieces `export-environment` runs on: the plugin's own reader, the repo root, this process's stdout and the shared secret-file helpers. */
|
|
466
|
+
function exportEnvironmentDeps(credentials, repoRoot) {
|
|
467
|
+
return {
|
|
468
|
+
read: (environment) => credentials.read(environment),
|
|
469
|
+
repoRoot,
|
|
470
|
+
resolveId: (id, root) => resolveEnvironmentId(id, { repoRoot: root }),
|
|
471
|
+
outKind: () => stdoutKind(process.stdout.isTTY === true),
|
|
472
|
+
out: (text) => void process.stdout.write(text),
|
|
473
|
+
copy: copyToClipboard,
|
|
474
|
+
writeFile: writeCredentialsFile,
|
|
475
|
+
shred: shredFile,
|
|
476
|
+
isIgnored: isGitIgnored,
|
|
477
|
+
platform: process.platform,
|
|
478
|
+
interactive: process.stdin.isTTY === true
|
|
479
|
+
};
|
|
138
480
|
}
|
|
139
|
-
|
|
140
|
-
//#region src/shell.ts
|
|
481
|
+
// src/shell.ts
|
|
141
482
|
/**
|
|
142
483
|
* Thin wrapper around `spawnSync` for `op` CLI shell-outs.
|
|
143
484
|
*
|
|
@@ -156,9 +497,12 @@ function parseEnvironmentDump(stdout) {
|
|
|
156
497
|
* token). Default spawnSync stdio of `['pipe','pipe','pipe']` would
|
|
157
498
|
* suppress biometric unlock and return "not signed in" instead.
|
|
158
499
|
*/
|
|
500
|
+
/** Thin wrapper around `spawnSync` that runs the `op` CLI and returns a uniform result. */
|
|
159
501
|
var OpShell = class {
|
|
160
502
|
spawnImpl;
|
|
503
|
+
/** The `op` binary this wrapper runs; defaults to `"op"`. */
|
|
161
504
|
binary;
|
|
505
|
+
/** The 1Password account UUID passed as `--account` on each call, when one is set. */
|
|
162
506
|
account;
|
|
163
507
|
constructor(opts = {}) {
|
|
164
508
|
this.spawnImpl = opts.spawn ?? spawnSync;
|
|
@@ -178,7 +522,8 @@ var OpShell = class {
|
|
|
178
522
|
"inherit",
|
|
179
523
|
"pipe",
|
|
180
524
|
"pipe"
|
|
181
|
-
]
|
|
525
|
+
],
|
|
526
|
+
...opts.timeoutMs !== void 0 ? { timeout: opts.timeoutMs } : {}
|
|
182
527
|
});
|
|
183
528
|
if (out.error) return {
|
|
184
529
|
ok: false,
|
|
@@ -198,10 +543,9 @@ var OpShell = class {
|
|
|
198
543
|
return result.stdout;
|
|
199
544
|
}
|
|
200
545
|
};
|
|
201
|
-
|
|
202
|
-
//#region src/verify-token.ts
|
|
546
|
+
// src/verify-token.ts
|
|
203
547
|
/**
|
|
204
|
-
* `verifyToken` — plugin-level export used by `holocron
|
|
548
|
+
* `verifyToken` — plugin-level export used by `holocron check token`.
|
|
205
549
|
*
|
|
206
550
|
* 1Password doesn't use a bearer token like the REST-transport plugins
|
|
207
551
|
* do — the `op` CLI manages its own auth via desktop-app biometric on
|
|
@@ -209,10 +553,11 @@ var OpShell = class {
|
|
|
209
553
|
* argument is intentionally IGNORED here. What we actually check is:
|
|
210
554
|
* is `op` installed AND signed in (i.e., can it answer `whoami`).
|
|
211
555
|
*
|
|
212
|
-
* If someone tries `holocron
|
|
556
|
+
* If someone tries `holocron new token 1password <token>`, the token
|
|
213
557
|
* will be stored in the keyring but never read by this plugin — the
|
|
214
558
|
* `AUTH_HINT` below explains that up front.
|
|
215
559
|
*/
|
|
560
|
+
/** Checks that `op` is installed and signed in by running `op whoami`; the token argument is unused. */
|
|
216
561
|
async function verifyToken(_token, opts = {}) {
|
|
217
562
|
const spawnImpl = opts.spawn ?? spawnSync;
|
|
218
563
|
const binary = opts.binary ?? "op";
|
|
@@ -245,10 +590,9 @@ async function verifyToken(_token, opts = {}) {
|
|
|
245
590
|
};
|
|
246
591
|
}
|
|
247
592
|
}
|
|
248
|
-
|
|
249
|
-
|
|
593
|
+
// src/index.ts
|
|
594
|
+
/** Builds the plugin context; throws when the `op` binary is not installed. */
|
|
250
595
|
function createContext(options) {
|
|
251
|
-
if (!options.vault) throw new Error("@theholocron/holocron-plugin-1password requires `vault` in options");
|
|
252
596
|
const verifyOpts = {};
|
|
253
597
|
if (options.spawn !== void 0) verifyOpts.spawn = options.spawn;
|
|
254
598
|
if (options.binary !== void 0) verifyOpts.binary = options.binary;
|
|
@@ -262,21 +606,40 @@ function createContext(options) {
|
|
|
262
606
|
shell: new OpShell(shellOpts)
|
|
263
607
|
};
|
|
264
608
|
}
|
|
609
|
+
/** Builds the `vault` capability for the configured vault. */
|
|
265
610
|
function vault(ctx) {
|
|
266
|
-
return new OpVault(ctx.shell, {
|
|
611
|
+
return new OpVault(ctx.shell, {
|
|
612
|
+
...ctx.options.vault !== void 0 ? { vault: ctx.options.vault } : {},
|
|
613
|
+
...ctx.options.environment !== void 0 ? { environment: ctx.options.environment } : {}
|
|
614
|
+
});
|
|
267
615
|
}
|
|
268
|
-
|
|
616
|
+
/** Builds the `credentials` capability: the variables of a 1Password Environment, read for the token resolvers. */
|
|
617
|
+
function credentials(ctx) {
|
|
618
|
+
return new OpCredentials(ctx.shell);
|
|
619
|
+
}
|
|
620
|
+
/** Creates the 1Password plugin: its `connection` and `export-environment` probes and the `vault` and `credentials` capabilities. */
|
|
621
|
+
function createPlugin(options = {}) {
|
|
269
622
|
const ctx = createContext(options);
|
|
270
623
|
return {
|
|
271
624
|
name: "@theholocron/holocron-plugin-1password",
|
|
272
|
-
|
|
625
|
+
probes: {
|
|
626
|
+
connection: connectionProbe({
|
|
627
|
+
provider: "1Password",
|
|
628
|
+
token: () => "",
|
|
629
|
+
verify: (token) => verifyToken(token, { spawn: options.spawn })
|
|
630
|
+
}),
|
|
631
|
+
"export-environment": exportEnvironmentProbe(exportEnvironmentDeps(new OpCredentials(ctx.shell), options.repoRoot ?? process.cwd()))
|
|
632
|
+
},
|
|
633
|
+
capabilities: {
|
|
634
|
+
vault: () => vault(ctx),
|
|
635
|
+
credentials: () => credentials(ctx)
|
|
636
|
+
}
|
|
273
637
|
};
|
|
274
638
|
}
|
|
275
639
|
/**
|
|
276
|
-
* One-line hint printed by `holocron
|
|
640
|
+
* One-line hint printed by `holocron new token 1password` — 1P doesn't
|
|
277
641
|
* store a token in the holocron keyring; the `op` CLI manages its own
|
|
278
642
|
* auth. Directs the operator to the two paths that actually work.
|
|
279
643
|
*/
|
|
280
644
|
const AUTH_HINT = "1Password uses the `op` CLI for auth — no bearer token to store. On laptop: `op signin` (or the desktop app's biometric flow). In CI: set `OP_SERVICE_ACCOUNT_TOKEN` in the workflow env.";
|
|
281
|
-
|
|
282
|
-
export { AUTH_HINT, AuthError, OpShell, OpVault, createContext, createPlugin, vault, verifyOpInstalled, verifyToken };
|
|
645
|
+
export { AUTH_HINT, AuthError, OpCredentials, OpShell, OpVault, createContext, createPlugin, credentials, vault, verifyOpInstalled, verifyToken };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theholocron/holocron-plugin-1password",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.541",
|
|
4
4
|
"description": "Holocron plugin for 1Password. Implements the vault capability via shell-out to the `op` CLI (https://developer.1password.com/docs/cli).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"1password",
|
|
@@ -8,12 +8,12 @@
|
|
|
8
8
|
"plugin",
|
|
9
9
|
"vault"
|
|
10
10
|
],
|
|
11
|
-
"homepage": "https://
|
|
11
|
+
"homepage": "https://docs.theholocron.dev/holocron/plugins/1password/",
|
|
12
12
|
"bugs": "https://github.com/theholocron/holocron/issues",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
15
|
"url": "git+https://github.com/theholocron/holocron.git",
|
|
16
|
-
"directory": "
|
|
16
|
+
"directory": "plugins/holocron-plugin-1password"
|
|
17
17
|
},
|
|
18
18
|
"license": "MIT",
|
|
19
19
|
"author": "Newton Koumantzelis",
|
|
@@ -29,25 +29,28 @@
|
|
|
29
29
|
"files": [
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@theholocron/kyber": "^5.0.0-alpha.541"
|
|
34
|
+
},
|
|
32
35
|
"devDependencies": {
|
|
33
|
-
"@theholocron/eslint-config": "^8.4.5",
|
|
34
|
-
"@theholocron/tsconfig": "^8.4.5",
|
|
35
|
-
"@theholocron/tsdown-config": "^8.4.5",
|
|
36
|
-
"@theholocron/vitest-config": "^8.4.5",
|
|
37
36
|
"@types/node": "^26",
|
|
38
|
-
"@vitest/coverage-v8": "^
|
|
39
|
-
"@vitest/eslint-plugin": "^1.6.
|
|
40
|
-
"eslint": "^10.
|
|
41
|
-
"eslint-plugin-n": "^18.
|
|
42
|
-
"globals": "^17.
|
|
43
|
-
"tsdown": "^0.
|
|
44
|
-
"tsx": "4.23.
|
|
45
|
-
"typescript": "^
|
|
46
|
-
"vitest": "^
|
|
47
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
37
|
+
"@vitest/coverage-v8": "^5.1.0",
|
|
38
|
+
"@vitest/eslint-plugin": "^1.6.28",
|
|
39
|
+
"eslint": "^10.15.0",
|
|
40
|
+
"eslint-plugin-n": "^18.5.0",
|
|
41
|
+
"globals": "^17.14.0",
|
|
42
|
+
"tsdown": "^0.23.7",
|
|
43
|
+
"tsx": "4.23.15",
|
|
44
|
+
"typescript": "^6.0.3",
|
|
45
|
+
"vitest": "^5.1.0",
|
|
46
|
+
"@theholocron/cli": "5.0.0-alpha.541",
|
|
47
|
+
"@theholocron/tsdown-config": "^8.9.0-alpha.22",
|
|
48
|
+
"@theholocron/vitest-config": "^8.9.0-alpha.22",
|
|
49
|
+
"@theholocron/tsconfig": "^8.9.0-alpha.22",
|
|
50
|
+
"@theholocron/eslint-config": "^8.9.0-alpha.22"
|
|
48
51
|
},
|
|
49
52
|
"peerDependencies": {
|
|
50
|
-
"@theholocron/cli": "5.0.0-alpha.
|
|
53
|
+
"@theholocron/cli": "5.0.0-alpha.541"
|
|
51
54
|
},
|
|
52
55
|
"engines": {
|
|
53
56
|
"node": ">=22"
|
|
@@ -56,11 +59,11 @@
|
|
|
56
59
|
"access": "public"
|
|
57
60
|
},
|
|
58
61
|
"scripts": {
|
|
59
|
-
"
|
|
60
|
-
"
|
|
62
|
+
"build": "tsdown",
|
|
63
|
+
"lint:code": "eslint .",
|
|
64
|
+
"test:unit": "vitest run --coverage",
|
|
61
65
|
"test:watch": "vitest",
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"verification.unitTests": "holocron run verification.unitTests --"
|
|
66
|
+
"typecheck": "tsc --noEmit",
|
|
67
|
+
"validate:plugin": "tsx scripts/validate.mjs"
|
|
65
68
|
}
|
|
66
69
|
}
|