feat: frontend integration

This commit is contained in:
Sheen Capadngan
2025-01-08 18:24:40 +08:00
parent 74b95d92ab
commit d7c3192099
3 changed files with 172 additions and 2 deletions
@@ -10,6 +10,7 @@ import { useToggle } from "@app/hooks/useToggle";
import { ERROR_NOT_ALLOWED_READ_SECRETS } from "./constants";
import {
GetSecretVersionsDTO,
SecretAccessListEntry,
SecretType,
SecretV3Raw,
SecretV3RawResponse,
@@ -18,6 +19,7 @@ import {
TGetProjectSecretsAllEnvDTO,
TGetProjectSecretsDTO,
TGetProjectSecretsKey,
TGetSecretAccessListDTO,
TGetSecretReferenceTreeDTO,
TSecretReferenceTraceNode
} from "./types";
@@ -27,6 +29,13 @@ export const secretKeys = {
getProjectSecret: ({ workspaceId, environment, secretPath }: TGetProjectSecretsKey) =>
[{ workspaceId, environment, secretPath }, "secrets"] as const,
getSecretVersion: (secretId: string) => [{ secretId }, "secret-versions"] as const,
getSecretAccessList: ({
workspaceId,
environment,
secretPath,
secretKey
}: TGetSecretAccessListDTO) =>
["secret-access-list", { workspaceId, environment, secretPath, secretKey }] as const,
getSecretReferenceTree: (dto: TGetSecretReferenceTreeDTO) => ["secret-reference-tree", dto]
};
@@ -231,6 +240,27 @@ export const useGetSecretVersion = (dto: GetSecretVersionsDTO) =>
}, [])
});
export const useGetSecretAccessList = (dto: TGetSecretAccessListDTO) =>
useQuery({
enabled: Boolean(dto.secretKey),
queryKey: secretKeys.getSecretAccessList(dto),
queryFn: async () => {
const { data } = await apiRequest.get<{
groups: SecretAccessListEntry[];
identities: SecretAccessListEntry[];
users: SecretAccessListEntry[];
}>(`/api/v1/secrets/raw/${dto.secretKey}/access-list`, {
params: {
workspaceId: dto.workspaceId,
environment: dto.environment,
secretPath: dto.secretPath
}
});
return data;
}
});
const fetchSecretReferenceTree = async ({
secretPath,
projectId,
+16
View File
@@ -1,3 +1,5 @@
import { ProjectPermissionActions } from "@app/context";
import type { WsTag } from "../tags/types";
export enum SecretType {
@@ -123,6 +125,13 @@ export type GetSecretVersionsDTO = {
offset: number;
};
export type TGetSecretAccessListDTO = {
workspaceId: string;
environment: string;
secretPath: string;
secretKey: string;
};
export type TCreateSecretsV3DTO = {
secretKey: string;
secretValue: string;
@@ -228,3 +237,10 @@ export type TSecretReferenceTraceNode = {
secretPath: string;
children: TSecretReferenceTraceNode[];
};
export type SecretAccessListEntry = {
allowedActions: ProjectPermissionActions[];
id: string;
membershipId: string;
name: string;
};