mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 13:27:22 +00:00
feat(folder-sec-overview): added folder path support in get secrets and get folders
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
validateFolderName,
|
validateFolderName,
|
||||||
generateFolderId,
|
generateFolderId,
|
||||||
getParentFromFolderId,
|
getParentFromFolderId,
|
||||||
|
getFolderByPath,
|
||||||
} from "../../services/FolderService";
|
} from "../../services/FolderService";
|
||||||
import { ADMIN, MEMBER } from "../../variables";
|
import { ADMIN, MEMBER } from "../../variables";
|
||||||
import { validateMembership } from "../../helpers/membership";
|
import { validateMembership } from "../../helpers/membership";
|
||||||
@@ -177,10 +178,12 @@ export const deleteFolder = async (req: Request, res: Response) => {
|
|||||||
|
|
||||||
// TODO: validate workspace
|
// TODO: validate workspace
|
||||||
export const getFolders = async (req: Request, res: Response) => {
|
export const getFolders = async (req: Request, res: Response) => {
|
||||||
const { workspaceId, environment, parentFolderId } = req.query as {
|
const { workspaceId, environment, parentFolderId, parentFolderPath } =
|
||||||
|
req.query as {
|
||||||
workspaceId: string;
|
workspaceId: string;
|
||||||
environment: string;
|
environment: string;
|
||||||
parentFolderId?: string;
|
parentFolderId?: string;
|
||||||
|
parentFolderPath?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const folders = await Folder.findOne({ workspace: workspaceId, environment });
|
const folders = await Folder.findOne({ workspace: workspaceId, environment });
|
||||||
@@ -196,6 +199,20 @@ export const getFolders = async (req: Request, res: Response) => {
|
|||||||
acceptedRoles: [ADMIN, MEMBER],
|
acceptedRoles: [ADMIN, MEMBER],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// if instead of parentFolderId given a path like /folder1/folder2
|
||||||
|
if (parentFolderPath) {
|
||||||
|
const folder = getFolderByPath(folders.nodes, parentFolderPath);
|
||||||
|
if (!folder) {
|
||||||
|
res.send({ folders: [], dir: [] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// dir is not needed at present as this is only used in overview section of secrets
|
||||||
|
res.send({
|
||||||
|
folders: folder.children.map(({ id, name }) => ({ id, name })),
|
||||||
|
dir: [{ name: folder.name, id: folder.id }],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!parentFolderId) {
|
if (!parentFolderId) {
|
||||||
const rootFolders = folders.nodes.children.map(({ id, name }) => ({
|
const rootFolders = folders.nodes.children.map(({ id, name }) => ({
|
||||||
id,
|
id,
|
||||||
|
|||||||
@@ -700,11 +700,15 @@ export const getSecrets = async (req: Request, res: Response) => {
|
|||||||
(!folders && folderId && folderId !== "root") ||
|
(!folders && folderId && folderId !== "root") ||
|
||||||
(!folders && secretPath)
|
(!folders && secretPath)
|
||||||
) {
|
) {
|
||||||
throw BadRequestError({ message: "Folder not found" });
|
res.send({ secrets: [] });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (folders && folderId !== "root") {
|
if (folders && folderId !== "root") {
|
||||||
const folder = searchByFolderId(folders.nodes, folderId as string);
|
const folder = searchByFolderId(folders.nodes, folderId as string);
|
||||||
if (!folder) throw BadRequestError({ message: "Folder not found" });
|
if (!folder) {
|
||||||
|
res.send({ secrets: [] });
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.authData.authPayload instanceof ServiceTokenData) {
|
if (req.authData.authPayload instanceof ServiceTokenData) {
|
||||||
@@ -720,10 +724,11 @@ export const getSecrets = async (req: Request, res: Response) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (folders && secretPath) {
|
if (folders && secretPath) {
|
||||||
if (!folders) throw BadRequestError({ message: "Folder not found" });
|
// avoid throwing error and send empty list
|
||||||
const folder = getFolderByPath(folders.nodes, secretPath as string);
|
const folder = getFolderByPath(folders.nodes, secretPath as string);
|
||||||
if (!folder) {
|
if (!folder) {
|
||||||
throw BadRequestError({ message: "Secret path not found" });
|
res.send({ secrets: [] });
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
folderId = folder.id;
|
folderId = folder.id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ router.get(
|
|||||||
query("workspaceId").exists().isString().trim(),
|
query("workspaceId").exists().isString().trim(),
|
||||||
query("environment").exists().isString().trim(),
|
query("environment").exists().isString().trim(),
|
||||||
query("parentFolderId").optional().isString().trim(),
|
query("parentFolderId").optional().isString().trim(),
|
||||||
|
query("parentFolderPath").optional().isString().trim(),
|
||||||
validateRequest,
|
validateRequest,
|
||||||
getFolders
|
getFolders
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user