Move ssh back to project level

This commit is contained in:
Tuan Dang
2024-12-09 21:36:42 -08:00
parent 42249726d4
commit 7cf297344b
61 changed files with 837 additions and 635 deletions
+2 -4
View File
@@ -19,8 +19,6 @@ export {
useGetOrgPmtMethods,
useGetOrgTaxIds,
useGetOrgTrialUrl,
useListOrgSshCas,
useListOrgSshCertificates,
useListOrgSshCertificateTemplates,
useUpdateOrg,
useUpdateOrgBillingDetails} from "./queries";
useUpdateOrgBillingDetails
} from "./queries";
@@ -4,8 +4,6 @@ import { apiRequest } from "@app/config/request";
import { OrderByDirection } from "@app/hooks/api/generic/types";
import { TGroupOrgMembership } from "../groups/types";
import { TSshCertificate,TSshCertificateAuthority } from "../ssh-ca/types";
import { TSshCertificateTemplate } from "../sshCertificateTemplates/types";
import { IntegrationAuth } from "../types";
import {
BillingDetails,
@@ -43,12 +41,7 @@ export const organizationKeys = {
}: TListOrgIdentitiesDTO) =>
[...organizationKeys.getOrgIdentityMemberships(orgId), params] as const,
getOrgGroups: (orgId: string) => [{ orgId }, "organization-groups"] as const,
getOrgIntegrationAuths: (orgId: string) => [{ orgId }, "integration-auths"] as const,
getOrgSshCas: ({ orgId }: { orgId: string }) => [{ orgId }, "org-ssh-cas"] as const,
allOrgSshCertificates: () => ["org-ssh-certificates"] as const,
specificOrgSshCertificates: ({ offset, limit }: { offset: number; limit: number }) =>
[...organizationKeys.allOrgSshCertificates(), { offset, limit }] as const,
getOrgSshCertificateTemplates: () => ["org-ssh-certificate-templates"] as const
getOrgIntegrationAuths: (orgId: string) => [{ orgId }, "integration-auths"] as const
};
export const fetchOrganizations = async () => {
@@ -502,63 +495,3 @@ export const useGetOrgIntegrationAuths = <TData = IntegrationAuth[],>(
select
});
};
export const useListOrgSshCas = ({ orgId }: { orgId: string }) => {
return useQuery({
queryKey: organizationKeys.getOrgSshCas({ orgId }),
queryFn: async () => {
const {
data: { cas }
} = await apiRequest.get<{ cas: Omit<TSshCertificateAuthority, "publicKey">[] }>(
`/api/v1/organization/${orgId}/ssh-cas`
);
return cas;
},
enabled: Boolean(orgId)
});
};
export const useListOrgSshCertificates = ({
orgId,
offset,
limit
}: {
orgId: string;
offset: number;
limit: number;
}) => {
return useQuery({
queryKey: organizationKeys.specificOrgSshCertificates({
offset,
limit
}),
queryFn: async () => {
const params = new URLSearchParams({
offset: String(offset),
limit: String(limit)
});
const { data } = await apiRequest.get<{
certificates: TSshCertificate[];
totalCount: number;
}>(`/api/v1/organization/${orgId}/ssh-certificates`, {
params
});
return data;
},
enabled: Boolean(orgId)
});
};
export const useListOrgSshCertificateTemplates = ({ orgId }: { orgId: string }) => {
return useQuery({
queryKey: organizationKeys.getOrgSshCertificateTemplates(),
queryFn: async () => {
const { data } = await apiRequest.get<{ certificateTemplates: TSshCertificateTemplate[] }>(
`/api/v1/organization/${orgId}/ssh-certificate-templates`
);
return data;
},
enabled: Boolean(orgId)
});
};
+11 -11
View File
@@ -2,7 +2,7 @@ import { useMutation, useQueryClient } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { organizationKeys } from "../organization/queries";
import { workspaceKeys } from "../workspace/query-keys";
import {
TCreateSshCaDTO,
TDeleteSshCaDTO,
@@ -27,8 +27,8 @@ export const useCreateSshCa = () => {
} = await apiRequest.post<{ ca: TSshCertificateAuthority }>("/api/v1/ssh/ca/", body);
return ca;
},
onSuccess: ({ orgId }) => {
queryClient.invalidateQueries(organizationKeys.getOrgSshCas({ orgId }));
onSuccess: ({ projectId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspaceSshCas(projectId));
}
});
};
@@ -42,8 +42,8 @@ export const useUpdateSshCa = () => {
} = await apiRequest.patch<{ ca: TSshCertificateAuthority }>(`/api/v1/ssh/ca/${caId}`, body);
return ca;
},
onSuccess: ({ orgId }, { caId }) => {
queryClient.invalidateQueries(organizationKeys.getOrgSshCas({ orgId }));
onSuccess: ({ projectId }, { caId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspaceSshCas(projectId));
queryClient.invalidateQueries(sshCaKeys.getSshCaById(caId));
}
});
@@ -58,8 +58,8 @@ export const useDeleteSshCa = () => {
} = await apiRequest.delete<{ ca: TSshCertificateAuthority }>(`/api/v1/ssh/ca/${caId}`);
return ca;
},
onSuccess: ({ orgId }) => {
queryClient.invalidateQueries(organizationKeys.getOrgSshCas({ orgId }));
onSuccess: ({ projectId }) => {
queryClient.invalidateQueries(workspaceKeys.getWorkspaceSshCas(projectId));
}
});
};
@@ -71,8 +71,8 @@ export const useSignSshKey = () => {
const { data } = await apiRequest.post<TSignSshKeyResponse>("/api/v1/ssh/sign", body);
return data;
},
onSuccess: () => {
queryClient.invalidateQueries(organizationKeys.allOrgSshCertificates());
onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries(workspaceKeys.allWorkspaceSshCertificates(projectId));
}
});
};
@@ -84,8 +84,8 @@ export const useIssueSshCreds = () => {
const { data } = await apiRequest.post<TIssueSshCredsResponse>("/api/v1/ssh/issue", body);
return data;
},
onSuccess: () => {
queryClient.invalidateQueries(organizationKeys.allOrgSshCertificates());
onSuccess: (_, { projectId }) => {
queryClient.invalidateQueries(workspaceKeys.allWorkspaceSshCertificates(projectId));
}
});
};
+4 -2
View File
@@ -7,7 +7,6 @@ export type TSshCertificate = {
sshCertificateTemplateId: string;
serialNumber: string;
certType: SshCertType;
publicKey: string;
principals: string[];
keyId: string;
notBefore: string;
@@ -16,7 +15,7 @@ export type TSshCertificate = {
export type TSshCertificateAuthority = {
id: string;
orgId: string;
projectId: string;
status: SshCaStatus;
friendlyName: string;
keyAlgorithm: CertKeyAlgorithm;
@@ -26,6 +25,7 @@ export type TSshCertificateAuthority = {
};
export type TCreateSshCaDTO = {
projectId: string;
friendlyName?: string;
keyAlgorithm: CertKeyAlgorithm;
};
@@ -41,6 +41,7 @@ export type TDeleteSshCaDTO = {
};
export type TSignSshKeyDTO = {
projectId: string;
templateName: string;
publicKey?: string;
certType: SshCertType;
@@ -55,6 +56,7 @@ export type TSignSshKeyResponse = {
};
export type TIssueSshCredsDTO = {
projectId: string;
templateName: string;
keyAlgorithm: CertKeyAlgorithm;
certType: SshCertType;
@@ -32,6 +32,9 @@ export {
useListWorkspaceGroups,
useListWorkspacePkiAlerts,
useListWorkspacePkiCollections,
useListWorkspaceSshCas,
useListWorkspaceSshCertificates,
useListWorkspaceSshCertificateTemplates,
useNameWorkspaceSecrets,
useToggleAutoCapitalization,
useUpdateIdentityWorkspaceRole,
@@ -15,6 +15,8 @@ import { TIntegration } from "../integrations/types";
import { TPkiAlert } from "../pkiAlerts/types";
import { TPkiCollection } from "../pkiCollections/types";
import { EncryptedSecret } from "../secrets/types";
import { TSshCertificate, TSshCertificateAuthority } from "../ssh-ca/types";
import { TSshCertificateTemplate } from "../sshCertificateTemplates/types";
import { userKeys } from "../users/query-keys";
import { TWorkspaceUser } from "../users/types";
import { ProjectSlackConfig } from "../workflowIntegrations/types";
@@ -713,6 +715,67 @@ export const useListWorkspaceCertificateTemplates = ({ workspaceId }: { workspac
});
};
export const useListWorkspaceSshCertificates = ({
offset,
limit,
projectId
}: {
offset: number;
limit: number;
projectId: string;
}) => {
return useQuery({
queryKey: workspaceKeys.specificWorkspaceSshCertificates({
offset,
limit,
projectId
}),
queryFn: async () => {
const params = new URLSearchParams({
offset: String(offset),
limit: String(limit)
});
const { data } = await apiRequest.get<{
certificates: TSshCertificate[];
totalCount: number;
}>(`/api/v2/workspace/${projectId}/ssh-certificates`, {
params
});
return data;
},
enabled: Boolean(projectId)
});
};
export const useListWorkspaceSshCas = (projectId: string) => {
return useQuery({
queryKey: workspaceKeys.getWorkspaceSshCas(projectId),
queryFn: async () => {
const {
data: { cas }
} = await apiRequest.get<{ cas: Omit<TSshCertificateAuthority, "publicKey">[] }>(
`/api/v2/workspace/${projectId}/ssh-cas`
);
return cas;
},
enabled: Boolean(projectId)
});
};
export const useListWorkspaceSshCertificateTemplates = (projectId: string) => {
return useQuery({
queryKey: workspaceKeys.getWorkspaceSshCertificateTemplates(projectId),
queryFn: async () => {
const { data } = await apiRequest.get<{ certificateTemplates: TSshCertificateTemplate[] }>(
`/api/v2/workspace/${projectId}/ssh-certificate-templates`
);
return data;
},
enabled: Boolean(projectId)
});
};
export const useGetWorkspaceSlackConfig = ({ workspaceId }: { workspaceId: string }) => {
return useQuery({
queryKey: workspaceKeys.getWorkspaceSlackConfig(workspaceId),
@@ -52,5 +52,19 @@ export const workspaceKeys = {
getWorkspaceCertificateTemplates: (workspaceId: string) =>
[{ workspaceId }, "workspace-certificate-templates"] as const,
getWorkspaceSlackConfig: (workspaceId: string) =>
[{ workspaceId }, "workspace-slack-config"] as const
[{ workspaceId }, "workspace-slack-config"] as const,
getWorkspaceSshCas: (projectId: string) => [{ projectId }, "workspace-ssh-cas"] as const,
allWorkspaceSshCertificates: (projectId: string) =>
[{ projectId }, "workspace-ssh-certificates"] as const,
specificWorkspaceSshCertificates: ({
offset,
limit,
projectId
}: {
offset: number;
limit: number;
projectId: string;
}) => [...workspaceKeys.allWorkspaceSshCertificates(projectId), { offset, limit }] as const,
getWorkspaceSshCertificateTemplates: (projectId: string) =>
[{ projectId }, "workspace-ssh-certificate-templates"] as const
};