Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Merge branch 'main' into feat/adilsitos/secrets-188

adilsonc813fcdbde8b
diff --cc frontend/src/hooks/api/secrets/mutations.tsx
index 0d24e95d90,f6f4075aa3..ce48d28e82
--- a/frontend/src/hooks/api/secrets/mutations.tsx
+++ b/frontend/src/hooks/api/secrets/mutations.tsx
@@@ -485,79 -483,11 +485,82 @@@ export const useMoveSecrets = (
});
};
+export const useDuplicateSecret = ({
+ options
+}: {
+ options?: Omit<
+ MutationOptions<TDuplicateSecretResponse, object, TDuplicateSecretDTO>,
+ "mutationFn"
+ >;
+} = {}) => {
+ const queryClient = useQueryClient();
+
+ return useMutation<TDuplicateSecretResponse, object, TDuplicateSecretDTO>({
+ mutationFn: async (dto) => {
+ const { data } = await apiRequest.post<TDuplicateSecretResponse>(
+ "/api/v4/secrets/duplicate",
+ dto
+ );
+ return data;
+ },
+ onSuccess: (data, { projectId, destinationEnvironment, destinationSecretPath }) => {
+ queryClient.invalidateQueries({
+ queryKey: dashboardKeys.getDashboardSecrets({
+ projectId,
+ secretPath: destinationSecretPath
+ })
+ });
+ queryClient.invalidateQueries({
+ queryKey: secretKeys.getProjectSecret({
+ projectId,
+ environment: destinationEnvironment,
+ secretPath: destinationSecretPath
+ })
+ });
+ queryClient.invalidateQueries({
+ queryKey: secretSnapshotKeys.list({
+ environment: destinationEnvironment,
+ projectId,
+ directory: destinationSecretPath
+ })
+ });
+ queryClient.invalidateQueries({
+ queryKey: secretSnapshotKeys.count({
+ environment: destinationEnvironment,
+ projectId,
+ directory: destinationSecretPath
+ })
+ });
+ queryClient.invalidateQueries({
+ queryKey: commitKeys.count({
+ projectId,
+ environment: destinationEnvironment,
+ directory: destinationSecretPath
+ })
+ });
+ queryClient.invalidateQueries({
+ queryKey: commitKeys.history({
+ projectId,
+ environment: destinationEnvironment,
+ directory: destinationSecretPath
+ })
+ });
+ if (data.results.some((result) => "approval" in result)) {
+ queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ projectId }) });
+ queryClient.invalidateQueries({
+ queryKey: secretApprovalRequestKeys.listAllForProject({ projectId })
+ });
+ }
+ },
+ ...options
+ });
+};
+
export const createSecret = async (dto: TCreateSecretsV3DTO) => {
- const { data } = await apiRequest.post(`/api/v4/secrets/${dto.secretKey}`, dto);
+ const { data } = await apiRequest.post(
+ `/api/v4/secrets/${encodeURIComponent(dto.secretKey)}`,
+ dto
+ );
return data;
};