Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Support for multiple paths during secrets Injection #2881

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
37 changes: 22 additions & 15 deletions backend/src/services/secret-v2-bridge/secret-v2-bridge-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,25 +787,32 @@ export const secretV2BridgeServiceFactory = ({

let paths: { folderId: string; path: string }[] = [];

// Split paths if multiple paths are provided, separated by commas
const pathList = path.split(",").map((p) => p.trim());
if (recursive) {
const deepPaths = await recursivelyGetSecretPaths({
folderDAL,
projectEnvDAL,
projectId,
environment,
currentPath: path
});

if (!deepPaths) return { secrets: [], imports: [] };

paths = deepPaths.map(({ folderId, path: p }) => ({ folderId, path: p }));
for(const currentPath of pathList){
const deepPaths = await recursivelyGetSecretPaths({
folderDAL,
projectEnvDAL,
projectId,
environment,
currentPath
});
if (!deepPaths) continue;
// concatenate each array returned from deepPaths.map to paths to get the final array.
paths = paths.concat(deepPaths.map(({ folderId, path: p }) => ({ folderId, path: p })));
}
} else {
const folder = await folderDAL.findBySecretPath(projectId, environment, path);
if (!folder) return { secrets: [], imports: [] };

paths = [{ folderId: folder.id, path }];
for(const currentPath of pathList){
const folder = await folderDAL.findBySecretPath(projectId, environment, currentPath);
if (!folder) continue;
// push each path to the paths
paths.push({ folderId: folder.id, path });
}
}

if(paths?.length === 0) return { secrets: [], imports: [] };

const groupedPaths = groupBy(paths, (p) => p.folderId);

const secrets = await secretDAL.findByFolderIds(
Expand Down