getmyenv 0.12.1 → 0.12.2
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 +1 -1
- package/dist/lib/keychain.js +2 -2
- package/dist/lib/vault.js +20 -0
- package/package.json +1 -1
package/README.md
CHANGED
package/dist/lib/keychain.js
CHANGED
|
@@ -2,8 +2,8 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import { VAULT_UNLOCK_MS } from "@getmyenv/shared";
|
|
3
3
|
/**
|
|
4
4
|
* Unlocked open context keys, remembered in the OS keychain (macOS Keychain,
|
|
5
|
-
* Windows Credential Manager, Linux Secret Service) for a few hours so `run
|
|
6
|
-
* on an open context
|
|
5
|
+
* Windows Credential Manager, Linux Secret Service) for a few hours so `run`,
|
|
6
|
+
* `set` and `import` on an open context do not ask for the Vault password every time.
|
|
7
7
|
* Never the Vault password or the private key.
|
|
8
8
|
*/
|
|
9
9
|
const SERVICE = "getmyenv";
|
package/dist/lib/vault.js
CHANGED
|
@@ -20,12 +20,32 @@ export function fetchVault(linked) {
|
|
|
20
20
|
export async function writeKey(linked, target) {
|
|
21
21
|
if (!versions.has(target.id))
|
|
22
22
|
memo.delete(target.id);
|
|
23
|
+
const cached = await cachedWriteKey(linked, target);
|
|
24
|
+
if (cached)
|
|
25
|
+
return cached;
|
|
23
26
|
const key = await contextKey(linked, { ...target, sealedKey: undefined }, { create: true });
|
|
24
27
|
const keyVersion = versions.get(target.id);
|
|
25
28
|
if (keyVersion === undefined)
|
|
26
29
|
throw new Error(`No key version for ${target.slug}. Run the command again.`);
|
|
27
30
|
return { key, keyVersion };
|
|
28
31
|
}
|
|
32
|
+
/** An open context key from the keychain, with the version from a fresh vault response. No password. */
|
|
33
|
+
async function cachedWriteKey(linked, target) {
|
|
34
|
+
if (memo.has(target.id) || linked.who.token.kind === "server" || target.protection !== "open")
|
|
35
|
+
return null;
|
|
36
|
+
const account = keychainFor(linked);
|
|
37
|
+
if (!account)
|
|
38
|
+
return null;
|
|
39
|
+
const ctx = (await fetchVault(linked)).contexts.find((c) => c.id === target.id);
|
|
40
|
+
if (!ctx || ctx.protection !== "open" || !ctx.hasKey || !ctx.sealedKey)
|
|
41
|
+
return null;
|
|
42
|
+
const key = await readCachedContextKey(account, ctx.id, JSON.stringify(ctx.sealedKey));
|
|
43
|
+
if (!key)
|
|
44
|
+
return null;
|
|
45
|
+
memo.set(ctx.id, key);
|
|
46
|
+
versions.set(ctx.id, ctx.keyVersion);
|
|
47
|
+
return { key, keyVersion: ctx.keyVersion };
|
|
48
|
+
}
|
|
29
49
|
/** The context key, unlocking with the Vault password when needed. */
|
|
30
50
|
export async function contextKey(linked, target, opts = {}) {
|
|
31
51
|
const cached = memo.get(target.id);
|