mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-16 01:05:40 +00:00
feat(secret-approval): implemented the new policy based approval system bare version
This commit is contained in:
@@ -1,2 +1,5 @@
|
||||
export { useUpdateSecretApprovalRequestStatus } from "./mutation";
|
||||
export {
|
||||
usePerformSecretApprovalRequestMerge,
|
||||
useUpdateSecretApprovalRequestStatus
|
||||
} from "./mutation";
|
||||
export { useGetSecretApprovalRequestDetails, useGetSecretApprovalRequests } from "./queries";
|
||||
|
||||
@@ -3,7 +3,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { secretApprovalRequestKeys } from "./queries";
|
||||
import { TUpdateSecretApprovalRequestStatusDTO } from "./types";
|
||||
import { TPerformSecretApprovalRequestMerge, TUpdateSecretApprovalRequestStatusDTO } from "./types";
|
||||
|
||||
export const useUpdateSecretApprovalRequestStatus = () => {
|
||||
const queryClient = useQueryClient();
|
||||
@@ -18,3 +18,17 @@ export const useUpdateSecretApprovalRequestStatus = () => {
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const usePerformSecretApprovalRequestMerge = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<{}, {}, TPerformSecretApprovalRequestMerge>({
|
||||
mutationFn: async ({ id }) => {
|
||||
const { data } = await apiRequest.post("/api/v1/secret-approval-requests/merge", { id });
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { id }) => {
|
||||
queryClient.invalidateQueries(secretApprovalRequestKeys.detail({ id }));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
import {
|
||||
useInfiniteQuery,
|
||||
UseInfiniteQueryOptions,
|
||||
useQuery,
|
||||
UseQueryOptions
|
||||
} from "@tanstack/react-query";
|
||||
|
||||
import {
|
||||
decryptAssymmetric,
|
||||
@@ -18,8 +23,18 @@ import {
|
||||
} from "./types";
|
||||
|
||||
export const secretApprovalRequestKeys = {
|
||||
list: ({ workspaceId, environment }: TGetSecretApprovalRequestList) =>
|
||||
[{ workspaceId, environment }, "secret-approval-requests"] as const,
|
||||
list: ({
|
||||
workspaceId,
|
||||
environment,
|
||||
status,
|
||||
committer,
|
||||
offset,
|
||||
limit
|
||||
}: TGetSecretApprovalRequestList) =>
|
||||
[
|
||||
{ workspaceId, environment, status, committer, offset, limit },
|
||||
"secret-approval-requests"
|
||||
] as const,
|
||||
detail: ({ id }: Omit<TGetSecretApprovalRequestDetails, "decryptKey">) =>
|
||||
[{ id }, "secret-approval-request-detail"] as const
|
||||
};
|
||||
@@ -68,14 +83,22 @@ export const decryptSecretApprovalSecret = (
|
||||
|
||||
const fetchSecretApprovalRequestList = async ({
|
||||
workspaceId,
|
||||
environment
|
||||
environment,
|
||||
committer,
|
||||
status = "open",
|
||||
limit = 20,
|
||||
offset
|
||||
}: TGetSecretApprovalRequestList) => {
|
||||
const { data } = await apiRequest.get<{ approvals: TSecretApprovalRequest[] }>(
|
||||
"/api/v1/secret-approval-requests",
|
||||
{
|
||||
params: {
|
||||
workspaceId,
|
||||
environment
|
||||
environment,
|
||||
committer,
|
||||
status,
|
||||
limit,
|
||||
offset
|
||||
}
|
||||
}
|
||||
);
|
||||
@@ -86,10 +109,13 @@ const fetchSecretApprovalRequestList = async ({
|
||||
export const useGetSecretApprovalRequests = ({
|
||||
workspaceId,
|
||||
environment,
|
||||
options = {}
|
||||
options = {},
|
||||
status,
|
||||
limit = 20,
|
||||
committer
|
||||
}: TGetSecretApprovalRequestList & {
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
UseInfiniteQueryOptions<
|
||||
TSecretApprovalRequest[],
|
||||
unknown,
|
||||
TSecretApprovalRequest[],
|
||||
@@ -98,10 +124,26 @@ export const useGetSecretApprovalRequests = ({
|
||||
"queryKey" | "queryFn"
|
||||
>;
|
||||
}) =>
|
||||
useQuery({
|
||||
queryKey: secretApprovalRequestKeys.list({ workspaceId, environment }),
|
||||
queryFn: () => fetchSecretApprovalRequestList({ workspaceId, environment }),
|
||||
enabled: Boolean(workspaceId) && (options?.enabled ?? true)
|
||||
useInfiniteQuery({
|
||||
queryKey: secretApprovalRequestKeys.list({
|
||||
workspaceId,
|
||||
environment,
|
||||
committer,
|
||||
status
|
||||
}),
|
||||
queryFn: ({ pageParam }) =>
|
||||
fetchSecretApprovalRequestList({
|
||||
workspaceId,
|
||||
environment,
|
||||
status,
|
||||
committer,
|
||||
limit,
|
||||
offset: pageParam
|
||||
}),
|
||||
enabled: Boolean(workspaceId) && (options?.enabled ?? true),
|
||||
getNextPageParam: (lastPage, pages) => {
|
||||
return lastPage?.length !== 0 ? pages.length * limit : undefined;
|
||||
}
|
||||
});
|
||||
|
||||
const fetchSecretApprovalRequestDetails = async ({
|
||||
@@ -134,9 +176,10 @@ export const useGetSecretApprovalRequestDetails = ({
|
||||
queryFn: () => fetchSecretApprovalRequestDetails({ id }),
|
||||
select: (data) => ({
|
||||
...data,
|
||||
commits: data.commits.map(({ secret, op, newVersion }) => ({
|
||||
commits: data.commits.map(({ secretVersion, op, newVersion, secret }) => ({
|
||||
op,
|
||||
secret: secret ? decryptSecrets([secret], decryptKey)[0] : undefined,
|
||||
secret,
|
||||
secretVersion: secretVersion ? decryptSecrets([secretVersion], decryptKey)[0] : undefined,
|
||||
newVersion: newVersion ? decryptSecretApprovalSecret(newVersion, decryptKey) : undefined
|
||||
}))
|
||||
}),
|
||||
|
||||
@@ -60,7 +60,8 @@ export type TSecretApprovalRequest<
|
||||
policy: TSecretApprovalPolicy;
|
||||
commits: {
|
||||
// if there is no secret means it was creation
|
||||
secret?: J;
|
||||
secret?: { version: number };
|
||||
secretVersion: J;
|
||||
// if there is no new version its for Delete
|
||||
newVersion?: T;
|
||||
op: CommitType;
|
||||
@@ -70,6 +71,10 @@ export type TSecretApprovalRequest<
|
||||
export type TGetSecretApprovalRequestList = {
|
||||
workspaceId: string;
|
||||
environment?: string;
|
||||
status?: "open" | "close";
|
||||
committer?: string;
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
};
|
||||
|
||||
export type TGetSecretApprovalRequestDetails = {
|
||||
@@ -81,3 +86,7 @@ export type TUpdateSecretApprovalRequestStatusDTO = {
|
||||
status: ApprovalStatus;
|
||||
id: string;
|
||||
};
|
||||
|
||||
export type TPerformSecretApprovalRequestMerge = {
|
||||
id: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user