Skip to content
Prev Previous commit
Next Next commit
fix the _# generating of creds - file name
  • Loading branch information
royendo committed Jan 13, 2026
commit f873ad3fffc908c0dd3b061bd4b0d52aa07f9c8b
41 changes: 33 additions & 8 deletions web-common/src/features/sources/modal/submitAddDataForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const connectorSubmissions = new Map<
promise: Promise<void>;
connectorName: string;
completed: boolean;
originalEnvBlob?: string;
newEnvBlob?: string;
}
>();

Expand Down Expand Up @@ -160,6 +162,8 @@ async function saveConnectorAnyway(
formValues: AddDataFormValues,
newConnectorName: string,
instanceId?: string,
preComputedEnvBlob?: string,
originalEnvBlob?: string,
): Promise<void> {
const resolvedInstanceId = instanceId ?? get(runtime).instanceId;

Expand All @@ -172,14 +176,19 @@ async function saveConnectorAnyway(
// Mark to avoid rollback by concurrent submissions
savedAnywayPaths.add(newConnectorFilePath);

// Update .env file with secrets (keep ordering consistent with Test and Connect)
const newEnvBlob = await updateDotEnvWithSecrets(
queryClient,
connector,
formValues,
"connector",
newConnectorName,
);
// Use pre-computed env blob if provided to avoid re-computing and getting _1 suffix
// when the first attempt already added the variable
let newEnvBlob = preComputedEnvBlob;
if (!newEnvBlob) {
// Fallback to computing if not provided (for backwards compatibility)
newEnvBlob = await updateDotEnvWithSecrets(
queryClient,
connector,
formValues,
"connector",
newConnectorName,
);
}

await runtimeServicePutFile(resolvedInstanceId, {
path: ".env",
Expand All @@ -189,10 +198,12 @@ async function saveConnectorAnyway(
});

// Always create/overwrite to ensure the connector file is created immediately
// Use originalEnvBlob (before modifications) to check conflicts, not the modified blob
await runtimeServicePutFile(resolvedInstanceId, {
path: newConnectorFilePath,
blob: compileConnectorYAML(connector, formValues, {
connectorInstanceName: newConnectorName,
existingEnvBlob: originalEnvBlob,
}),
create: true,
createOnly: false,
Expand Down Expand Up @@ -243,12 +254,16 @@ export async function submitAddConnectorForm(
const newConnectorName = existingSubmission.connectorName;

// Proceed immediately with Save Anyway logic
// Use the pre-computed env blobs from the concurrent Test and Connect operation
// to ensure consistent variable naming (e.g., GOOGLE_APPLICATION_CREDENTIALS not _2)
await saveConnectorAnyway(
queryClient,
connector,
formValues,
newConnectorName,
instanceId,
existingSubmission.newEnvBlob,
existingSubmission.originalEnvBlob,
);
return;
} else if (!existingSubmission.completed) {
Expand Down Expand Up @@ -290,6 +305,13 @@ export async function submitAddConnectorForm(
newConnectorName,
);

// Store the computed blobs in the submission so concurrent "Save Anyway" can reuse them
const submission = connectorSubmissions.get(uniqueConnectorSubmissionKey);
if (submission) {
submission.originalEnvBlob = originalEnvBlob;
submission.newEnvBlob = newEnvBlob;
}

if (saveAnyway) {
// Save Anyway: bypass reconciliation entirely via centralized helper
await saveConnectorAnyway(
Expand All @@ -298,6 +320,8 @@ export async function submitAddConnectorForm(
formValues,
newConnectorName,
instanceId,
newEnvBlob,
originalEnvBlob,
);
return;
}
Expand All @@ -322,6 +346,7 @@ export async function submitAddConnectorForm(
path: newConnectorFilePath,
blob: compileConnectorYAML(connector, formValues, {
connectorInstanceName: newConnectorName,
existingEnvBlob: originalEnvBlob,
}),
create: true,
createOnly: false,
Expand Down
Loading