diff --git a/backend/src/services/secret/secret-fns.ts b/backend/src/services/secret/secret-fns.ts index 32860e38c..007f8cb9e 100644 --- a/backend/src/services/secret/secret-fns.ts +++ b/backend/src/services/secret/secret-fns.ts @@ -396,13 +396,34 @@ export const decryptSecretRaw = ( }; }; -export const getAllNestedSecretReferences = (value: string) => { - const references = Array.from(value.matchAll(INTERPOLATION_SYNTAX_REG), (m) => m[1]); +/** + * Grabs and processes nested secret references from a string + * + * This function looks for patterns that match the interpolation syntax in the input string. + * It filters out references that include nested paths, splits them into environment and + * secret path parts, and then returns an array of objects with the environment and the + * joined secret path. + * + * @param {string} maybeSecretReference - The string that has the potential secret references. + * @returns {Array<{ environment: string, secretPath: string }>} - An array of objects + * with the environment and joined secret path. + * + * @example + * const value = "Hello ${dev.someFolder.OtherFolder.SECRET_NAME} and ${prod.anotherFolder.SECRET_NAME}"; + * const result = getAllNestedSecretReferences(value); + * // result will be: + * // [ + * // { environment: 'dev', secretPath: '/someFolder/OtherFolder' }, + * // { environment: 'prod', secretPath: '/anotherFolder' } + * // ] + */ +export const getAllNestedSecretReferences = (maybeSecretReference: string) => { + const references = Array.from(maybeSecretReference.matchAll(INTERPOLATION_SYNTAX_REG), (m) => m[1]); return references .filter((el) => el.includes(".")) .map((el) => { - const [environment, ...secretPath] = el.split("."); - return { environment, secretPath: path.join("/", ...secretPath.slice(0, -1)) }; + const [environment, ...secretPathList] = el.split("."); + return { environment, secretPath: path.join("/", ...secretPathList.slice(0, -1)) }; }); }; diff --git a/backend/src/services/secret/secret-service.ts b/backend/src/services/secret/secret-service.ts index 37baa5ad4..aa5867c4a 100644 --- a/backend/src/services/secret/secret-service.ts +++ b/backend/src/services/secret/secret-service.ts @@ -1562,10 +1562,12 @@ export const secretServiceFactory = ({ actorOrgId ); - if (!hasRole(ProjectMembershipRole.Admin)) throw new BadRequestError({ message: "Only admins are allowed" }); + if (!hasRole(ProjectMembershipRole.Admin)) + throw new BadRequestError({ message: "Only admins are allowed to take this action" }); const botKey = await projectBotService.getBotKey(projectId); - if (!botKey) throw new BadRequestError({ message: "Kindly upgrade your project", name: "bot_not_found_error" }); + if (!botKey) + throw new BadRequestError({ message: "Please upgrade your project first", name: "bot_not_found_error" }); await secretDAL.transaction(async (tx) => { const secrets = await secretDAL.findAllProjectSecretValues(projectId, tx); @@ -1584,7 +1586,7 @@ export const secretServiceFactory = ({ ); }); - return { message: "Successfully backfilled secret references." }; + return { message: "Successfully backfilled secret references" }; }; return { diff --git a/frontend/src/views/Settings/ProjectSettingsPage/components/BackfillSecretReferenceSection/BackfillSecretReferenceSection.tsx b/frontend/src/views/Settings/ProjectSettingsPage/components/BackfillSecretReferenceSection/BackfillSecretReferenceSection.tsx index 6aca7e36e..84faa0d1f 100644 --- a/frontend/src/views/Settings/ProjectSettingsPage/components/BackfillSecretReferenceSection/BackfillSecretReferenceSection.tsx +++ b/frontend/src/views/Settings/ProjectSettingsPage/components/BackfillSecretReferenceSection/BackfillSecretReferenceSection.tsx @@ -25,11 +25,10 @@ export const BackfillSecretReferenceSecretion = () => { return (
Resync Secret References
+Sync Secret References
- Trigger this to reindex all your inline secret references to map integration - synchronization. + This will index all secret references, enabling integrations to be triggered when their values change going forward.