Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/local/env-sync/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ async function syncEnvVars(options: {
plan.envLocalAutoCreates.length > 0
? await computePlanAsync(repoRoot, serviceFilter, refreshSourceBackedSecrets)
: plan;
await applyPlan(applyReadyPlan, repoRoot, { missingSecretsOnly });
await applyPlan(applyReadyPlan, repoRoot);
console.log(`\n${GREEN}✓ Applied${RESET}`);
} else {
console.log('Skipped.');
Expand Down
23 changes: 8 additions & 15 deletions dev/local/env-sync/output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ function secretCreate(workerDir: string, secretName: string): SecretStoreAutoCre
};
}

test('creates missing secrets concurrently across stores and rechecks existing secrets', async () => {
test('creates planned secrets concurrently across stores without re-listing them', async () => {
const repoRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'env-sync-output-'));
const existing = secretCreate('services/event-service', 'EXISTING_SECRET');
const missing = secretCreate('services/model-eval-ingest', 'MISSING_SECRET');
for (const create of [existing, missing]) {
const first = secretCreate('services/event-service', 'FIRST_SECRET');
const second = secretCreate('services/model-eval-ingest', 'SECOND_SECRET');
for (const create of [first, second]) {
fs.mkdirSync(path.join(repoRoot, create.workerDir, '.wrangler'), { recursive: true });
}

Expand All @@ -33,7 +33,7 @@ test('creates missing secrets concurrently across stores and rechecks existing s
envDevLocalChanges: [],
envLocalAutoCreates: [],
secretStoreWarnings: [],
secretStoreAutoCreates: [existing, missing],
secretStoreAutoCreates: [first, second],
consistencyWarnings: [],
execWarnings: [],
missingEnvLocal: false,
Expand All @@ -44,20 +44,13 @@ test('creates missing secrets concurrently across stores and rechecks existing s
try {
await applyPlan(plan, repoRoot, {
concurrency: 2,
missingSecretsOnly: true,
runWrangler: async (_repoRoot, workerDir, args, input) => {
runWrangler: async (_repoRoot, _workerDir, args, input) => {
active++;
maxActive = Math.max(maxActive, active);
await new Promise(resolve => setTimeout(resolve, 20));
active--;

if (args.includes('list')) {
return {
status: 0,
stderr: '',
stdout: workerDir === existing.workerDir ? 'EXISTING_SECRET\n' : '',
};
}
assert.ok(!args.includes('list'));
assert.ok(input?.startsWith('value-for-'));
assert.ok(!args.some(arg => arg.startsWith('value-for-')));
created.push(args[args.indexOf('--name') + 1] ?? '');
Expand All @@ -66,7 +59,7 @@ test('creates missing secrets concurrently across stores and rechecks existing s
});

assert.equal(maxActive, 2);
assert.deepEqual(created, ['MISSING_SECRET']);
assert.deepEqual(created.sort(), ['FIRST_SECRET', 'SECOND_SECRET']);
} finally {
fs.rmSync(repoRoot, { recursive: true, force: true });
}
Expand Down
29 changes: 1 addition & 28 deletions dev/local/env-sync/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ type WranglerRunner = typeof runWrangler;

type ApplyPlanOptions = {
concurrency?: number;
missingSecretsOnly?: boolean;
runWrangler?: WranglerRunner;
};

Expand Down Expand Up @@ -331,26 +330,6 @@ function resolveWranglerPersistenceDir(repoRoot: string, workerDir: string): str
}
}

async function secretExists(
create: SecretStoreAutoCreate,
repoRoot: string,
runner: WranglerRunner = runWrangler
): Promise<boolean> {
const result = await runner(repoRoot, create.workerDir, [
'secrets-store',
'secret',
'list',
create.binding.store_id,
]);
if (result.status !== 0) {
const errorOutput = result.stderr.trim();
throw new Error(
`Failed to list Secrets Store secrets for ${create.workerDir}${errorOutput ? `: ${errorOutput}` : ''}`
);
}
return result.stdout.includes(create.binding.secret_name);
}

async function applySecretsStoreAutoCreates(
creates: SecretStoreAutoCreate[],
repoRoot: string,
Expand All @@ -377,13 +356,7 @@ async function applySecretsStoreAutoCreates(
`Secrets Store for ${group[0]?.workerDir ?? persistenceDir}`,
async () => {
for (const create of group) {
if (
options.missingSecretsOnly &&
(await secretExists(create, repoRoot, options.runWrangler))
) {
console.log(` ✓ ${create.binding.secret_name} already exists`);
continue;
}
// The plan already filtered out secrets that exist locally, so no re-listing here.
Comment thread
RSO marked this conversation as resolved.
await createSecretsStoreSecret(
repoRoot,
create.workerDir,
Expand Down