keypin 0.8.0 → 0.9.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 +23 -18
- package/{chunk-m8824n5b.js → chunk-8jhj2smy.js} +122 -1041
- package/main.js +1 -1
- package/package.json +1 -1
|
@@ -8044,7 +8044,6 @@ function addDays(day, days) {
|
|
|
8044
8044
|
|
|
8045
8045
|
// ../../packages/core/src/map.ts
|
|
8046
8046
|
var DESTINATION_KINDS = ["cloudflare-worker", "github-actions"];
|
|
8047
|
-
var PROVIDER_KINDS = ["cloudflare-account-token"];
|
|
8048
8047
|
function runEnvironment(map) {
|
|
8049
8048
|
return map.environments[0] ?? "dev";
|
|
8050
8049
|
}
|
|
@@ -8091,21 +8090,26 @@ function parseMap(text, file) {
|
|
|
8091
8090
|
return validateMap(data, file);
|
|
8092
8091
|
}
|
|
8093
8092
|
var ENVIRONMENT_NAME = /^[a-z][a-z0-9-]*$/;
|
|
8094
|
-
var TARGET_NAME = ENVIRONMENT_NAME;
|
|
8095
8093
|
var KEY_FIELDS = ["rotate_every"];
|
|
8096
8094
|
var VARIABLE_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
8097
8095
|
var REPO = /^[A-Za-z0-9-]+\/[A-Za-z0-9._-]+$/;
|
|
8098
8096
|
var REMOVED_KEY_FIELDS = ["owner", "consumers"];
|
|
8099
8097
|
var OLD_FORMAT = "see docs/configuration.md for the current format";
|
|
8098
|
+
var PLACEHOLDER = /<[^<>]*>/;
|
|
8099
|
+
function filledIn(value, field, what, fail) {
|
|
8100
|
+
if (value === undefined || !PLACEHOLDER.test(value))
|
|
8101
|
+
return value;
|
|
8102
|
+
fail(`field "${field}" is a <...> placeholder: replace it with ${what}`);
|
|
8103
|
+
return;
|
|
8104
|
+
}
|
|
8100
8105
|
function validateMap(data, file) {
|
|
8101
8106
|
const errors = [];
|
|
8102
8107
|
const fail = (where, message) => errors.push(`${file}: ${where}${message}`);
|
|
8103
8108
|
if (!isRecord(data))
|
|
8104
8109
|
return { ok: false, errors: [`${file}: expected a table at the top level`] };
|
|
8105
|
-
unknownFields(data, ["environments", "1password", "
|
|
8110
|
+
unknownFields(data, ["environments", "1password", "keys"], (field) => fail("", field === "vaults" ? `[vaults] is from keypin 0.4; use [1password] and op:// references (${OLD_FORMAT})` : field === "targets" ? `shared [targets] are no longer supported; write each destination inline under [[keys.<VARIABLE>.<env>.publish]] (${OLD_FORMAT})` : `unknown top-level field "${field}"`));
|
|
8106
8111
|
const environments = validateEnvironments(data.environments, (message) => fail("", message));
|
|
8107
8112
|
const account = validateAccount(data["1password"], (message) => fail("[1password]: ", message));
|
|
8108
|
-
const targets = validateTargets(data.targets, (where, message) => fail(where, message));
|
|
8109
8113
|
const keys = [];
|
|
8110
8114
|
const rawKeys = data.keys ?? {};
|
|
8111
8115
|
if (!isRecord(rawKeys))
|
|
@@ -8113,15 +8117,11 @@ function validateMap(data, file) {
|
|
|
8113
8117
|
else {
|
|
8114
8118
|
Object.entries(rawKeys).forEach(([id, raw], index) => {
|
|
8115
8119
|
const label = VARIABLE_NAME.test(id) ? `key "${id}"` : `keys[${index}]`;
|
|
8116
|
-
const entry = validateKey(id, raw, account, environments,
|
|
8120
|
+
const entry = validateKey(id, raw, account, environments, (where, message) => fail(`${label}${where}: `, message));
|
|
8117
8121
|
if (entry)
|
|
8118
8122
|
keys.push(entry);
|
|
8119
8123
|
});
|
|
8120
8124
|
}
|
|
8121
|
-
for (const name of targets.defined) {
|
|
8122
|
-
if (!targets.used.has(name))
|
|
8123
|
-
fail(`target "${name}": `, "no key publishes to it; use it in a publish list or delete it");
|
|
8124
|
-
}
|
|
8125
8125
|
sharedDestinations(keys, environments, (where, message) => fail(where, message));
|
|
8126
8126
|
return errors.length ? { ok: false, errors } : { ok: true, map: { file, account: account ?? null, environments, keys } };
|
|
8127
8127
|
}
|
|
@@ -8133,43 +8133,9 @@ function validateAccount(raw, fail) {
|
|
|
8133
8133
|
return;
|
|
8134
8134
|
}
|
|
8135
8135
|
unknownFields(raw, ["account"], (field) => fail(`unknown field "${field}"`));
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8139
|
-
const targets = { defined: [], valid: new Map, used: new Set };
|
|
8140
|
-
if (raw === undefined)
|
|
8141
|
-
return targets;
|
|
8142
|
-
if (!isRecord(raw)) {
|
|
8143
|
-
fail("", `"targets" must be a table of named destinations, such as [targets.ci]`);
|
|
8144
|
-
return targets;
|
|
8145
|
-
}
|
|
8146
|
-
Object.entries(raw).forEach(([name, table], index) => {
|
|
8147
|
-
if (!TARGET_NAME.test(name)) {
|
|
8148
|
-
fail(`targets[${index}]: `, "a target name starts with a lowercase letter and uses only lowercase letters, digits and dashes");
|
|
8149
|
-
return;
|
|
8150
|
-
}
|
|
8151
|
-
targets.defined.push(name);
|
|
8152
|
-
const target = validateTarget(table, (m) => fail(`target "${name}": `, m));
|
|
8153
|
-
if (target)
|
|
8154
|
-
targets.valid.set(name, target);
|
|
8155
|
-
});
|
|
8156
|
-
return targets;
|
|
8157
|
-
}
|
|
8158
|
-
function resolveTarget(raw, targets, fail) {
|
|
8159
|
-
if (isRecord(raw))
|
|
8160
|
-
return validateTarget(raw, fail);
|
|
8161
|
-
if (typeof raw !== "string") {
|
|
8162
|
-
fail("must be a target name or a table");
|
|
8163
|
-
return;
|
|
8164
|
-
}
|
|
8165
|
-
const name = targets.defined.find((defined) => defined === raw);
|
|
8166
|
-
if (name === undefined) {
|
|
8167
|
-
fail(targets.defined.length ? `names no target in [targets]; targets are ${targets.defined.map((n) => `"${n}"`).join(", ")}` : "names a target, but the map has no [targets]");
|
|
8168
|
-
return;
|
|
8169
|
-
}
|
|
8170
|
-
targets.used.add(name);
|
|
8171
|
-
const target = targets.valid.get(name);
|
|
8172
|
-
return target ? { ...target } : undefined;
|
|
8136
|
+
const account = requiredString(raw, "account", fail);
|
|
8137
|
+
filledIn(account, "account", "your 1Password account's sign-in address (such as my.1password.com, at the top left of the 1Password app) or its account ID", fail);
|
|
8138
|
+
return account;
|
|
8173
8139
|
}
|
|
8174
8140
|
function validateEnvironments(raw, fail) {
|
|
8175
8141
|
if (raw === undefined)
|
|
@@ -8205,7 +8171,7 @@ function sharedDestinations(keys, environments, fail) {
|
|
|
8205
8171
|
}
|
|
8206
8172
|
}
|
|
8207
8173
|
}
|
|
8208
|
-
function validateKey(id, raw, account, environmentNames,
|
|
8174
|
+
function validateKey(id, raw, account, environmentNames, fail) {
|
|
8209
8175
|
let failures = 0;
|
|
8210
8176
|
const err = (where, message) => {
|
|
8211
8177
|
failures++;
|
|
@@ -8225,7 +8191,7 @@ function validateKey(id, raw, account, environmentNames, targets, fail) {
|
|
|
8225
8191
|
const environments = Object.create(null);
|
|
8226
8192
|
const declared = environmentNames.filter((name) => Object.hasOwn(raw, name));
|
|
8227
8193
|
for (const name of declared) {
|
|
8228
|
-
const entry = validateEnv(raw[name], account,
|
|
8194
|
+
const entry = validateEnv(raw[name], account, (m) => err(` ${name}`, m));
|
|
8229
8195
|
if (entry)
|
|
8230
8196
|
environments[name] = entry;
|
|
8231
8197
|
}
|
|
@@ -8242,7 +8208,7 @@ function validateKey(id, raw, account, environmentNames, targets, fail) {
|
|
|
8242
8208
|
return;
|
|
8243
8209
|
return { name: id, rotateEvery: rotateEvery ?? null, environments };
|
|
8244
8210
|
}
|
|
8245
|
-
function validateEnv(given, account,
|
|
8211
|
+
function validateEnv(given, account, fail) {
|
|
8246
8212
|
const raw = typeof given === "string" ? { from: given } : given;
|
|
8247
8213
|
if (!isRecord(raw)) {
|
|
8248
8214
|
fail(`must be an op:// reference, or a table with "from"`);
|
|
@@ -8253,7 +8219,7 @@ function validateEnv(given, account, targets, fail) {
|
|
|
8253
8219
|
failed = true;
|
|
8254
8220
|
fail(message);
|
|
8255
8221
|
};
|
|
8256
|
-
unknownFields(raw, ["from", "publish"
|
|
8222
|
+
unknownFields(raw, ["from", "publish"], (field) => err(field === "vault" || field === "item" ? `"vault" and "item" are from keypin 0.4; use from = "op://<vault>/<item>/<field>" (${OLD_FORMAT})` : field === "rotate" || field === "issue" ? `the "${field}" section is no longer supported, because keypin rotate is gone; delete it. To rotate the key by hand, replace the value in 1Password, set the item's rotated date to today, then run keypin publish` : `unknown field "${field}"`));
|
|
8257
8223
|
const ref = reference(raw, "from", account, err);
|
|
8258
8224
|
const publish = [];
|
|
8259
8225
|
const firstAt = new Map;
|
|
@@ -8262,7 +8228,7 @@ function validateEnv(given, account, targets, fail) {
|
|
|
8262
8228
|
err(`field "publish" must be a list`);
|
|
8263
8229
|
else {
|
|
8264
8230
|
raw.publish.forEach((t, i) => {
|
|
8265
|
-
const target =
|
|
8231
|
+
const target = destination(t, (m) => err(`publish[${i}]: ${m}`));
|
|
8266
8232
|
if (!target)
|
|
8267
8233
|
return;
|
|
8268
8234
|
const same = firstAt.get(placeId(target));
|
|
@@ -8275,10 +8241,9 @@ function validateEnv(given, account, targets, fail) {
|
|
|
8275
8241
|
});
|
|
8276
8242
|
}
|
|
8277
8243
|
}
|
|
8278
|
-
const rotate = raw.rotate === undefined || !ref ? undefined : validateRotate(raw.rotate, ref, account, (m) => err(`rotate: ${m}`));
|
|
8279
8244
|
if (failed || !ref)
|
|
8280
8245
|
return;
|
|
8281
|
-
return { ref, publish
|
|
8246
|
+
return { ref, publish };
|
|
8282
8247
|
}
|
|
8283
8248
|
function reference(table, field, account, fail) {
|
|
8284
8249
|
const text = requiredString(table, field, fail);
|
|
@@ -8289,6 +8254,11 @@ function reference(table, field, account, fail) {
|
|
|
8289
8254
|
fail(`field "${field}" ${parsed}`);
|
|
8290
8255
|
return;
|
|
8291
8256
|
}
|
|
8257
|
+
const parts = ["vault", "item", "section", "field"].filter((part) => PLACEHOLDER.test(parsed[part] ?? ""));
|
|
8258
|
+
if (parts.length) {
|
|
8259
|
+
fail(`field "${field}" has a <...> placeholder for its ${parts.join(" and ")}: replace it with the field's secret reference (in 1Password, open the field's menu and select Copy Secret Reference)`);
|
|
8260
|
+
return;
|
|
8261
|
+
}
|
|
8292
8262
|
if (account === undefined) {
|
|
8293
8263
|
fail(`field "${field}" needs your 1Password account: add [1password] with account = "..."`);
|
|
8294
8264
|
return;
|
|
@@ -8296,32 +8266,11 @@ function reference(table, field, account, fail) {
|
|
|
8296
8266
|
return { kind: "1password", account, ...parsed };
|
|
8297
8267
|
}
|
|
8298
8268
|
var ACCOUNT_ID = /^[0-9a-f]{32}$/;
|
|
8299
|
-
function
|
|
8300
|
-
if (
|
|
8301
|
-
fail("
|
|
8269
|
+
function destination(raw, fail) {
|
|
8270
|
+
if (typeof raw === "string") {
|
|
8271
|
+
fail(`names a shared target, which is no longer supported; write the destination inline, such as { to = "github-actions", repo = "owner/name" } (${OLD_FORMAT})`);
|
|
8302
8272
|
return;
|
|
8303
8273
|
}
|
|
8304
|
-
let failed = false;
|
|
8305
|
-
const err = (message) => {
|
|
8306
|
-
failed = true;
|
|
8307
|
-
fail(message);
|
|
8308
|
-
};
|
|
8309
|
-
unknownFields(raw, ["provider", "account", "admin"], (field) => err(`unknown field "${field}"`));
|
|
8310
|
-
const provider = requiredString(raw, "provider", err);
|
|
8311
|
-
const account = requiredString(raw, "account", err);
|
|
8312
|
-
const admin = reference(raw, "admin", vaultAccount, err);
|
|
8313
|
-
const kind = PROVIDER_KINDS.find((known) => known === provider);
|
|
8314
|
-
if (provider !== undefined && !kind)
|
|
8315
|
-
err(`field "provider" must be one of: ${PROVIDER_KINDS.join(", ")}`);
|
|
8316
|
-
if (account !== undefined && !ACCOUNT_ID.test(account))
|
|
8317
|
-
err(`field "account" must be a Cloudflare account ID (32 hex characters)`);
|
|
8318
|
-
if (admin && sameItem(admin, own))
|
|
8319
|
-
err(`field "admin" names the key's own item; the admin token needs its own item`);
|
|
8320
|
-
if (failed || !kind || account === undefined || admin === undefined)
|
|
8321
|
-
return;
|
|
8322
|
-
return { provider: kind, account, admin };
|
|
8323
|
-
}
|
|
8324
|
-
function validateTarget(raw, fail) {
|
|
8325
8274
|
if (!isRecord(raw)) {
|
|
8326
8275
|
fail("must be a table");
|
|
8327
8276
|
return;
|
|
@@ -8336,15 +8285,15 @@ function validateTarget(raw, fail) {
|
|
|
8336
8285
|
};
|
|
8337
8286
|
if (to === "cloudflare-worker") {
|
|
8338
8287
|
unknownFields(raw, ["to", "account", "worker"], (field) => err(`unknown field "${field}" for ${to}`));
|
|
8339
|
-
const account = requiredString(raw, "account", err);
|
|
8340
|
-
const worker = requiredString(raw, "worker", err);
|
|
8288
|
+
const account = filledIn(requiredString(raw, "account", err), "account", "the Cloudflare account ID the Worker belongs to (32 hex characters; wrangler whoami lists it)", err);
|
|
8289
|
+
const worker = filledIn(requiredString(raw, "worker", err), "worker", `the Worker's name, the "name" in its wrangler config`, err);
|
|
8341
8290
|
if (account !== undefined && !ACCOUNT_ID.test(account))
|
|
8342
8291
|
err(`field "account" must be a Cloudflare account ID (32 hex characters)`);
|
|
8343
8292
|
return failed || account === undefined || worker === undefined ? undefined : { to, account, worker };
|
|
8344
8293
|
}
|
|
8345
8294
|
if (to === "github-actions") {
|
|
8346
8295
|
unknownFields(raw, ["to", "repo"], (field) => err(field === "account" ? `field "account" is from keypin 0.6; the map pins only repo = "owner/name", and each machine publishes as its own GitHub login (git config github.account, else the active gh login). Delete it (${OLD_FORMAT})` : `unknown field "${field}" for ${to}`));
|
|
8347
|
-
const repo = requiredString(raw, "repo", err);
|
|
8296
|
+
const repo = filledIn(requiredString(raw, "repo", err), "repo", `the GitHub repository as "owner/name", such as "acme/billing"`, err);
|
|
8348
8297
|
if (repo !== undefined && !REPO.test(repo))
|
|
8349
8298
|
err(`field "repo" must be "owner/name"`);
|
|
8350
8299
|
return failed || repo === undefined ? undefined : { to, repo, account: repo.split("/")[0] };
|
|
@@ -8379,26 +8328,6 @@ function requiredString(table, field, fail) {
|
|
|
8379
8328
|
function optionalString(table, field, fail) {
|
|
8380
8329
|
return table[field] === undefined ? undefined : requiredString(table, field, fail);
|
|
8381
8330
|
}
|
|
8382
|
-
// ../../packages/core/src/tokens.ts
|
|
8383
|
-
function sameAccess(a, b) {
|
|
8384
|
-
return canonical(a.policies.map(policyShape)) === canonical(b.policies.map(policyShape)) && canonical(a.condition ?? {}) === canonical(b.condition ?? {});
|
|
8385
|
-
}
|
|
8386
|
-
function policyShape(policy) {
|
|
8387
|
-
return {
|
|
8388
|
-
effect: policy.effect,
|
|
8389
|
-
resources: policy.resources,
|
|
8390
|
-
groups: policy.permissionGroups.map((group) => group.id)
|
|
8391
|
-
};
|
|
8392
|
-
}
|
|
8393
|
-
function canonical(value) {
|
|
8394
|
-
if (Array.isArray(value))
|
|
8395
|
-
return `[${value.map(canonical).toSorted().join(",")}]`;
|
|
8396
|
-
if (isRecord(value)) {
|
|
8397
|
-
const entries = Object.entries(value).toSorted(([a], [b]) => a < b ? -1 : 1).map(([key, item]) => `${JSON.stringify(key)}:${canonical(item ?? null)}`);
|
|
8398
|
-
return `{${entries.join(",")}}`;
|
|
8399
|
-
}
|
|
8400
|
-
return JSON.stringify(value);
|
|
8401
|
-
}
|
|
8402
8331
|
// ../../packages/core/src/files.ts
|
|
8403
8332
|
async function writeJsonAtomic(files, path, data) {
|
|
8404
8333
|
const temporary = `${path}.${crypto.randomUUID()}.tmp`;
|
|
@@ -8631,52 +8560,8 @@ function latestPerSecret(receipts) {
|
|
|
8631
8560
|
function describeRef(ref) {
|
|
8632
8561
|
return `${formatReference(ref)} (1Password account ${ref.account})`;
|
|
8633
8562
|
}
|
|
8634
|
-
// ../../packages/core/src/rotations.ts
|
|
8635
|
-
var ROTATIONS_VERSION = 2;
|
|
8636
|
-
var ROTATION_STAGES = ["issuing", "issued", "stored", "published", "revoked"];
|
|
8637
|
-
var emptyRotations = () => ({ version: ROTATIONS_VERSION, rotations: [] });
|
|
8638
|
-
async function loadRotations(files, path) {
|
|
8639
|
-
const data = await readVersionedJson(files, path, [1, ROTATIONS_VERSION], "rotations file");
|
|
8640
|
-
if (!data)
|
|
8641
|
-
return emptyRotations();
|
|
8642
|
-
const rotations = Array.isArray(data.rotations) ? data.rotations.map((r) => isRecord(r) ? {
|
|
8643
|
-
...r,
|
|
8644
|
-
mapFile: data.version === ROTATIONS_VERSION ? r.mapFile : null,
|
|
8645
|
-
item: storedRefWithPasswordDefault(r.item) ?? r.item
|
|
8646
|
-
} : r) : data.rotations;
|
|
8647
|
-
if (!Array.isArray(rotations) || !rotations.every(isRotation)) {
|
|
8648
|
-
throw new Error(`${path}: the rotations file's "rotations" must be a list of rotations`);
|
|
8649
|
-
}
|
|
8650
|
-
return { version: ROTATIONS_VERSION, rotations };
|
|
8651
|
-
}
|
|
8652
|
-
async function saveRotations(files, path, data) {
|
|
8653
|
-
await writeJsonAtomic(files, path, data);
|
|
8654
|
-
}
|
|
8655
|
-
function unfinishedRotation(data, owner, item) {
|
|
8656
|
-
return data.rotations.find((r) => ownedBy(r, owner) && sameRef(r.item, item) && r.stage !== "revoked");
|
|
8657
|
-
}
|
|
8658
|
-
function rotateCommand(keyId, environment, fallback) {
|
|
8659
|
-
return `keypin rotate ${keyId}${envFlag(environment, fallback)}`;
|
|
8660
|
-
}
|
|
8661
|
-
function putRotation(data, rotation) {
|
|
8662
|
-
return {
|
|
8663
|
-
...data,
|
|
8664
|
-
rotations: [...data.rotations.filter((r) => r.id !== rotation.id), rotation]
|
|
8665
|
-
};
|
|
8666
|
-
}
|
|
8667
|
-
function dropRotation(data, id) {
|
|
8668
|
-
return { ...data, rotations: data.rotations.filter((r) => r.id !== id) };
|
|
8669
|
-
}
|
|
8670
|
-
var isText2 = (value) => typeof value === "string";
|
|
8671
|
-
var isTextOrNull2 = (value) => value === null || typeof value === "string";
|
|
8672
|
-
function isTokenRecord(t) {
|
|
8673
|
-
return isRecord(t) && isText2(t.name) && [t.id, t.expiresOn, t.generation].every(isTextOrNull2);
|
|
8674
|
-
}
|
|
8675
|
-
function isRotation(r) {
|
|
8676
|
-
return isRecord(r) && [r.id, r.keyId, r.environment, r.provider, r.account, r.startedAt, r.updatedAt].every(isText2) && isTextOrNull2(r.mapFile) && ROTATION_STAGES.some((stage) => stage === r.stage) && storedRefWithPasswordDefault(r.item) !== null && isTokenRecord(r.old) && isTokenRecord(r.new);
|
|
8677
|
-
}
|
|
8678
8563
|
// ../../packages/core/src/status.ts
|
|
8679
|
-
var NOTICES = ["due-soon", "never-published"
|
|
8564
|
+
var NOTICES = ["due-soon", "never-published"];
|
|
8680
8565
|
function buildStatus(input) {
|
|
8681
8566
|
if (!isDay(input.today))
|
|
8682
8567
|
throw new Error(`today must be YYYY-MM-DD, got "${input.today}"`);
|
|
@@ -8757,10 +8642,6 @@ function buildStatus(input) {
|
|
|
8757
8642
|
if (unpublished.length) {
|
|
8758
8643
|
add("never-published", `${label}: not published yet to ${unpublished.join(", ")}; run ${publish}`);
|
|
8759
8644
|
}
|
|
8760
|
-
const rotation = unfinishedRotation({ version: ROTATIONS_VERSION, rotations: [...input.rotations ?? []] }, owner, entry.ref);
|
|
8761
|
-
if (rotation) {
|
|
8762
|
-
add("rotation-unfinished", `${label}: a rotation started ${rotation.startedAt} is at stage "${rotation.stage}"; run ${rotateCommand(key.name, environment, publishEnvironment(result.map))} to continue`);
|
|
8763
|
-
}
|
|
8764
8645
|
rows.push({
|
|
8765
8646
|
...where,
|
|
8766
8647
|
ref: entry.ref,
|
|
@@ -10060,11 +9941,22 @@ function str(value) {
|
|
|
10060
9941
|
}
|
|
10061
9942
|
// ../../packages/destination-cloudflare/src/token.ts
|
|
10062
9943
|
import { execFile } from "child_process";
|
|
9944
|
+
import { statSync } from "fs";
|
|
10063
9945
|
import { readFile } from "fs/promises";
|
|
10064
9946
|
import { homedir } from "os";
|
|
10065
9947
|
import { join } from "path";
|
|
10066
|
-
|
|
10067
|
-
|
|
9948
|
+
function wranglerConfigFile(env = process.env, platform = process.platform, home = homedir()) {
|
|
9949
|
+
if (platform === "win32")
|
|
9950
|
+
throw new Error("keypin doesn't find the wrangler login on Windows yet; publish to Cloudflare from macOS or Linux");
|
|
9951
|
+
const legacy = join(home, ".wrangler");
|
|
9952
|
+
const base = env.XDG_CONFIG_HOME || join(home, platform === "darwin" ? "Library/Preferences" : ".config");
|
|
9953
|
+
const folder = isDirectory(legacy) ? legacy : join(base, ".wrangler");
|
|
9954
|
+
return join(folder, "config", "default.toml");
|
|
9955
|
+
}
|
|
9956
|
+
function isDirectory(path) {
|
|
9957
|
+
return statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;
|
|
9958
|
+
}
|
|
9959
|
+
async function wranglerToken(path = wranglerConfigFile()) {
|
|
10068
9960
|
let login = await readLogin(path);
|
|
10069
9961
|
if (login.expired) {
|
|
10070
9962
|
await refresh();
|
|
@@ -10074,7 +9966,7 @@ async function wranglerToken(path = WRANGLER_CONFIG) {
|
|
|
10074
9966
|
}
|
|
10075
9967
|
return login.token;
|
|
10076
9968
|
}
|
|
10077
|
-
async function currentWranglerToken(path =
|
|
9969
|
+
async function currentWranglerToken(path = wranglerConfigFile()) {
|
|
10078
9970
|
const login = await readLogin(path);
|
|
10079
9971
|
if (login.expired)
|
|
10080
9972
|
throw new Error("the wrangler login has expired; run `wrangler whoami`");
|
|
@@ -10581,172 +10473,6 @@ function refusal(status, repo) {
|
|
|
10581
10473
|
return "HTTP 401: the gh login's token was refused";
|
|
10582
10474
|
return `GitHub returned HTTP ${status}`;
|
|
10583
10475
|
}
|
|
10584
|
-
// ../../packages/provider-cloudflare/src/tokens.ts
|
|
10585
|
-
var API5 = "https://api.cloudflare.com/client/v4";
|
|
10586
|
-
var ACCOUNT_ID5 = /^[0-9a-f]{32}$/;
|
|
10587
|
-
var TOKEN_ID = /^[0-9a-f]{32}$/;
|
|
10588
|
-
|
|
10589
|
-
class CloudflareAccountTokens {
|
|
10590
|
-
#account;
|
|
10591
|
-
#admin;
|
|
10592
|
-
#fetch;
|
|
10593
|
-
constructor(options) {
|
|
10594
|
-
if (!ACCOUNT_ID5.test(options.account))
|
|
10595
|
-
throw new Error(`"${options.account}" isn't a Cloudflare account ID`);
|
|
10596
|
-
this.#account = options.account;
|
|
10597
|
-
this.#admin = options.admin;
|
|
10598
|
-
this.#fetch = options.fetch ?? globalThis.fetch;
|
|
10599
|
-
}
|
|
10600
|
-
describe() {
|
|
10601
|
-
return `Cloudflare account API tokens in account ${this.#account}`;
|
|
10602
|
-
}
|
|
10603
|
-
async verify(secret) {
|
|
10604
|
-
const path = `${this.#base()}/verify`;
|
|
10605
|
-
const reply = await this.#request("GET", path, secret);
|
|
10606
|
-
if (reply.status !== 200)
|
|
10607
|
-
throw failure2("GET", path, reply);
|
|
10608
|
-
const result = objectField3(reply.body, "result");
|
|
10609
|
-
return {
|
|
10610
|
-
id: tokenId(result.id, "verify"),
|
|
10611
|
-
status: text(result.status, "status"),
|
|
10612
|
-
expiresOn: optionalText(result.expires_on)
|
|
10613
|
-
};
|
|
10614
|
-
}
|
|
10615
|
-
async details(id) {
|
|
10616
|
-
const path = `${this.#base()}/${tokenId(id, "details")}`;
|
|
10617
|
-
const reply = await this.#request("GET", path, this.#admin);
|
|
10618
|
-
if (reply.status === 404)
|
|
10619
|
-
return null;
|
|
10620
|
-
if (reply.status !== 200)
|
|
10621
|
-
throw failure2("GET", path, reply);
|
|
10622
|
-
return token(objectField3(reply.body, "result"));
|
|
10623
|
-
}
|
|
10624
|
-
async issue(request) {
|
|
10625
|
-
const path = this.#base();
|
|
10626
|
-
const body = {
|
|
10627
|
-
name: request.name,
|
|
10628
|
-
policies: request.like.policies.map((policy) => ({
|
|
10629
|
-
effect: policy.effect,
|
|
10630
|
-
resources: policy.resources,
|
|
10631
|
-
permission_groups: policy.permissionGroups.map((group) => ({ id: group.id }))
|
|
10632
|
-
})),
|
|
10633
|
-
expires_on: request.expiresOn
|
|
10634
|
-
};
|
|
10635
|
-
if (request.like.condition)
|
|
10636
|
-
body.condition = request.like.condition;
|
|
10637
|
-
const reply = await this.#request("POST", path, this.#admin, body);
|
|
10638
|
-
if (reply.status >= 400 && reply.status < 500)
|
|
10639
|
-
return { refused: failure2("POST", path, reply).message };
|
|
10640
|
-
if (reply.status !== 200)
|
|
10641
|
-
throw failure2("POST", path, reply);
|
|
10642
|
-
const result = objectField3(reply.body, "result");
|
|
10643
|
-
const value = result.value;
|
|
10644
|
-
if (typeof value !== "string" || !value)
|
|
10645
|
-
throw new Error("Cloudflare's create response has no token value");
|
|
10646
|
-
return { token: token(result), value: new Secret(value) };
|
|
10647
|
-
}
|
|
10648
|
-
async revoke(id) {
|
|
10649
|
-
const path = `${this.#base()}/${tokenId(id, "revoke")}`;
|
|
10650
|
-
const reply = await this.#request("DELETE", path, this.#admin);
|
|
10651
|
-
if (reply.status === 404)
|
|
10652
|
-
return "already gone";
|
|
10653
|
-
if (reply.status !== 200)
|
|
10654
|
-
throw failure2("DELETE", path, reply);
|
|
10655
|
-
return "revoked";
|
|
10656
|
-
}
|
|
10657
|
-
#base() {
|
|
10658
|
-
return `/accounts/${this.#account}/tokens`;
|
|
10659
|
-
}
|
|
10660
|
-
async#request(method, path, auth, body) {
|
|
10661
|
-
const response = await this.#fetch(`${API5}${path}`, {
|
|
10662
|
-
method,
|
|
10663
|
-
headers: {
|
|
10664
|
-
Authorization: `Bearer ${auth.reveal()}`,
|
|
10665
|
-
...body === undefined ? {} : { "Content-Type": "application/json" }
|
|
10666
|
-
},
|
|
10667
|
-
body: body === undefined ? undefined : JSON.stringify(body)
|
|
10668
|
-
});
|
|
10669
|
-
return { status: response.status, body: parseObject3(await response.text()) };
|
|
10670
|
-
}
|
|
10671
|
-
}
|
|
10672
|
-
function token(result) {
|
|
10673
|
-
const policies = result.policies;
|
|
10674
|
-
if (!Array.isArray(policies))
|
|
10675
|
-
throw new Error("Cloudflare's token has no policies list");
|
|
10676
|
-
const condition = result.condition;
|
|
10677
|
-
return {
|
|
10678
|
-
id: tokenId(result.id, "token"),
|
|
10679
|
-
name: text(result.name, "name"),
|
|
10680
|
-
status: text(result.status, "status"),
|
|
10681
|
-
expiresOn: optionalText(result.expires_on),
|
|
10682
|
-
lastUsedOn: optionalText(result.last_used_on),
|
|
10683
|
-
policies: policies.map(policy),
|
|
10684
|
-
condition: isJsonObject(condition) && Object.keys(condition).length ? condition : null
|
|
10685
|
-
};
|
|
10686
|
-
}
|
|
10687
|
-
function policy(raw) {
|
|
10688
|
-
if (!isRecord(raw))
|
|
10689
|
-
throw new Error("a Cloudflare token policy isn't an object");
|
|
10690
|
-
const resources = raw.resources;
|
|
10691
|
-
const groups = raw.permission_groups;
|
|
10692
|
-
if (!isJsonObject(resources))
|
|
10693
|
-
throw new Error("a Cloudflare token policy has no resources");
|
|
10694
|
-
if (!Array.isArray(groups))
|
|
10695
|
-
throw new Error("a Cloudflare token policy has no permission groups");
|
|
10696
|
-
return {
|
|
10697
|
-
effect: text(raw.effect, "effect"),
|
|
10698
|
-
resources,
|
|
10699
|
-
permissionGroups: groups.map((group) => {
|
|
10700
|
-
if (!isRecord(group))
|
|
10701
|
-
throw new Error("a Cloudflare permission group isn't an object");
|
|
10702
|
-
return {
|
|
10703
|
-
id: text(group.id, "permission group id"),
|
|
10704
|
-
name: typeof group.name === "string" ? group.name : "(unnamed)"
|
|
10705
|
-
};
|
|
10706
|
-
})
|
|
10707
|
-
};
|
|
10708
|
-
}
|
|
10709
|
-
function isJson(value) {
|
|
10710
|
-
if (value === null || ["string", "number", "boolean"].includes(typeof value))
|
|
10711
|
-
return true;
|
|
10712
|
-
if (Array.isArray(value))
|
|
10713
|
-
return value.every(isJson);
|
|
10714
|
-
return isJsonObject(value);
|
|
10715
|
-
}
|
|
10716
|
-
function isJsonObject(value) {
|
|
10717
|
-
return isRecord(value) && Object.values(value).every(isJson);
|
|
10718
|
-
}
|
|
10719
|
-
function tokenId(value, where) {
|
|
10720
|
-
if (typeof value !== "string" || !TOKEN_ID.test(value))
|
|
10721
|
-
throw new Error(`Cloudflare's ${where} response has no valid token ID`);
|
|
10722
|
-
return value;
|
|
10723
|
-
}
|
|
10724
|
-
function text(value, field) {
|
|
10725
|
-
if (typeof value !== "string")
|
|
10726
|
-
throw new Error(`Cloudflare's token has no "${field}"`);
|
|
10727
|
-
return value;
|
|
10728
|
-
}
|
|
10729
|
-
function optionalText(value) {
|
|
10730
|
-
return typeof value === "string" && value ? value : null;
|
|
10731
|
-
}
|
|
10732
|
-
function failure2(method, path, reply) {
|
|
10733
|
-
const errors = reply.body.errors;
|
|
10734
|
-
const codes = Array.isArray(errors) ? errors.map((e) => isRecord(e) ? e.code : undefined).filter((c) => typeof c === "string" || typeof c === "number") : [];
|
|
10735
|
-
const detail = codes.length ? `, codes ${codes.join(", ")}` : "";
|
|
10736
|
-
return new Error(`Cloudflare ${method} ${path.split("?")[0]} returned HTTP ${reply.status}${detail}`);
|
|
10737
|
-
}
|
|
10738
|
-
function parseObject3(body) {
|
|
10739
|
-
try {
|
|
10740
|
-
const data = JSON.parse(body);
|
|
10741
|
-
return isRecord(data) ? data : {};
|
|
10742
|
-
} catch {
|
|
10743
|
-
return {};
|
|
10744
|
-
}
|
|
10745
|
-
}
|
|
10746
|
-
function objectField3(data, field) {
|
|
10747
|
-
const value = data[field];
|
|
10748
|
-
return isRecord(value) ? value : {};
|
|
10749
|
-
}
|
|
10750
10476
|
// ../../packages/vault-1password/src/sdk.ts
|
|
10751
10477
|
var desktopConnect = async (account) => {
|
|
10752
10478
|
const sdk = await import("@1password/sdk");
|
|
@@ -10844,11 +10570,6 @@ function onePasswordBackend(connect = desktopConnect) {
|
|
|
10844
10570
|
throw new Error(`${where(ref)}: rotated must be a real day as YYYY-MM-DD, got "${rotated}"`);
|
|
10845
10571
|
}
|
|
10846
10572
|
const sdk = await client(ref.account);
|
|
10847
|
-
if (options.item) {
|
|
10848
|
-
const item = await sdk.items.get(options.item.vault, options.item.item);
|
|
10849
|
-
await sdk.items.put(withValue(item, ref, secret, rotated));
|
|
10850
|
-
return;
|
|
10851
|
-
}
|
|
10852
10573
|
const id = await vaultId(sdk, ref);
|
|
10853
10574
|
const found = await find(sdk, id, ref);
|
|
10854
10575
|
if (found && options.newItem) {
|
|
@@ -10959,7 +10680,7 @@ function messageOf2(error) {
|
|
|
10959
10680
|
return error instanceof Error ? error.message : String(error);
|
|
10960
10681
|
}
|
|
10961
10682
|
// src/commands/check.ts
|
|
10962
|
-
import { dirname as
|
|
10683
|
+
import { dirname as dirname2, resolve } from "path";
|
|
10963
10684
|
import { parseArgs } from "util";
|
|
10964
10685
|
|
|
10965
10686
|
// src/deps.ts
|
|
@@ -10971,7 +10692,7 @@ function localDay(date) {
|
|
|
10971
10692
|
}
|
|
10972
10693
|
|
|
10973
10694
|
// src/paths.ts
|
|
10974
|
-
import {
|
|
10695
|
+
import { join as join2 } from "path";
|
|
10975
10696
|
function registryPath(deps) {
|
|
10976
10697
|
return join2(base(deps.env.XDG_CONFIG_HOME, deps.home, ".config"), "keypin", "registry.json");
|
|
10977
10698
|
}
|
|
@@ -10985,12 +10706,9 @@ function projectCount(registry, path) {
|
|
|
10985
10706
|
const count = registry.projects.length;
|
|
10986
10707
|
return `${count} ${count === 1 ? "project" : "projects"} in ${path}`;
|
|
10987
10708
|
}
|
|
10988
|
-
function rotationsPath(deps) {
|
|
10989
|
-
return join2(dirname(statePath(deps)), "rotations.json");
|
|
10990
|
-
}
|
|
10991
10709
|
|
|
10992
10710
|
// src/project.ts
|
|
10993
|
-
import { dirname
|
|
10711
|
+
import { dirname, join as join3 } from "path";
|
|
10994
10712
|
var MAP_FILE = "keypin.toml";
|
|
10995
10713
|
async function findMap(files, cwd) {
|
|
10996
10714
|
const found = await locateMap(files, cwd);
|
|
@@ -11004,12 +10722,12 @@ async function findMap(files, cwd) {
|
|
|
11004
10722
|
return result.map;
|
|
11005
10723
|
}
|
|
11006
10724
|
async function locateMap(files, cwd) {
|
|
11007
|
-
for (let folder = cwd;; folder =
|
|
10725
|
+
for (let folder = cwd;; folder = dirname(folder)) {
|
|
11008
10726
|
const file = join3(folder, MAP_FILE);
|
|
11009
10727
|
const text = await files.read(file);
|
|
11010
10728
|
if (text !== null)
|
|
11011
10729
|
return { file, text };
|
|
11012
|
-
if (
|
|
10730
|
+
if (dirname(folder) === folder)
|
|
11013
10731
|
return null;
|
|
11014
10732
|
}
|
|
11015
10733
|
}
|
|
@@ -11098,9 +10816,9 @@ async function build(folder, deps) {
|
|
|
11098
10816
|
}
|
|
11099
10817
|
report.map = found.file;
|
|
11100
10818
|
const registry = await loadRegistry(deps.files, registryPath(deps));
|
|
11101
|
-
report.registered = registry.projects.includes(
|
|
10819
|
+
report.registered = registry.projects.includes(dirname2(found.file));
|
|
11102
10820
|
if (!report.registered)
|
|
11103
|
-
report.notes.push(`${
|
|
10821
|
+
report.notes.push(`${dirname2(found.file)} isn't registered, so keypin status doesn't list it; run keypin init there`);
|
|
11104
10822
|
const parsed = parseMap(found.text, found.file);
|
|
11105
10823
|
if (!parsed.ok) {
|
|
11106
10824
|
report.problems.push(...parsed.errors);
|
|
@@ -11117,7 +10835,7 @@ async function build(folder, deps) {
|
|
|
11117
10835
|
}));
|
|
11118
10836
|
const users = new Map;
|
|
11119
10837
|
const use = (id, label) => users.set(id, [...users.get(id) ?? [], label]);
|
|
11120
|
-
const refs = distinctRefs(entries.
|
|
10838
|
+
const refs = distinctRefs(entries.map(({ entry }) => entry.ref));
|
|
11121
10839
|
announce(deps.stderr, "each value to check that its item and field exist (none is printed)", refs);
|
|
11122
10840
|
const items = new Map;
|
|
11123
10841
|
for (const ref of refs)
|
|
@@ -11144,9 +10862,6 @@ async function build(folder, deps) {
|
|
|
11144
10862
|
if (!from)
|
|
11145
10863
|
throw new Error(`no item check for ${formatReference(entry.ref)}`);
|
|
11146
10864
|
use(`item ${refKey(entry.ref)}`, label);
|
|
11147
|
-
const admin = entry.rotate ? items.get(refKey(entry.rotate.admin)) : undefined;
|
|
11148
|
-
if (entry.rotate)
|
|
11149
|
-
use(`item ${refKey(entry.rotate.admin)}`, `${label} rotate admin`);
|
|
11150
10865
|
const reached = entry.publish.map((target) => {
|
|
11151
10866
|
use(`place ${placeOf(target)}`, label);
|
|
11152
10867
|
const result = destinations.get(placeOf(target));
|
|
@@ -11154,13 +10869,7 @@ async function build(folder, deps) {
|
|
|
11154
10869
|
throw new Error(`no account check for ${placeOf(target)}`);
|
|
11155
10870
|
return { ...result, destination: secretKey(target, key) };
|
|
11156
10871
|
});
|
|
11157
|
-
report.keys.push({
|
|
11158
|
-
key,
|
|
11159
|
-
environment,
|
|
11160
|
-
from,
|
|
11161
|
-
rotateAdmin: admin ?? null,
|
|
11162
|
-
destinations: reached
|
|
11163
|
-
});
|
|
10872
|
+
report.keys.push({ key, environment, from, destinations: reached });
|
|
11164
10873
|
}
|
|
11165
10874
|
const usedBy = (id) => ` (${users.get(id)?.join(", ") ?? "unused"})`;
|
|
11166
10875
|
for (const ref of refs) {
|
|
@@ -11224,8 +10933,6 @@ function render(report) {
|
|
|
11224
10933
|
for (const row of report.keys) {
|
|
11225
10934
|
lines.push("", `${row.key} (${row.environment})`);
|
|
11226
10935
|
lines.push(` ${mark(row.from.ok)} from ${row.from.reference}`);
|
|
11227
|
-
if (row.rotateAdmin)
|
|
11228
|
-
lines.push(` ${mark(row.rotateAdmin.ok)} rotate admin ${row.rotateAdmin.reference}`);
|
|
11229
10936
|
for (const d of row.destinations) {
|
|
11230
10937
|
lines.push(` ${mark(d.ok)} ${d.destination}: login ${d.login}, publisher ${d.publisher ?? "unknown"}, pinned account ${d.pinned}, reaches ${d.reached ?? "unknown"}`);
|
|
11231
10938
|
}
|
|
@@ -11413,11 +11120,6 @@ async function discover(args, deps) {
|
|
|
11413
11120
|
environments: map?.environments ?? DEFAULT_ENVIRONMENTS,
|
|
11414
11121
|
written: values.write
|
|
11415
11122
|
});
|
|
11416
|
-
if (draft !== null) {
|
|
11417
|
-
const check = parseMap(draft, "draft");
|
|
11418
|
-
if (!check.ok)
|
|
11419
|
-
throw new Error(`the draft doesn't parse: ${check.errors.join("; ")}`);
|
|
11420
|
-
}
|
|
11421
11123
|
if (values.write && draft === null) {
|
|
11422
11124
|
deps.stderr.write(`keypin discover: found no unmapped name set locally or in the cloud, so there's no draft; nothing was written. Run keypin init for a template.
|
|
11423
11125
|
`);
|
|
@@ -11663,12 +11365,12 @@ async function locked(deps, body) {
|
|
|
11663
11365
|
}
|
|
11664
11366
|
function lockedMessage(file, holder) {
|
|
11665
11367
|
if (holder.pid === null) {
|
|
11666
|
-
return `keypin: ${file} exists but names no process. If no publish
|
|
11368
|
+
return `keypin: ${file} exists but names no process. If no publish is running, delete that file and try again.`;
|
|
11667
11369
|
}
|
|
11668
11370
|
if (holder.running === false) {
|
|
11669
11371
|
return `keypin: ${file} was left by process ${holder.pid}, which isn't running any more. Delete that file and try again.`;
|
|
11670
11372
|
}
|
|
11671
|
-
return `keypin: another publish
|
|
11373
|
+
return `keypin: another publish (process ${holder.pid}) holds ${file} and is still running. Wait for it to finish.`;
|
|
11672
11374
|
}
|
|
11673
11375
|
async function checkAccounts(key, entry, deps, say, heading = "Account checks") {
|
|
11674
11376
|
say(`
|
|
@@ -11792,8 +11494,9 @@ async function importEnv(args, deps) {
|
|
|
11792
11494
|
const target = await readTarget(deps, request);
|
|
11793
11495
|
const environment = runEnvironment(target.map ?? { environments: DEFAULT_ENVIRONMENTS });
|
|
11794
11496
|
const project = basename2(deps.cwd);
|
|
11795
|
-
const
|
|
11796
|
-
|
|
11497
|
+
const file = envValues(text);
|
|
11498
|
+
const values = selected(file, request.names, envPath);
|
|
11499
|
+
if (!file.size)
|
|
11797
11500
|
throw new Error(`${envPath} sets no variables; nothing to import`);
|
|
11798
11501
|
const planned = [];
|
|
11799
11502
|
let skips = [];
|
|
@@ -11809,7 +11512,12 @@ async function importEnv(args, deps) {
|
|
|
11809
11512
|
onlyInFile: true
|
|
11810
11513
|
});
|
|
11811
11514
|
else if (value.isEmpty())
|
|
11812
|
-
skips.push({
|
|
11515
|
+
skips.push({
|
|
11516
|
+
name,
|
|
11517
|
+
reason: "the value is empty",
|
|
11518
|
+
onlyInFile: false,
|
|
11519
|
+
mappedEmpty: Boolean(mapped?.environments[environment])
|
|
11520
|
+
});
|
|
11813
11521
|
else if (mapped?.environments[environment] && value.includes("$"))
|
|
11814
11522
|
skips.push({
|
|
11815
11523
|
name,
|
|
@@ -11924,8 +11632,20 @@ async function importEnv(args, deps) {
|
|
|
11924
11632
|
if (!target.map)
|
|
11925
11633
|
await registerProject(deps, deps.cwd);
|
|
11926
11634
|
const left = [...skips.filter((skip) => skip.onlyInFile).map((skip) => skip.name), ...failed];
|
|
11635
|
+
const done = new Set([
|
|
11636
|
+
...mapped.map((entry) => entry.name),
|
|
11637
|
+
...skips.filter((skip) => skip.mapped && !skip.onlyInFile).map((skip) => skip.name),
|
|
11638
|
+
...skips.filter((skip) => skip.mappedEmpty).map((skip) => skip.name)
|
|
11639
|
+
]);
|
|
11640
|
+
const remove = [...file.keys()].filter((name) => done.has(name));
|
|
11641
|
+
const rest = [...file].filter(([name, value]) => !remove.includes(name) && (left.includes(name) || !value.isEmpty()));
|
|
11927
11642
|
say(`The imported values are now in 1Password, and keypin run -- <command> provides them. keypin left ${envPath} as it is.`);
|
|
11928
|
-
|
|
11643
|
+
if (left.length)
|
|
11644
|
+
say(`${names(left)} ${left.length === 1 ? "is" : "are"} still only in that file, for the reason under Skipped.`);
|
|
11645
|
+
if (basename2(envPath).startsWith(".dev.vars"))
|
|
11646
|
+
say(rest.length ? `Delete it once ${names(rest.map(([name]) => name))} ${rest.length === 1 ? "has" : "have"} a new home: while a .dev.vars file exists, wrangler dev reads secrets only from it and ignores the ones keypin run provides. Import a secret among them too. A plain setting that isn't secret can go to wrangler dev --var NAME:value; [vars] in the wrangler config also deploys.` : "Nothing else is set in it. Delete it: while a .dev.vars file exists, wrangler dev ignores the secrets keypin run provides.");
|
|
11647
|
+
else
|
|
11648
|
+
say(rest.length ? `Remove the ${names(remove)} ${remove.length === 1 ? "line" : "lines"} from it: keypin run warns while an env file holds a key it provides.` : "Nothing else is set in it. Delete it and stop loading it.");
|
|
11929
11649
|
if (failed.length)
|
|
11930
11650
|
say("Run keypin import again to create the rest. It maps an item it already stored, since that item holds the same value.");
|
|
11931
11651
|
return failed.length || existed ? 1 : 0;
|
|
@@ -11967,6 +11687,14 @@ async function existingProblem(deps, entry) {
|
|
|
11967
11687
|
return `and couldn't be read (${messageOf(error)})`;
|
|
11968
11688
|
}
|
|
11969
11689
|
}
|
|
11690
|
+
function selected(file, wanted, envPath) {
|
|
11691
|
+
if (!wanted.length)
|
|
11692
|
+
return file;
|
|
11693
|
+
const missing = wanted.filter((name) => !file.has(name));
|
|
11694
|
+
if (missing.length)
|
|
11695
|
+
throw new UsageError(`${envPath} doesn't set ${names(missing)}; name variables it sets`);
|
|
11696
|
+
return new Map([...file].filter(([name]) => wanted.includes(name)));
|
|
11697
|
+
}
|
|
11970
11698
|
function names(list) {
|
|
11971
11699
|
return list.length ? list.join(", ") : "none";
|
|
11972
11700
|
}
|
|
@@ -11980,9 +11708,9 @@ function parseRequest(args) {
|
|
|
11980
11708
|
},
|
|
11981
11709
|
allowPositionals: true
|
|
11982
11710
|
});
|
|
11983
|
-
const [envFile, ...
|
|
11984
|
-
if (envFile === undefined
|
|
11985
|
-
throw new UsageError("keypin import takes
|
|
11711
|
+
const [envFile, ...names] = positionals;
|
|
11712
|
+
if (envFile === undefined)
|
|
11713
|
+
throw new UsageError("keypin import takes an env file, such as .env or .dev.vars");
|
|
11986
11714
|
const vault = values.vault?.trim();
|
|
11987
11715
|
if (!vault)
|
|
11988
11716
|
throw new UsageError("--vault is required: the 1Password vault to create the items in");
|
|
@@ -11991,7 +11719,7 @@ function parseRequest(args) {
|
|
|
11991
11719
|
const account = values.account?.trim();
|
|
11992
11720
|
if (values.account !== undefined && !account)
|
|
11993
11721
|
throw new UsageError("--account is your 1Password sign-in address, such as my.1password.com");
|
|
11994
|
-
return { envFile, vault, account, yes: values.yes, args };
|
|
11722
|
+
return { envFile, names: [...new Set(names)], vault, account, yes: values.yes, args };
|
|
11995
11723
|
}
|
|
11996
11724
|
async function readTarget(deps, request) {
|
|
11997
11725
|
const file = join6(deps.cwd, MAP_FILE);
|
|
@@ -12288,649 +12016,11 @@ async function confirmed2(deps, needsApproval, request) {
|
|
|
12288
12016
|
return false;
|
|
12289
12017
|
}
|
|
12290
12018
|
|
|
12291
|
-
// src/commands/rotate.ts
|
|
12292
|
-
import { join as join7 } from "path";
|
|
12293
|
-
import { parseArgs as parseArgs6 } from "util";
|
|
12294
|
-
var GRACE_DAYS = DUE_SOON_DAYS;
|
|
12295
|
-
async function rotate(args, deps) {
|
|
12296
|
-
const { values, positionals } = parseArgs6({
|
|
12297
|
-
args,
|
|
12298
|
-
options: {
|
|
12299
|
-
env: { type: "string" },
|
|
12300
|
-
yes: { type: "boolean", default: false },
|
|
12301
|
-
plan: { type: "boolean", default: false }
|
|
12302
|
-
},
|
|
12303
|
-
allowPositionals: true
|
|
12304
|
-
});
|
|
12305
|
-
const [keyId, ...extra] = positionals;
|
|
12306
|
-
if (keyId === undefined || extra.length)
|
|
12307
|
-
throw new UsageError("keypin rotate takes one key: the variable name");
|
|
12308
|
-
const map = await findMap(deps.files, deps.cwd);
|
|
12309
|
-
const environment = pickEnvironment(map, values.env, publishEnvironment(map));
|
|
12310
|
-
const key = map.keys.find((k) => k.name === keyId);
|
|
12311
|
-
if (!key)
|
|
12312
|
-
throw new Error(`${map.file} has no key "${keyId}"`);
|
|
12313
|
-
const entry = key.environments[environment];
|
|
12314
|
-
if (!entry)
|
|
12315
|
-
throw new Error(`key "${keyId}" has no ${environment} entry in ${map.file}`);
|
|
12316
|
-
const spec = entry.rotate;
|
|
12317
|
-
if (!spec) {
|
|
12318
|
-
throw new Error(`key "${keyId}" has no [keys.${keyId}.${environment}.rotate] section in ${map.file}, so keypin can't make a new value`);
|
|
12319
|
-
}
|
|
12320
|
-
const say = (text) => deps.stderr.write(`${text}
|
|
12321
|
-
`);
|
|
12322
|
-
return locked(deps, async (statePath) => {
|
|
12323
|
-
const run = {
|
|
12324
|
-
map,
|
|
12325
|
-
key,
|
|
12326
|
-
entry,
|
|
12327
|
-
spec,
|
|
12328
|
-
environment,
|
|
12329
|
-
yes: values.yes,
|
|
12330
|
-
plan: values.plan,
|
|
12331
|
-
args,
|
|
12332
|
-
statePath,
|
|
12333
|
-
rotationsPath: rotationsPath(deps),
|
|
12334
|
-
deps,
|
|
12335
|
-
say
|
|
12336
|
-
};
|
|
12337
|
-
const data = await loadRotations(deps.files, run.rotationsPath);
|
|
12338
|
-
const open = unfinishedRotation(data, keyOwner(run), entry.ref);
|
|
12339
|
-
if (!open)
|
|
12340
|
-
return start(run, data);
|
|
12341
|
-
say(`An unfinished rotation of ${key.name} (${environment}), started ${open.startedAt}, is at stage "${open.stage}".`);
|
|
12342
|
-
if (open.provider !== spec.provider || open.account !== spec.account) {
|
|
12343
|
-
say(`Stopped: that rotation made its token as ${open.provider} in account ${open.account}, and the map now says ${spec.provider} in account ${spec.account}. Put the map back to finish it. Nothing was changed.`);
|
|
12344
|
-
return 1;
|
|
12345
|
-
}
|
|
12346
|
-
switch (open.stage) {
|
|
12347
|
-
case "issuing":
|
|
12348
|
-
case "issued":
|
|
12349
|
-
return abandon(run, data, open);
|
|
12350
|
-
case "stored":
|
|
12351
|
-
return publishNew(run, data, open, null);
|
|
12352
|
-
case "published":
|
|
12353
|
-
return revokeOld(run, data, open);
|
|
12354
|
-
case "revoked":
|
|
12355
|
-
throw new Error(`rotation ${open.id} is finished`);
|
|
12356
|
-
}
|
|
12357
|
-
});
|
|
12358
|
-
}
|
|
12359
|
-
async function start(run, data) {
|
|
12360
|
-
const { key, entry, spec, environment, deps, say } = run;
|
|
12361
|
-
say(`Rotating ${key.name} (${environment}) from ${formatReference(entry.ref)}`);
|
|
12362
|
-
say(` 1Password account: ${entry.ref.account}`);
|
|
12363
|
-
say(` new token: ${spec.provider} in account ${spec.account}, made with the admin token in ${formatReference(spec.admin)}`);
|
|
12364
|
-
for (const target of entry.publish)
|
|
12365
|
-
say(` to: ${describeTarget(target, key.name)}`);
|
|
12366
|
-
if (!entry.publish.length) {
|
|
12367
|
-
say(`Stopped: the map lists no destinations for ${key.name} (${environment}), so nothing would get the new token. Nothing was changed.`);
|
|
12368
|
-
return 1;
|
|
12369
|
-
}
|
|
12370
|
-
const every = key.rotateEvery;
|
|
12371
|
-
const days = periodDays(every);
|
|
12372
|
-
if (!days) {
|
|
12373
|
-
say(`Stopped: rotate needs a rotation period to set the new token's expiry, and ${every ? `rotate_every is "${every}"` : "keypin.toml has no rotate_every for this key"}. Nothing was changed.`);
|
|
12374
|
-
return 1;
|
|
12375
|
-
}
|
|
12376
|
-
const state = await loadState(deps.files, run.statePath);
|
|
12377
|
-
const checked = await checkAccounts(key, entry, deps, say);
|
|
12378
|
-
if (!checked) {
|
|
12379
|
-
say("Stopped: an account check failed. Nothing was read and nothing was changed.");
|
|
12380
|
-
return 1;
|
|
12381
|
-
}
|
|
12382
|
-
const unattended = !deps.isTerminal && !run.plan;
|
|
12383
|
-
let unread = approvalsFor({ ...planFor(run), receipts: state.receipts });
|
|
12384
|
-
if (unattended && run.yes && !unread.length) {
|
|
12385
|
-
const found = await idsBeforeReading(run);
|
|
12386
|
-
if (!found)
|
|
12387
|
-
return 1;
|
|
12388
|
-
unread = approvalsFor({ ...planFor(run), receipts: state.receipts }, found);
|
|
12389
|
-
}
|
|
12390
|
-
if (unattended && (unread.length || !run.yes)) {
|
|
12391
|
-
for (const approval of unread)
|
|
12392
|
-
say(` needs approval: ${approval.approval}`);
|
|
12393
|
-
say(unread.length ? "Stopped before reading anything: this rotation needs approval, and --yes can't give it. Nothing was changed." : "Stopped before reading anything: no terminal to confirm on. Nothing was changed. Add --yes, or confirm in a terminal.");
|
|
12394
|
-
say(rerun(deps, "rotate", run.args));
|
|
12395
|
-
return NEEDS_APPROVAL;
|
|
12396
|
-
}
|
|
12397
|
-
announce(deps.stderr, "the current value and the admin token", [entry.ref, spec.admin]);
|
|
12398
|
-
const vault = deps.vault();
|
|
12399
|
-
let current;
|
|
12400
|
-
let ids;
|
|
12401
|
-
let admin;
|
|
12402
|
-
try {
|
|
12403
|
-
({ secret: current, ids } = await vault.readItem(entry.ref));
|
|
12404
|
-
admin = await vault.read(spec.admin);
|
|
12405
|
-
} catch (error) {
|
|
12406
|
-
say(`Stopped: ${messageOf(error)}. Nothing was changed.`);
|
|
12407
|
-
return 1;
|
|
12408
|
-
}
|
|
12409
|
-
if (current.equals(admin)) {
|
|
12410
|
-
say(`Stopped: ${formatReference(spec.admin)} holds the same value as ${formatReference(entry.ref)}. The admin token needs its own field, or rotating would overwrite it. Nothing was changed.`);
|
|
12411
|
-
return 1;
|
|
12412
|
-
}
|
|
12413
|
-
const provider = deps.provider(spec, admin);
|
|
12414
|
-
const found = await provider.verify(current);
|
|
12415
|
-
if (found.status !== "active") {
|
|
12416
|
-
say(`Stopped: the current value is token ${found.id}, and it's ${found.status}. Nothing was changed.`);
|
|
12417
|
-
return 1;
|
|
12418
|
-
}
|
|
12419
|
-
const old = await provider.details(found.id);
|
|
12420
|
-
if (!old) {
|
|
12421
|
-
say(`Stopped: the admin token can't read token ${found.id}, the current value's token. Nothing was changed.`);
|
|
12422
|
-
return 1;
|
|
12423
|
-
}
|
|
12424
|
-
const approvals = approvalsFor({ ...planFor(run), receipts: state.receipts }, ids);
|
|
12425
|
-
const today = localDay(deps.now());
|
|
12426
|
-
const name = nextName(old.name, today);
|
|
12427
|
-
const expiresOn = `${addDays(today, days + GRACE_DAYS)}T23:59:59Z`;
|
|
12428
|
-
say(`
|
|
12429
|
-
Plan:`);
|
|
12430
|
-
say(` current token: ${old.id} "${old.name}", ${old.status}, expires ${old.expiresOn ?? "never"}`);
|
|
12431
|
-
say(` new token: "${name}", expires ${expiresOn} (rotate_every ${every} plus ${GRACE_DAYS} days' grace)`);
|
|
12432
|
-
for (const line of describeAccess(old))
|
|
12433
|
-
say(` ${line}`);
|
|
12434
|
-
say(` store in: ${formatReference(entry.ref)}, with rotated ${today}`);
|
|
12435
|
-
for (const target of entry.publish) {
|
|
12436
|
-
const found = checked.get(destinationId(target, key.name));
|
|
12437
|
-
say(` publish to: ${describeTarget(target, key.name)}`);
|
|
12438
|
-
if (found)
|
|
12439
|
-
say(` ${accountFacts(found.check)}`);
|
|
12440
|
-
}
|
|
12441
|
-
for (const approval of approvals)
|
|
12442
|
-
say(` needs approval: ${approval.approval}`);
|
|
12443
|
-
say(` then stop: the old token stays active until you run ${again(run)} again.`);
|
|
12444
|
-
if (run.plan)
|
|
12445
|
-
return planOnly(deps, "rotate", run.args, approvals.length > 0);
|
|
12446
|
-
if (!await confirmed3(run, approvals.length > 0, "make the new token"))
|
|
12447
|
-
return NEEDS_APPROVAL;
|
|
12448
|
-
const now = deps.now().toISOString();
|
|
12449
|
-
let rotation = {
|
|
12450
|
-
id: crypto.randomUUID(),
|
|
12451
|
-
keyId: key.name,
|
|
12452
|
-
environment,
|
|
12453
|
-
mapFile: run.map.file,
|
|
12454
|
-
item: entry.ref,
|
|
12455
|
-
provider: spec.provider,
|
|
12456
|
-
account: spec.account,
|
|
12457
|
-
stage: "issuing",
|
|
12458
|
-
startedAt: now,
|
|
12459
|
-
updatedAt: now,
|
|
12460
|
-
old: {
|
|
12461
|
-
id: old.id,
|
|
12462
|
-
name: old.name,
|
|
12463
|
-
expiresOn: old.expiresOn,
|
|
12464
|
-
generation: await generationOf(current)
|
|
12465
|
-
},
|
|
12466
|
-
new: { id: null, name, expiresOn, generation: null }
|
|
12467
|
-
};
|
|
12468
|
-
data = putRotation(withoutFinished(data, keyOwner(run)), rotation);
|
|
12469
|
-
await saveRotations(deps.files, run.rotationsPath, data);
|
|
12470
|
-
const made = await provider.issue({ name, like: old, expiresOn });
|
|
12471
|
-
if ("refused" in made) {
|
|
12472
|
-
await saveRotations(deps.files, run.rotationsPath, dropRotation(data, rotation.id));
|
|
12473
|
-
say(`Stopped: ${made.refused}. No token was made, and nothing was changed.`);
|
|
12474
|
-
return 1;
|
|
12475
|
-
}
|
|
12476
|
-
const generation = await generationOf(made.value);
|
|
12477
|
-
rotation = {
|
|
12478
|
-
...rotation,
|
|
12479
|
-
stage: "issued",
|
|
12480
|
-
updatedAt: deps.now().toISOString(),
|
|
12481
|
-
new: { id: made.token.id, name: made.token.name, expiresOn: made.token.expiresOn, generation }
|
|
12482
|
-
};
|
|
12483
|
-
data = putRotation(data, rotation);
|
|
12484
|
-
await saveRotations(deps.files, run.rotationsPath, data);
|
|
12485
|
-
say(`
|
|
12486
|
-
issued ${made.token.id} "${made.token.name}", expires ${made.token.expiresOn ?? "never"}`);
|
|
12487
|
-
const problem = await checkNew(provider, made.token.id, made.value, old);
|
|
12488
|
-
if (problem) {
|
|
12489
|
-
say(` FAILED the new token's check: ${problem}`);
|
|
12490
|
-
return deleteUnchecked(run, data, rotation, provider);
|
|
12491
|
-
}
|
|
12492
|
-
say(` checked: ${made.token.id} is active and has the same policies as ${old.id}`);
|
|
12493
|
-
say(`keypin: writing the new value to ${formatReference(entry.ref)}, with rotated ${today}`);
|
|
12494
|
-
try {
|
|
12495
|
-
await vault.write(entry.ref, made.value, { rotated: today, item: ids });
|
|
12496
|
-
const readBack = await vault.readItem(entry.ref);
|
|
12497
|
-
const stored = await generationOf(readBack.secret);
|
|
12498
|
-
if (stored !== generation)
|
|
12499
|
-
throw new Error(`the item reads back generation ${stored}, not ${generation}`);
|
|
12500
|
-
if (readBack.ids.vault !== ids.vault || readBack.ids.item !== ids.item)
|
|
12501
|
-
throw new Error(`it reads back as item ${readBack.ids.item}, not ${ids.item}`);
|
|
12502
|
-
} catch (error) {
|
|
12503
|
-
say(`Stopped: couldn't store the new value: ${messageOf(error)}.`);
|
|
12504
|
-
say(`The new token ${made.token.id} exists, and the old token still works everywhere. Run ${again(run)} again to delete the new token and start over.`);
|
|
12505
|
-
return 1;
|
|
12506
|
-
}
|
|
12507
|
-
rotation = { ...rotation, stage: "stored", updatedAt: deps.now().toISOString() };
|
|
12508
|
-
data = putRotation(data, rotation);
|
|
12509
|
-
await saveRotations(deps.files, run.rotationsPath, data);
|
|
12510
|
-
say(` stored generation ${generation}`);
|
|
12511
|
-
return publishNew(run, data, rotation, { value: made.value, ids, checked });
|
|
12512
|
-
}
|
|
12513
|
-
async function publishNew(run, data, rotation, fresh) {
|
|
12514
|
-
const { key, entry, environment, deps, say } = run;
|
|
12515
|
-
const state = await loadState(deps.files, run.statePath);
|
|
12516
|
-
let value;
|
|
12517
|
-
let ids;
|
|
12518
|
-
let checked;
|
|
12519
|
-
const resuming = fresh === null;
|
|
12520
|
-
if (fresh) {
|
|
12521
|
-
({ value, ids, checked } = fresh);
|
|
12522
|
-
} else {
|
|
12523
|
-
say(`It stored the new value (generation ${rotation.new.generation}); this run publishes it.`);
|
|
12524
|
-
const found = await checkAccounts(key, entry, deps, say);
|
|
12525
|
-
if (!found) {
|
|
12526
|
-
say("Stopped: an account check failed. Nothing was read and nothing was written.");
|
|
12527
|
-
return 1;
|
|
12528
|
-
}
|
|
12529
|
-
checked = found;
|
|
12530
|
-
const unattended = !deps.isTerminal && !run.plan;
|
|
12531
|
-
let approvals = approvalsFor({ ...planFor(run), receipts: state.receipts });
|
|
12532
|
-
if (unattended && !approvals.length) {
|
|
12533
|
-
const found = await idsBeforeReading(run);
|
|
12534
|
-
if (!found)
|
|
12535
|
-
return 1;
|
|
12536
|
-
approvals = approvalsFor({ ...planFor(run), receipts: state.receipts }, found);
|
|
12537
|
-
}
|
|
12538
|
-
if (unattended && approvals.length) {
|
|
12539
|
-
say("Stopped before reading the value: publishing needs approval, and --yes can't give it.");
|
|
12540
|
-
say(rerun(deps, "rotate", run.args));
|
|
12541
|
-
return NEEDS_APPROVAL;
|
|
12542
|
-
}
|
|
12543
|
-
announce(deps.stderr, "the value to publish and the admin token, to check the new token", [
|
|
12544
|
-
entry.ref,
|
|
12545
|
-
run.spec.admin
|
|
12546
|
-
]);
|
|
12547
|
-
({ secret: value, ids } = await deps.vault().readItem(entry.ref));
|
|
12548
|
-
const generation = await generationOf(value);
|
|
12549
|
-
if (generation !== rotation.new.generation) {
|
|
12550
|
-
say(`Stopped: ${formatReference(entry.ref)} holds generation ${generation}, not the rotation's ${rotation.new.generation}. Something else changed it. Nothing was written.`);
|
|
12551
|
-
return 1;
|
|
12552
|
-
}
|
|
12553
|
-
const problem = await recheck(run, rotation, value);
|
|
12554
|
-
if (problem) {
|
|
12555
|
-
say(`Stopped: ${problem}. Nothing was written, and the rotation stays at "${rotation.stage}". The old token still works where it was published.`);
|
|
12556
|
-
return 1;
|
|
12557
|
-
}
|
|
12558
|
-
say(` checked: ${rotation.new.id} is active and has the same policies as ${rotation.old.id}`);
|
|
12559
|
-
}
|
|
12560
|
-
const generation = rotation.new.generation ?? await generationOf(value);
|
|
12561
|
-
const plan = planPublish({ ...planFor(run), receipts: state.receipts, generation, ids });
|
|
12562
|
-
say(`
|
|
12563
|
-
Publishing generation ${generation}:`);
|
|
12564
|
-
for (const step of plan.steps) {
|
|
12565
|
-
say(` ${step.action} ${describeTarget(step.target, key.name)}: ${step.reason}`);
|
|
12566
|
-
if (step.approval)
|
|
12567
|
-
say(` needs approval: ${step.approval}`);
|
|
12568
|
-
}
|
|
12569
|
-
const writes = writesFor(plan.steps, checked);
|
|
12570
|
-
if (run.plan)
|
|
12571
|
-
return planOnly(deps, "rotate", run.args, plan.needsApproval);
|
|
12572
|
-
if (resuming && writes.length && !await confirmed3(run, plan.needsApproval, "publish")) {
|
|
12573
|
-
return NEEDS_APPROVAL;
|
|
12574
|
-
}
|
|
12575
|
-
const written = await writeAll({
|
|
12576
|
-
key,
|
|
12577
|
-
environment,
|
|
12578
|
-
mapFile: run.map.file,
|
|
12579
|
-
entry,
|
|
12580
|
-
secret: value,
|
|
12581
|
-
ids,
|
|
12582
|
-
generation,
|
|
12583
|
-
writes,
|
|
12584
|
-
state,
|
|
12585
|
-
path: run.statePath,
|
|
12586
|
-
deps,
|
|
12587
|
-
say
|
|
12588
|
-
});
|
|
12589
|
-
if (!written.ok) {
|
|
12590
|
-
say(`Stopped. The old token still works where the write failed. Run ${again(run)} again to finish publishing.`);
|
|
12591
|
-
return 1;
|
|
12592
|
-
}
|
|
12593
|
-
const published = {
|
|
12594
|
-
...rotation,
|
|
12595
|
-
stage: "published",
|
|
12596
|
-
updatedAt: deps.now().toISOString()
|
|
12597
|
-
};
|
|
12598
|
-
await saveRotations(deps.files, run.rotationsPath, putRotation(data, published));
|
|
12599
|
-
say(`
|
|
12600
|
-
Published. The old token ${rotation.old.id} "${rotation.old.name}" is still active.`);
|
|
12601
|
-
say("Next, check that every consumer works with the new value:");
|
|
12602
|
-
for (const target of entry.publish)
|
|
12603
|
-
say(` ${describeTarget(target, key.name)}`);
|
|
12604
|
-
say(`Then run ${again(run)} again to revoke the old token.`);
|
|
12605
|
-
return 0;
|
|
12606
|
-
}
|
|
12607
|
-
async function revokeOld(run, data, rotation) {
|
|
12608
|
-
const { key, spec, environment, deps, say } = run;
|
|
12609
|
-
const generation = rotation.new.generation;
|
|
12610
|
-
if (!generation || !rotation.new.id || !rotation.old.id) {
|
|
12611
|
-
throw new Error(`rotation ${rotation.id} has no new generation or token IDs`);
|
|
12612
|
-
}
|
|
12613
|
-
const state = await loadState(deps.files, run.statePath);
|
|
12614
|
-
const plan = planPublish({ ...planFor(run), receipts: state.receipts, generation, ids: null });
|
|
12615
|
-
const behind = plan.steps.filter((step) => step.action === "write");
|
|
12616
|
-
for (const step of behind) {
|
|
12617
|
-
say(` ${step.destinationId} doesn't have generation ${generation}: ${step.reason}`);
|
|
12618
|
-
}
|
|
12619
|
-
const retired = plan.removed.filter((removed) => removed.lastReceipt.generation === rotation.old.generation);
|
|
12620
|
-
if (behind.length) {
|
|
12621
|
-
say(`Stopped: run keypin publish ${key.name}${envFlag(environment, publishEnvironment(run.map))} first. Nothing was revoked.`);
|
|
12622
|
-
return 1;
|
|
12623
|
-
}
|
|
12624
|
-
say(`The receipts on this machine show every destination of ${key.name} (${environment}) got generation ${generation}.`);
|
|
12625
|
-
for (const removed of retired) {
|
|
12626
|
-
say(` ${removed.destinationId} left the map and its receipt has the old token (generation ${removed.lastReceipt.generation}); revoking breaks it unless that secret is gone`);
|
|
12627
|
-
}
|
|
12628
|
-
const others = await otherHolders(run, state.receipts, rotation.old.generation, retired);
|
|
12629
|
-
if (others === null)
|
|
12630
|
-
return 1;
|
|
12631
|
-
if (others.length) {
|
|
12632
|
-
say(`Stopped: these destinations still have the old token. Put the new value in each one's vault item, then run its keypin publish. Nothing was revoked.`);
|
|
12633
|
-
for (const { receipt, owner } of others) {
|
|
12634
|
-
say(` ${describeHolder(receipt)}: ${publishCommand(owner)}`);
|
|
12635
|
-
}
|
|
12636
|
-
return 1;
|
|
12637
|
-
}
|
|
12638
|
-
if (!deps.isTerminal && !run.plan) {
|
|
12639
|
-
say("Stopped: revoking needs yes typed in a terminal, and --yes can't give it. Nothing was revoked.");
|
|
12640
|
-
say(rerun(deps, "rotate", run.args));
|
|
12641
|
-
return NEEDS_APPROVAL;
|
|
12642
|
-
}
|
|
12643
|
-
announce(deps.stderr, "the current value, to check it's the new token, and the admin token", [
|
|
12644
|
-
run.entry.ref,
|
|
12645
|
-
spec.admin
|
|
12646
|
-
]);
|
|
12647
|
-
const holds = await generationOf(await deps.vault().read(run.entry.ref));
|
|
12648
|
-
if (holds !== generation) {
|
|
12649
|
-
say(`Stopped: ${formatReference(run.entry.ref)} holds generation ${holds}, not the new ${generation}. Something else changed it, and revoking would leave it with a dead token. Nothing was revoked.`);
|
|
12650
|
-
return 1;
|
|
12651
|
-
}
|
|
12652
|
-
const provider = deps.provider(spec, await deps.vault().read(spec.admin));
|
|
12653
|
-
const current = await provider.details(rotation.new.id);
|
|
12654
|
-
if (current?.status !== "active") {
|
|
12655
|
-
say(`Stopped: the new token ${rotation.new.id} is ${current ? current.status : "gone"}. Nothing was revoked.`);
|
|
12656
|
-
return 1;
|
|
12657
|
-
}
|
|
12658
|
-
const old = await provider.details(rotation.old.id);
|
|
12659
|
-
if (!old) {
|
|
12660
|
-
say(`The old token ${rotation.old.id} is already gone.`);
|
|
12661
|
-
if (!run.plan)
|
|
12662
|
-
return finish(run, data, rotation);
|
|
12663
|
-
say("The next run records this rotation as finished, and asks nothing.");
|
|
12664
|
-
return planOnly(deps, "rotate", run.args, true);
|
|
12665
|
-
}
|
|
12666
|
-
say(`
|
|
12667
|
-
Old token: ${old.id} "${old.name}", ${old.status}, expires ${old.expiresOn ?? "never"}`);
|
|
12668
|
-
say(` last used: ${old.lastUsedOn ?? "not reported"}`);
|
|
12669
|
-
say(`New token: ${current.id} "${current.name}", ${current.status}, expires ${current.expiresOn ?? "never"}`);
|
|
12670
|
-
if (run.plan)
|
|
12671
|
-
return planOnly(deps, "rotate", run.args, true);
|
|
12672
|
-
const answer = await deps.ask(`Type yes to revoke the old token ${old.id}: `);
|
|
12673
|
-
if (answer.trim() !== "yes") {
|
|
12674
|
-
say("Not confirmed. Nothing was revoked.");
|
|
12675
|
-
return NEEDS_APPROVAL;
|
|
12676
|
-
}
|
|
12677
|
-
say(` ${await provider.revoke(old.id)} ${old.id}`);
|
|
12678
|
-
return finish(run, data, rotation);
|
|
12679
|
-
}
|
|
12680
|
-
async function finish(run, data, rotation) {
|
|
12681
|
-
const done = { ...rotation, stage: "revoked", updatedAt: run.deps.now().toISOString() };
|
|
12682
|
-
await saveRotations(run.deps.files, run.rotationsPath, putRotation(data, done));
|
|
12683
|
-
run.say(`Rotated ${run.key.name} (${run.environment}): ${rotation.new.id} replaced ${rotation.old.id}.`);
|
|
12684
|
-
return 0;
|
|
12685
|
-
}
|
|
12686
|
-
async function abandon(run, data, rotation) {
|
|
12687
|
-
const { entry, spec, deps, say } = run;
|
|
12688
|
-
if (rotation.new.generation) {
|
|
12689
|
-
announce(deps.stderr, "the current value, to see which token it holds", [entry.ref]);
|
|
12690
|
-
const holds = await generationOf(await deps.vault().read(entry.ref));
|
|
12691
|
-
if (holds === rotation.new.generation) {
|
|
12692
|
-
const stored = {
|
|
12693
|
-
...rotation,
|
|
12694
|
-
stage: "stored",
|
|
12695
|
-
updatedAt: deps.now().toISOString()
|
|
12696
|
-
};
|
|
12697
|
-
const next = putRotation(data, stored);
|
|
12698
|
-
if (!run.plan)
|
|
12699
|
-
await saveRotations(deps.files, run.rotationsPath, next);
|
|
12700
|
-
say(`${formatReference(entry.ref)} already holds the new value (generation ${holds}).`);
|
|
12701
|
-
return publishNew(run, next, stored, null);
|
|
12702
|
-
}
|
|
12703
|
-
if (holds !== rotation.old.generation) {
|
|
12704
|
-
say(`Stopped: ${formatReference(entry.ref)} holds generation ${holds}, neither the old ${rotation.old.generation} nor the new ${rotation.new.generation}. Something else changed it. Nothing was changed.`);
|
|
12705
|
-
return 1;
|
|
12706
|
-
}
|
|
12707
|
-
}
|
|
12708
|
-
if (rotation.new.generation) {
|
|
12709
|
-
const state = await loadState(deps.files, run.statePath);
|
|
12710
|
-
const holders = holdersOf(state.receipts, rotation.new.generation);
|
|
12711
|
-
if (holders.length) {
|
|
12712
|
-
say(`Stopped: the new token ${rotation.new.id} was published, so keypin won't delete it. Nothing was changed. Either put the new value back in ${formatReference(entry.ref)} and run ${again(run)} again to finish, or publish the old value to each destination that has the new one:`);
|
|
12713
|
-
const owners = await listedOwners(run);
|
|
12714
|
-
if (owners === null)
|
|
12715
|
-
return 1;
|
|
12716
|
-
for (const r of holders) {
|
|
12717
|
-
const owner = ownerOf2(r, owners);
|
|
12718
|
-
say(` ${describeHolder(r)}: ${owner ? publishCommand(owner) : "no registered map lists it; set that secret to the old value by hand"}`);
|
|
12719
|
-
}
|
|
12720
|
-
return 1;
|
|
12721
|
-
}
|
|
12722
|
-
}
|
|
12723
|
-
say(`It stopped before the new value was stored, so the old token ${rotation.old.id} still works everywhere.`);
|
|
12724
|
-
if (run.plan) {
|
|
12725
|
-
say(rotation.new.id ? `The next run deletes the new token ${rotation.new.id} and forgets this rotation.` : `Cloudflare may have made a token named "${rotation.new.name}". The next run can't delete it: find it under Account API tokens and delete it, then the next run forgets this rotation.`);
|
|
12726
|
-
return planOnly(deps, "rotate", run.args, true);
|
|
12727
|
-
}
|
|
12728
|
-
if (!deps.isTerminal) {
|
|
12729
|
-
say("Stopped: cleaning it up needs yes typed in a terminal. Nothing was changed.");
|
|
12730
|
-
say(rerun(deps, "rotate", run.args));
|
|
12731
|
-
return NEEDS_APPROVAL;
|
|
12732
|
-
}
|
|
12733
|
-
const id = rotation.new.id;
|
|
12734
|
-
if (!id) {
|
|
12735
|
-
say(`Cloudflare may have made a token named "${rotation.new.name}". Look for it under Account API tokens and delete it if it's there.`);
|
|
12736
|
-
if ((await deps.ask("Type yes to forget this rotation: ")).trim() !== "yes") {
|
|
12737
|
-
say("Not confirmed. Nothing was changed.");
|
|
12738
|
-
return NEEDS_APPROVAL;
|
|
12739
|
-
}
|
|
12740
|
-
} else {
|
|
12741
|
-
announce(deps.stderr, "the admin token", [spec.admin]);
|
|
12742
|
-
const provider = deps.provider(spec, await deps.vault().read(spec.admin));
|
|
12743
|
-
const made = await provider.details(id);
|
|
12744
|
-
if (made) {
|
|
12745
|
-
say(`New token: ${made.id} "${made.name}", ${made.status}, its value was never stored`);
|
|
12746
|
-
if ((await deps.ask(`Type yes to delete the new token ${made.id}: `)).trim() !== "yes") {
|
|
12747
|
-
say("Not confirmed. Nothing was changed.");
|
|
12748
|
-
return NEEDS_APPROVAL;
|
|
12749
|
-
}
|
|
12750
|
-
say(` ${await provider.revoke(made.id)} ${made.id}`);
|
|
12751
|
-
} else {
|
|
12752
|
-
say(`The new token ${id} is already gone.`);
|
|
12753
|
-
}
|
|
12754
|
-
}
|
|
12755
|
-
await saveRotations(deps.files, run.rotationsPath, dropRotation(data, rotation.id));
|
|
12756
|
-
say(`Cleared. Run ${again(run)} again to start over.`);
|
|
12757
|
-
return 1;
|
|
12758
|
-
}
|
|
12759
|
-
async function deleteUnchecked(run, data, rotation, provider) {
|
|
12760
|
-
const id = rotation.new.id;
|
|
12761
|
-
if (!id)
|
|
12762
|
-
throw new Error(`rotation ${rotation.id} has no new token ID`);
|
|
12763
|
-
try {
|
|
12764
|
-
run.say(` ${await provider.revoke(id)} ${id}, the token this run made`);
|
|
12765
|
-
} catch (error) {
|
|
12766
|
-
run.say(`Couldn't delete the new token ${id}: ${messageOf(error)}.`);
|
|
12767
|
-
run.say(`Nothing else was changed, and the old token still works everywhere. Run ${again(run)} again to delete it.`);
|
|
12768
|
-
return 1;
|
|
12769
|
-
}
|
|
12770
|
-
await saveRotations(run.deps.files, run.rotationsPath, dropRotation(data, rotation.id));
|
|
12771
|
-
run.say("Stopped. Nothing else was changed, and the old token still works everywhere.");
|
|
12772
|
-
return 1;
|
|
12773
|
-
}
|
|
12774
|
-
async function recheck(run, rotation, value) {
|
|
12775
|
-
if (!rotation.new.id || !rotation.old.id)
|
|
12776
|
-
return "the rotation has no token IDs";
|
|
12777
|
-
const provider = run.deps.provider(run.spec, await run.deps.vault().read(run.spec.admin));
|
|
12778
|
-
const old = await provider.details(rotation.old.id);
|
|
12779
|
-
if (!old)
|
|
12780
|
-
return `the old token ${rotation.old.id} is gone, so its policies can't be compared`;
|
|
12781
|
-
return checkNew(provider, rotation.new.id, value, old);
|
|
12782
|
-
}
|
|
12783
|
-
function holdersOf(receipts, generation) {
|
|
12784
|
-
return latestPerSecret(receipts).filter((r) => r.generation === generation);
|
|
12785
|
-
}
|
|
12786
|
-
function describeHolder(receipt) {
|
|
12787
|
-
return `${receipt.destinationId} (${receipt.keyId}, ${receipt.environment})`;
|
|
12788
|
-
}
|
|
12789
|
-
function publishCommand(owner) {
|
|
12790
|
-
const env = envFlag(owner.environment, owner.publishDefault);
|
|
12791
|
-
const where = owner.project === null ? "" : `cd ${shellWord(owner.project)} && `;
|
|
12792
|
-
return `${where}keypin publish ${owner.keyId}${env}`;
|
|
12793
|
-
}
|
|
12794
|
-
async function listedOwners(run) {
|
|
12795
|
-
const { deps, say } = run;
|
|
12796
|
-
const owners = new Map;
|
|
12797
|
-
const list = (map, project) => {
|
|
12798
|
-
for (const k of map.keys) {
|
|
12799
|
-
for (const [name, entry] of Object.entries(k.environments)) {
|
|
12800
|
-
for (const target of entry?.publish ?? []) {
|
|
12801
|
-
const secret = secretKey(target, k.name);
|
|
12802
|
-
owners.set(secret, [
|
|
12803
|
-
...owners.get(secret) ?? [],
|
|
12804
|
-
{
|
|
12805
|
-
project,
|
|
12806
|
-
keyId: k.name,
|
|
12807
|
-
environment: name,
|
|
12808
|
-
mapFile: map.file,
|
|
12809
|
-
publishDefault: publishEnvironment(map)
|
|
12810
|
-
}
|
|
12811
|
-
]);
|
|
12812
|
-
}
|
|
12813
|
-
}
|
|
12814
|
-
}
|
|
12815
|
-
};
|
|
12816
|
-
list(run.map, null);
|
|
12817
|
-
const registry = await loadRegistry(deps.files, registryPath(deps));
|
|
12818
|
-
for (const project of registry.projects) {
|
|
12819
|
-
const file = join7(project, MAP_FILE);
|
|
12820
|
-
if (file === run.map.file)
|
|
12821
|
-
continue;
|
|
12822
|
-
const text = await deps.files.read(file);
|
|
12823
|
-
const result = text === null ? null : parseMap(text, file);
|
|
12824
|
-
if (!result?.ok) {
|
|
12825
|
-
say(`Stopped: ${file} ${result ? "has errors" : "is missing"}, so keypin can't tell which keys use these destinations. Fix it or run keypin unregister ${shellWord(project)}. Nothing was changed.`);
|
|
12826
|
-
return null;
|
|
12827
|
-
}
|
|
12828
|
-
list(result.map, project);
|
|
12829
|
-
}
|
|
12830
|
-
return owners;
|
|
12831
|
-
}
|
|
12832
|
-
function ownerOf2(receipt, owners) {
|
|
12833
|
-
const found = owners.get(receiptSecretKey(receipt)) ?? [];
|
|
12834
|
-
return found.find((o) => ownedBy(receipt, o)) ?? found.find((o) => o.keyId === receipt.keyId && o.environment === receipt.environment) ?? found[0];
|
|
12835
|
-
}
|
|
12836
|
-
var UNLISTED = "no registered map lists it any more; revoking breaks it unless that secret is gone";
|
|
12837
|
-
async function otherHolders(run, receipts, generation, retired) {
|
|
12838
|
-
const owners = await listedOwners(run);
|
|
12839
|
-
if (owners === null)
|
|
12840
|
-
return null;
|
|
12841
|
-
const shown = new Set(retired.map((r) => r.destinationId));
|
|
12842
|
-
return holdersOf(receipts, generation).flatMap((receipt) => {
|
|
12843
|
-
const owner = ownerOf2(receipt, owners);
|
|
12844
|
-
if (owner)
|
|
12845
|
-
return [{ receipt, owner }];
|
|
12846
|
-
if (!shown.has(receipt.destinationId)) {
|
|
12847
|
-
run.say(` ${describeHolder(receipt)} has the old token, and ${UNLISTED}`);
|
|
12848
|
-
}
|
|
12849
|
-
return [];
|
|
12850
|
-
});
|
|
12851
|
-
}
|
|
12852
|
-
function again(run) {
|
|
12853
|
-
return rotateCommand(run.key.name, run.environment, publishEnvironment(run.map));
|
|
12854
|
-
}
|
|
12855
|
-
async function checkNew(provider, id, value, old) {
|
|
12856
|
-
try {
|
|
12857
|
-
const seen = await provider.verify(value);
|
|
12858
|
-
if (seen.id !== id)
|
|
12859
|
-
return `the new value verifies as token ${seen.id}, not ${id}`;
|
|
12860
|
-
if (seen.status !== "active")
|
|
12861
|
-
return `the new token is ${seen.status}`;
|
|
12862
|
-
const made = await provider.details(id);
|
|
12863
|
-
if (!made)
|
|
12864
|
-
return "the admin token can't read the new token";
|
|
12865
|
-
if (!sameAccess(made, old))
|
|
12866
|
-
return `its policies differ from ${old.id}'s`;
|
|
12867
|
-
return null;
|
|
12868
|
-
} catch (error) {
|
|
12869
|
-
return messageOf(error);
|
|
12870
|
-
}
|
|
12871
|
-
}
|
|
12872
|
-
async function confirmed3(run, needsApproval, what) {
|
|
12873
|
-
const { deps, say } = run;
|
|
12874
|
-
if (run.yes && !needsApproval)
|
|
12875
|
-
return true;
|
|
12876
|
-
if (deps.isTerminal) {
|
|
12877
|
-
const answer = await deps.ask(`Type yes to ${what}${needsApproval ? " (this plan needs approval)" : ""}: `);
|
|
12878
|
-
if (answer.trim() === "yes")
|
|
12879
|
-
return true;
|
|
12880
|
-
say("Not confirmed. Nothing was changed.");
|
|
12881
|
-
return false;
|
|
12882
|
-
}
|
|
12883
|
-
say("Stopped: this plan needs approval, and --yes can't give it. Nothing was changed.");
|
|
12884
|
-
say(rerun(deps, "rotate", run.args));
|
|
12885
|
-
return false;
|
|
12886
|
-
}
|
|
12887
|
-
function withoutFinished(data, owner) {
|
|
12888
|
-
return {
|
|
12889
|
-
...data,
|
|
12890
|
-
rotations: data.rotations.filter((r) => !(ownedBy(r, owner) && r.stage === "revoked"))
|
|
12891
|
-
};
|
|
12892
|
-
}
|
|
12893
|
-
function keyOwner(run) {
|
|
12894
|
-
return { keyId: run.key.name, environment: run.environment, mapFile: run.map.file };
|
|
12895
|
-
}
|
|
12896
|
-
async function idsBeforeReading(run) {
|
|
12897
|
-
try {
|
|
12898
|
-
const [ids] = await lookUpIds(run.deps, [run.entry.ref]);
|
|
12899
|
-
return ids ?? null;
|
|
12900
|
-
} catch (error) {
|
|
12901
|
-
run.say(`Stopped: couldn't find the item: ${messageOf(error)}. Nothing was changed.`);
|
|
12902
|
-
return null;
|
|
12903
|
-
}
|
|
12904
|
-
}
|
|
12905
|
-
function planFor(run) {
|
|
12906
|
-
return { key: run.key, environment: run.environment, mapFile: run.map.file };
|
|
12907
|
-
}
|
|
12908
|
-
var DATED = /^(.*) (\d{4}-\d{2}-\d{2})(?: #(\d+))?$/;
|
|
12909
|
-
function nextName(old, today) {
|
|
12910
|
-
const match = DATED.exec(old);
|
|
12911
|
-
const base = match?.[1] ?? old;
|
|
12912
|
-
if (match?.[2] !== today)
|
|
12913
|
-
return `${base} ${today}`;
|
|
12914
|
-
return `${base} ${today} #${Number(match[3] ?? 1) + 1}`;
|
|
12915
|
-
}
|
|
12916
|
-
function describeAccess(token) {
|
|
12917
|
-
const lines = ["policies it copies:"];
|
|
12918
|
-
for (const policy of token.policies) {
|
|
12919
|
-
const groups = policy.permissionGroups.map((g) => g.name).join(", ");
|
|
12920
|
-
lines.push(` ${policy.effect} ${groups}`);
|
|
12921
|
-
for (const [resource, scope] of Object.entries(policy.resources)) {
|
|
12922
|
-
lines.push(` on ${resource}: ${JSON.stringify(scope)}`);
|
|
12923
|
-
}
|
|
12924
|
-
}
|
|
12925
|
-
lines.push(`condition: ${token.condition ? JSON.stringify(token.condition) : "none"}`);
|
|
12926
|
-
return lines;
|
|
12927
|
-
}
|
|
12928
|
-
|
|
12929
12019
|
// src/commands/run.ts
|
|
12930
|
-
import { dirname as
|
|
12931
|
-
import { parseArgs as
|
|
12020
|
+
import { dirname as dirname3, join as join7, relative as relative2 } from "path";
|
|
12021
|
+
import { parseArgs as parseArgs6 } from "util";
|
|
12932
12022
|
async function run(args, deps) {
|
|
12933
|
-
const { values, positionals } =
|
|
12023
|
+
const { values, positionals } = parseArgs6({
|
|
12934
12024
|
args,
|
|
12935
12025
|
options: { env: { type: "string" } },
|
|
12936
12026
|
allowPositionals: true
|
|
@@ -12980,7 +12070,7 @@ async function run(args, deps) {
|
|
|
12980
12070
|
`);
|
|
12981
12071
|
return 1;
|
|
12982
12072
|
}
|
|
12983
|
-
await warnAboutEnvFiles(deps, [...new Set([
|
|
12073
|
+
await warnAboutEnvFiles(deps, [...new Set([dirname3(map.file), deps.cwd])], keys.map((k) => k.key.name));
|
|
12984
12074
|
let child;
|
|
12985
12075
|
try {
|
|
12986
12076
|
child = deps.launch(positionals, env);
|
|
@@ -13004,7 +12094,7 @@ async function warnAboutEnvFiles(deps, folders, mapped) {
|
|
|
13004
12094
|
for (const entry of entries.toSorted((a, b) => a.name.localeCompare(b.name))) {
|
|
13005
12095
|
if (entry.kind !== "file" || envFileKind(entry.name) !== "set")
|
|
13006
12096
|
continue;
|
|
13007
|
-
const path =
|
|
12097
|
+
const path = join7(folder, entry.name);
|
|
13008
12098
|
const text = await deps.files.read(path).catch(() => null);
|
|
13009
12099
|
if (text === null)
|
|
13010
12100
|
continue;
|
|
@@ -13024,10 +12114,10 @@ function envFileWarning(name, file, keys) {
|
|
|
13024
12114
|
}
|
|
13025
12115
|
|
|
13026
12116
|
// src/commands/status.ts
|
|
13027
|
-
import { join as
|
|
13028
|
-
import { parseArgs as
|
|
12117
|
+
import { join as join8 } from "path";
|
|
12118
|
+
import { parseArgs as parseArgs7 } from "util";
|
|
13029
12119
|
async function status(args, deps) {
|
|
13030
|
-
const { values, positionals } =
|
|
12120
|
+
const { values, positionals } = parseArgs7({
|
|
13031
12121
|
args,
|
|
13032
12122
|
options: { json: { type: "boolean", default: false } },
|
|
13033
12123
|
allowPositionals: true
|
|
@@ -13036,10 +12126,9 @@ async function status(args, deps) {
|
|
|
13036
12126
|
throw new UsageError("keypin status takes no arguments");
|
|
13037
12127
|
const registry = await loadRegistry(deps.files, registryPath(deps));
|
|
13038
12128
|
const state = await loadState(deps.files, statePath(deps));
|
|
13039
|
-
const { rotations } = await loadRotations(deps.files, rotationsPath(deps));
|
|
13040
12129
|
const maps = new Map;
|
|
13041
12130
|
for (const project of registry.projects) {
|
|
13042
|
-
const file =
|
|
12131
|
+
const file = join8(project, MAP_FILE);
|
|
13043
12132
|
try {
|
|
13044
12133
|
const text = await deps.files.read(file);
|
|
13045
12134
|
if (text !== null)
|
|
@@ -13068,7 +12157,6 @@ async function status(args, deps) {
|
|
|
13068
12157
|
registry,
|
|
13069
12158
|
maps,
|
|
13070
12159
|
receipts: state.receipts,
|
|
13071
|
-
rotations,
|
|
13072
12160
|
metadata: (ref) => metadata.get(refKey(ref)) ?? null,
|
|
13073
12161
|
today: localDay(deps.now())
|
|
13074
12162
|
});
|
|
@@ -13131,9 +12219,9 @@ function render3(result, projects) {
|
|
|
13131
12219
|
|
|
13132
12220
|
// src/commands/unregister.ts
|
|
13133
12221
|
import { resolve as resolve5 } from "path";
|
|
13134
|
-
import { parseArgs as
|
|
12222
|
+
import { parseArgs as parseArgs8 } from "util";
|
|
13135
12223
|
async function unregister2(args, deps) {
|
|
13136
|
-
const { positionals } =
|
|
12224
|
+
const { positionals } = parseArgs8({ args, options: {}, allowPositionals: true });
|
|
13137
12225
|
if (positionals.length > 1)
|
|
13138
12226
|
throw new UsageError("keypin unregister takes at most one folder");
|
|
13139
12227
|
const folder = resolve5(deps.cwd, positionals[0] ?? ".");
|
|
@@ -13152,7 +12240,7 @@ async function unregister2(args, deps) {
|
|
|
13152
12240
|
return 0;
|
|
13153
12241
|
}
|
|
13154
12242
|
// ../../package.json
|
|
13155
|
-
var version = "0.
|
|
12243
|
+
var version = "0.9.0";
|
|
13156
12244
|
|
|
13157
12245
|
// src/cli.ts
|
|
13158
12246
|
var USAGE = `Usage:
|
|
@@ -13167,10 +12255,11 @@ var USAGE = `Usage:
|
|
|
13167
12255
|
keypin check [folder] [--json]
|
|
13168
12256
|
check a project's map, vault items and logins without writing anything:
|
|
13169
12257
|
each item and field exists, each login reaches the pinned account
|
|
13170
|
-
keypin import <env-file> --vault <vault> [--account <sign-in address>] [--yes]
|
|
13171
|
-
move an env file's values into new 1Password items and map them
|
|
13172
|
-
account is the map's, or --account
|
|
13173
|
-
overwrites an item, so --yes is enough
|
|
12258
|
+
keypin import <env-file> [NAME...] --vault <vault> [--account <sign-in address>] [--yes]
|
|
12259
|
+
move an env file's values into new 1Password items and map them: only
|
|
12260
|
+
the named variables, or every one; the account is the map's, or --account
|
|
12261
|
+
when there's no map yet. It never overwrites an item, so --yes is enough
|
|
12262
|
+
to approve it. The file stays.
|
|
13174
12263
|
keypin run [--env <name>] -- <command>
|
|
13175
12264
|
run a command with one environment's keys (default: the first, dev)
|
|
13176
12265
|
keypin publish <VARIABLE> [--env <name>] [--yes | --plan]
|
|
@@ -13179,10 +12268,6 @@ var USAGE = `Usage:
|
|
|
13179
12268
|
the plan and the command to approve it, and writes nothing
|
|
13180
12269
|
keypin publish --all [--env <name>] [--yes | --plan]
|
|
13181
12270
|
the same for every key with destinations, with one plan and one approval
|
|
13182
|
-
keypin rotate <VARIABLE> [--env <name>] [--yes | --plan]
|
|
13183
|
-
replace a token with a new one that has the same permissions, publish it,
|
|
13184
|
-
and revoke the old one on the next run; --plan reads and checks the tokens,
|
|
13185
|
-
prints this run's plan and the command to approve it, and changes nothing
|
|
13186
12271
|
keypin --version print the version
|
|
13187
12272
|
|
|
13188
12273
|
Exit codes:
|
|
@@ -13201,8 +12286,7 @@ var COMMANDS = new Map([
|
|
|
13201
12286
|
["check", check],
|
|
13202
12287
|
["import", importEnv],
|
|
13203
12288
|
["run", run],
|
|
13204
|
-
["publish", publish]
|
|
13205
|
-
["rotate", rotate]
|
|
12289
|
+
["publish", publish]
|
|
13206
12290
|
]);
|
|
13207
12291
|
async function cli(argv, deps) {
|
|
13208
12292
|
const [name, ...args] = argv;
|
|
@@ -13244,7 +12328,7 @@ ${USAGE}`);
|
|
|
13244
12328
|
import { constants, rmSync } from "fs";
|
|
13245
12329
|
import { execFile as execFile3 } from "child_process";
|
|
13246
12330
|
import { chmod, lstat, mkdir, open, readdir, rename, rm, stat } from "fs/promises";
|
|
13247
|
-
import { dirname as
|
|
12331
|
+
import { dirname as dirname4 } from "path";
|
|
13248
12332
|
|
|
13249
12333
|
// src/launch.ts
|
|
13250
12334
|
var launch = (command, env) => {
|
|
@@ -13281,7 +12365,7 @@ var diskFiles = {
|
|
|
13281
12365
|
}
|
|
13282
12366
|
},
|
|
13283
12367
|
async write(path, text) {
|
|
13284
|
-
await privateFolder(
|
|
12368
|
+
await privateFolder(dirname4(path));
|
|
13285
12369
|
const handle = await open(path, PRIVATE_WRITE, 384);
|
|
13286
12370
|
try {
|
|
13287
12371
|
await handle.chmod(384);
|
|
@@ -13423,7 +12507,7 @@ function git(folder, args) {
|
|
|
13423
12507
|
});
|
|
13424
12508
|
}
|
|
13425
12509
|
var diskLock = async (path) => {
|
|
13426
|
-
await privateFolder(
|
|
12510
|
+
await privateFolder(dirname4(path));
|
|
13427
12511
|
if (await take(path))
|
|
13428
12512
|
return { held: true, lock: held(path) };
|
|
13429
12513
|
const pid = await holderOf(path);
|
|
@@ -13472,7 +12556,7 @@ function held(path) {
|
|
|
13472
12556
|
// src/start.ts
|
|
13473
12557
|
var vault;
|
|
13474
12558
|
var cloudflare;
|
|
13475
|
-
function
|
|
12559
|
+
function destination2(target, publisher) {
|
|
13476
12560
|
switch (target.to) {
|
|
13477
12561
|
case "cloudflare-worker":
|
|
13478
12562
|
return new WorkerSecretDestination({
|
|
@@ -13492,16 +12576,6 @@ function destination(target, publisher) {
|
|
|
13492
12576
|
}
|
|
13493
12577
|
}
|
|
13494
12578
|
}
|
|
13495
|
-
function provider(spec, admin) {
|
|
13496
|
-
switch (spec.provider) {
|
|
13497
|
-
case "cloudflare-account-token":
|
|
13498
|
-
return new CloudflareAccountTokens({ account: spec.account, admin });
|
|
13499
|
-
default: {
|
|
13500
|
-
const unknown = spec.provider;
|
|
13501
|
-
throw new Error(`unknown provider ${JSON.stringify(unknown)}`);
|
|
13502
|
-
}
|
|
13503
|
-
}
|
|
13504
|
-
}
|
|
13505
12579
|
var connect = (account) => desktopConnect(account).catch((error) => {
|
|
13506
12580
|
const hint = installProblem(error);
|
|
13507
12581
|
throw hint ? new Error(hint) : error;
|
|
@@ -13537,15 +12611,22 @@ function main() {
|
|
|
13537
12611
|
stderr: process.stderr,
|
|
13538
12612
|
launch,
|
|
13539
12613
|
onSignals,
|
|
13540
|
-
destination,
|
|
13541
|
-
|
|
13542
|
-
|
|
12614
|
+
destination: destination2,
|
|
12615
|
+
wranglerLoginFile: async () => {
|
|
12616
|
+
try {
|
|
12617
|
+
const file = wranglerConfigFile();
|
|
12618
|
+
await access(file);
|
|
12619
|
+
return file;
|
|
12620
|
+
} catch {
|
|
12621
|
+
return null;
|
|
12622
|
+
}
|
|
12623
|
+
},
|
|
13543
12624
|
lock: diskLock,
|
|
13544
12625
|
isTerminal: Boolean(process.stdin.isTTY),
|
|
13545
12626
|
ask
|
|
13546
12627
|
});
|
|
13547
12628
|
}
|
|
13548
12629
|
export {
|
|
13549
|
-
destination,
|
|
12630
|
+
destination2 as destination,
|
|
13550
12631
|
main
|
|
13551
12632
|
};
|