Preliminary scaffolding for CA structures

This commit is contained in:
Tuan Dang
2024-05-22 21:33:06 -07:00
parent 303edadb1e
commit 26ea949a4e
41 changed files with 1656 additions and 8 deletions
+6
View File
@@ -0,0 +1,6 @@
import { CertificateAuthorityType } from "./enums";
export const caTypeToNameMap: { [K in CertificateAuthorityType]: string } = {
[CertificateAuthorityType.ROOT]: "Root",
[CertificateAuthorityType.INTERMEDIATE]: "Intermediate"
};
+4
View File
@@ -0,0 +1,4 @@
export enum CertificateAuthorityType {
ROOT = "root",
INTERMEDIATE = "intermediate"
}
+2
View File
@@ -0,0 +1,2 @@
export { CertificateAuthorityType } from "./enums";
export { useCreateCa } from "./mutations";
+23
View File
@@ -0,0 +1,23 @@
import {
useMutation
// useQueryClient
} from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { TCertificateAuthority, TCreateCaDTO } from "./types";
export const useCreateCa = () => {
// const queryClient = useQueryClient();
return useMutation<TCertificateAuthority, {}, TCreateCaDTO>({
mutationFn: async (body) => {
const {
data: { identity }
} = await apiRequest.post("/api/v1/ca/", body);
return identity;
},
onSuccess: () => {
// queryClient.invalidateQueries(organizationKeys.getOrgIdentityMemberships(organizationId));
}
});
};
+23
View File
@@ -0,0 +1,23 @@
import { CertificateAuthorityType } from "./enums";
export type TCertificateAuthority = {
id: string;
parentCaId?: string;
projectId: string;
type: CertificateAuthorityType;
dn: string;
commonName: string;
createdAt: string;
updatedAt: string;
};
export type TCreateCaDTO = {
projectSlug: string;
type: string;
organization: string;
ou: string;
country: string;
province: string;
locality: string;
commonName: string;
};
+1
View File
@@ -5,6 +5,7 @@ export * from "./auditLogs";
export * from "./auditLogStreams";
export * from "./auth";
export * from "./bots";
export * from "./ca";
export * from "./dynamicSecret";
export * from "./dynamicSecretLease";
export * from "./groups";
+2 -2
View File
@@ -21,6 +21,7 @@ export {
useGetWorkspaceIntegrations,
useGetWorkspaceSecrets,
useGetWorkspaceUsers,
useListWorkspaceCas,
useListWorkspaceGroups,
useNameWorkspaceSecrets,
useRenameWorkspace,
@@ -28,5 +29,4 @@ export {
useUpdateIdentityWorkspaceRole,
useUpdateUserWorkspaceRole,
useUpdateWsEnvironment,
useUpgradeProject
} from "./queries";
useUpgradeProject} from "./queries";
+18 -1
View File
@@ -2,6 +2,7 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { TCertificateAuthority } from "../ca/types";
import { TGroupMembership } from "../groups/types";
import { IdentityMembership } from "../identities/types";
import { IntegrationAuth } from "../integrationAuth/types";
@@ -39,7 +40,8 @@ export const workspaceKeys = {
getWorkspaceIdentityMemberships: (workspaceId: string) =>
[{ workspaceId }, "workspace-identity-memberships"] as const,
getWorkspaceGroupMemberships: (workspaceId: string) =>
[{ workspaceId }, "workspace-groups"] as const
[{ workspaceId }, "workspace-groups"] as const,
getWorkspaceCas: (workspaceId: string) => [{ workspaceId }, "workspace-cas"] as const
};
const fetchWorkspaceById = async (workspaceId: string) => {
@@ -469,3 +471,18 @@ export const useListWorkspaceGroups = (projectSlug: string) => {
enabled: true
});
};
export const useListWorkspaceCas = (projectSlug: string) => {
return useQuery({
queryKey: workspaceKeys.getWorkspaceCas(projectSlug),
queryFn: async () => {
const {
data: { cas }
} = await apiRequest.get<{ cas: TCertificateAuthority[] }>(
`/api/v2/workspace/${projectSlug}/cas`
);
return cas;
},
enabled: Boolean(projectSlug)
});
};