Skip to content

Commit 488ef19

Browse files
committed
fix: handle secret store race conditions and normalize names
- Add .toLowerCase() to Cloudflare worker and KV namespace names - Add duplicate handling for Fastly secret store creation race condition - Remove explicit package.name override from edge integration test 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Signed-off-by: Lars Trieloff <[email protected]>
1 parent 90dfa42 commit 488ef19

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

src/CloudflareDeployer.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ export default class CloudflareDeployer extends BaseDeployer {
3838
get fullFunctionName() {
3939
return `${this.cfg.packageName}--${this.cfg.name}`
4040
.replace(/\./g, '_')
41-
.replace('@', '_');
41+
.replace('@', '_')
42+
.toLowerCase();
4243
}
4344

4445
async deploy() {
4546
const body = fs.readFileSync(this.cfg.edgeBundle);
4647
const settings = await this.getSettings();
47-
const { id } = await this.createKVNamespace(`${this.cfg.packageName}--secrets`);
48+
const { id } = await this.createKVNamespace(`${this.cfg.packageName}--secrets`.toLowerCase());
4849

4950
const metadata = {
5051
body_part: 'script',

src/ComputeAtEdgeDeployer.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,28 @@ service_id = ""
123123
this.log.debug('--: uploading package to fastly, service version', version);
124124
await this._fastly.writePackage(version, buf);
125125

126+
// Helper to get or create secret store with duplicate handling
127+
const getOrCreateSecretStore = async (name) => {
128+
try {
129+
return await this._fastly.writeSecretStore(name);
130+
} catch (error) {
131+
if (error.message && error.message.includes('duplicate')) {
132+
// Store was created between list and create, retry to get it
133+
this.log.debug(`--: secret store ${name} already exists, fetching...`);
134+
const stores = await this._fastly.readSecretStores();
135+
const existing = stores.data?.data?.find((s) => s.name === name);
136+
if (existing) {
137+
return { data: existing };
138+
}
139+
}
140+
throw error;
141+
}
142+
};
143+
126144
// Get or create action secret store (for action-specific params)
127145
const actionStoreName = this.fullFunctionName;
128146
this.log.debug(`--: getting or creating action secret store: ${actionStoreName}`);
129-
const actionStore = await this._fastly.writeSecretStore(actionStoreName);
147+
const actionStore = await getOrCreateSecretStore(actionStoreName);
130148
const actionStoreId = actionStore.data.id;
131149
try {
132150
await this._fastly.writeResource(version, actionStoreId, 'action_secrets');
@@ -141,7 +159,7 @@ service_id = ""
141159
// Get or create package secret store (for package-wide params)
142160
const packageStoreName = this.cfg.packageName;
143161
this.log.debug(`--: getting or creating package secret store: ${packageStoreName}`);
144-
const packageStore = await this._fastly.writeSecretStore(packageStoreName);
162+
const packageStore = await getOrCreateSecretStore(packageStoreName);
145163
const packageStoreId = packageStore.data.id;
146164
try {
147165
await this._fastly.writeResource(version, packageStoreId, 'package_secrets');

test/edge-integration.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ describe('Edge Integration Test', () => {
7171
// Fastly config
7272
'--compute-service-id', fastlyServiceID,
7373
'--compute-test-domain', fastlyTestDomain,
74-
'--package.name', 'Test',
7574
'--fastly-gateway', 'deploy-test.anywhere.run',
7675
'--fastly-service-id', '4u8SAdblhzzbXntBYCjhcK',
7776
// Shared config

0 commit comments

Comments
 (0)