mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Merge pull request #4357 from Infisical/ENG-3463
feat(api): Return path for folder create, update, delete
This commit is contained in:
@@ -45,7 +45,7 @@ export const registerSecretFolderRouter = async (server: FastifyZodProvider) =>
|
|||||||
.transform(removeTrailingSlash)
|
.transform(removeTrailingSlash)
|
||||||
.describe(FOLDERS.CREATE.path)
|
.describe(FOLDERS.CREATE.path)
|
||||||
.optional(),
|
.optional(),
|
||||||
// backward compatiability with cli
|
// backward compatibility with cli
|
||||||
directory: z
|
directory: z
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
@@ -58,7 +58,9 @@ export const registerSecretFolderRouter = async (server: FastifyZodProvider) =>
|
|||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
folder: SecretFoldersSchema
|
folder: SecretFoldersSchema.extend({
|
||||||
|
path: z.string()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -130,7 +132,7 @@ export const registerSecretFolderRouter = async (server: FastifyZodProvider) =>
|
|||||||
.transform(removeTrailingSlash)
|
.transform(removeTrailingSlash)
|
||||||
.describe(FOLDERS.UPDATE.path)
|
.describe(FOLDERS.UPDATE.path)
|
||||||
.optional(),
|
.optional(),
|
||||||
// backward compatiability with cli
|
// backward compatibility with cli
|
||||||
directory: z
|
directory: z
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
@@ -143,7 +145,9 @@ export const registerSecretFolderRouter = async (server: FastifyZodProvider) =>
|
|||||||
}),
|
}),
|
||||||
response: {
|
response: {
|
||||||
200: z.object({
|
200: z.object({
|
||||||
folder: SecretFoldersSchema
|
folder: SecretFoldersSchema.extend({
|
||||||
|
path: z.string()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -359,7 +363,7 @@ export const registerSecretFolderRouter = async (server: FastifyZodProvider) =>
|
|||||||
.transform(removeTrailingSlash)
|
.transform(removeTrailingSlash)
|
||||||
.describe(FOLDERS.LIST.path)
|
.describe(FOLDERS.LIST.path)
|
||||||
.optional(),
|
.optional(),
|
||||||
// backward compatiability with cli
|
// backward compatibility with cli
|
||||||
directory: z
|
directory: z
|
||||||
.string()
|
.string()
|
||||||
.trim()
|
.trim()
|
||||||
|
|||||||
@@ -238,8 +238,16 @@ export const secretFolderServiceFactory = ({
|
|||||||
return doc;
|
return doc;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [folderWithFullPath] = await folderDAL.findSecretPathByFolderIds(projectId, [folder.id]);
|
||||||
|
|
||||||
|
if (!folderWithFullPath) {
|
||||||
|
throw new NotFoundError({
|
||||||
|
message: `Failed to retrieve path for folder with ID '${folder.id}'`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await snapshotService.performSnapshot(folder.parentId as string);
|
await snapshotService.performSnapshot(folder.parentId as string);
|
||||||
return folder;
|
return { ...folder, path: folderWithFullPath.path };
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateManyFolders = async ({
|
const updateManyFolders = async ({
|
||||||
@@ -496,8 +504,27 @@ export const secretFolderServiceFactory = ({
|
|||||||
return doc;
|
return doc;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const foldersWithFullPaths = await folderDAL.findSecretPathByFolderIds(projectId, [newFolder.id, folder.id]);
|
||||||
|
|
||||||
|
const newFolderWithFullPath = foldersWithFullPaths.find((f) => f?.id === newFolder.id);
|
||||||
|
if (!newFolderWithFullPath) {
|
||||||
|
throw new NotFoundError({
|
||||||
|
message: `Failed to retrieve path for folder with ID '${newFolder.id}'`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const folderWithFullPath = foldersWithFullPaths.find((f) => f?.id === folder.id);
|
||||||
|
if (!folderWithFullPath) {
|
||||||
|
throw new NotFoundError({
|
||||||
|
message: `Failed to retrieve path for folder with ID '${folder.id}'`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await snapshotService.performSnapshot(newFolder.parentId as string);
|
await snapshotService.performSnapshot(newFolder.parentId as string);
|
||||||
return { folder: newFolder, old: folder };
|
return {
|
||||||
|
folder: { ...newFolder, path: newFolderWithFullPath.path },
|
||||||
|
old: { ...folder, path: folderWithFullPath.path }
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const $checkFolderPolicy = async ({
|
const $checkFolderPolicy = async ({
|
||||||
|
|||||||
Reference in New Issue
Block a user