feat: changed the whole api from projectid to slug

This commit is contained in:
Akhil Mohan
2024-03-22 14:18:12 +05:30
parent 70fe80414d
commit e3e62430ba
28 changed files with 357 additions and 165 deletions
@@ -21,8 +21,8 @@ export const useCreateDynamicSecret = () => {
);
return data.dynamicSecret;
},
onSuccess: (_, { path, environment, projectId }) => {
queryClient.invalidateQueries(dynamicSecretKeys.list({ path, projectId, environment }));
onSuccess: (_, { path, environment, projectSlug }) => {
queryClient.invalidateQueries(dynamicSecretKeys.list({ path, projectSlug, environment }));
}
});
};
@@ -38,8 +38,8 @@ export const useUpdateDynamicSecret = () => {
);
return data.dynamicSecret;
},
onSuccess: (_, { path, environment, projectId }) => {
queryClient.invalidateQueries(dynamicSecretKeys.list({ path, projectId, environment }));
onSuccess: (_, { path, environment, projectSlug }) => {
queryClient.invalidateQueries(dynamicSecretKeys.list({ path, projectSlug, environment }));
}
});
};
@@ -55,8 +55,8 @@ export const useDeleteDynamicSecret = () => {
);
return data.dynamicSecret;
},
onSuccess: (_, { path, environment, projectId }) => {
queryClient.invalidateQueries(dynamicSecretKeys.list({ path, projectId, environment }));
onSuccess: (_, { path, environment, projectSlug }) => {
queryClient.invalidateQueries(dynamicSecretKeys.list({ path, projectSlug, environment }));
}
});
};
+13 -13
View File
@@ -6,25 +6,25 @@ import { TDetailsDynamicSecretDTO, TDynamicSecret, TListDynamicSecretDTO } from
export const dynamicSecretKeys = {
list: ({
projectId,
projectSlug,
environment,
path
}: Pick<TListDynamicSecretDTO, "path" | "environment" | "projectId">) =>
[{ projectId, environment, path }, "dynamic-secrets"] as const,
details: ({ path, environment, projectId, slug }: TDetailsDynamicSecretDTO) =>
[{ projectId, path, environment, slug }, "dynamic-secret-details"] as const
}: Pick<TListDynamicSecretDTO, "path" | "environment" | "projectSlug">) =>
[{ projectSlug, environment, path }, "dynamic-secrets"] as const,
details: ({ path, environment, projectSlug, slug }: TDetailsDynamicSecretDTO) =>
[{ projectSlug, path, environment, slug }, "dynamic-secret-details"] as const
};
export const useGetDynamicSecrets = ({ projectId, environment, path }: TListDynamicSecretDTO) => {
export const useGetDynamicSecrets = ({ projectSlug, environment, path }: TListDynamicSecretDTO) => {
return useQuery({
queryKey: dynamicSecretKeys.list({ path, environment, projectId }),
enabled: Boolean(projectId && environment && path),
queryKey: dynamicSecretKeys.list({ path, environment, projectSlug }),
enabled: Boolean(projectSlug && environment && path),
queryFn: async () => {
const { data } = await apiRequest.get<{ dynamicSecrets: TDynamicSecret[] }>(
"/api/v1/dynamic-secrets",
{
params: {
projectId,
projectSlug,
environment,
path
}
@@ -37,20 +37,20 @@ export const useGetDynamicSecrets = ({ projectId, environment, path }: TListDyna
};
export const useGetDynamicSecretDetails = ({
projectId,
projectSlug,
environment,
path,
slug
}: TDetailsDynamicSecretDTO) => {
return useQuery({
queryKey: dynamicSecretKeys.details({ path, environment, projectId, slug }),
enabled: Boolean(projectId && environment && path && slug),
queryKey: dynamicSecretKeys.details({ path, environment, projectSlug, slug }),
enabled: Boolean(projectSlug && environment && path && slug),
queryFn: async () => {
const { data } = await apiRequest.get<{
dynamicSecret: TDynamicSecret & { inputs: unknown };
}>(`/api/v1/dynamic-secrets/${slug}`, {
params: {
projectId,
projectSlug,
environment,
path
}
@@ -40,7 +40,7 @@ export type TDynamicSecretProvider = {
};
export type TCreateDynamicSecretDTO = {
projectId: string;
projectSlug: string;
provider: TDynamicSecretProvider;
defaultTTL: string;
maxTTL?: string;
@@ -51,7 +51,7 @@ export type TCreateDynamicSecretDTO = {
export type TUpdateDynamicSecretDTO = {
slug: string;
projectId: string;
projectSlug: string;
path: string;
environment: string;
data: {
@@ -63,20 +63,20 @@ export type TUpdateDynamicSecretDTO = {
};
export type TListDynamicSecretDTO = {
projectId: string;
projectSlug: string;
path: string;
environment: string;
};
export type TDeleteDynamicSecretDTO = {
projectId: string;
projectSlug: string;
path: string;
environment: string;
slug: string;
};
export type TDetailsDynamicSecretDTO = {
projectId: string;
projectSlug: string;
path: string;
environment: string;
slug: string;
@@ -25,9 +25,9 @@ export const useCreateDynamicSecretLease = () => {
);
return data;
},
onSuccess: (_, { path, environment, projectId, slug }) => {
onSuccess: (_, { path, environment, projectSlug, slug }) => {
queryClient.invalidateQueries(
dynamicSecretLeaseKeys.list({ path, projectId, environment, slug })
dynamicSecretLeaseKeys.list({ path, projectSlug, environment, slug })
);
}
});
@@ -44,9 +44,9 @@ export const useRenewDynamicSecretLease = () => {
);
return data.lease;
},
onSuccess: (_, { path, environment, projectId, slug }) => {
onSuccess: (_, { path, environment, projectSlug, slug }) => {
queryClient.invalidateQueries(
dynamicSecretLeaseKeys.list({ path, projectId, environment, slug })
dynamicSecretLeaseKeys.list({ path, projectSlug, environment, slug })
);
}
});
@@ -63,9 +63,9 @@ export const useRevokeDynamicSecretLease = () => {
);
return data.lease;
},
onSuccess: (_, { path, environment, projectId, slug }) => {
onSuccess: (_, { path, environment, projectSlug, slug }) => {
queryClient.invalidateQueries(
dynamicSecretLeaseKeys.list({ path, projectId, environment, slug })
dynamicSecretLeaseKeys.list({ path, projectSlug, environment, slug })
);
}
});
@@ -5,26 +5,26 @@ import { apiRequest } from "@app/config/request";
import { TDynamicSecretLease, TListDynamicSecretLeaseDTO } from "./types";
export const dynamicSecretLeaseKeys = {
list: ({ projectId, environment, path, slug }: TListDynamicSecretLeaseDTO) =>
[{ projectId, environment, path, slug }, "dynamic-secret-leases"] as const
list: ({ projectSlug, environment, path, slug }: TListDynamicSecretLeaseDTO) =>
[{ projectSlug, environment, path, slug }, "dynamic-secret-leases"] as const
};
export const useGetDynamicSecretLeases = ({
projectId,
projectSlug,
environment,
path,
slug,
enabled = true
}: TListDynamicSecretLeaseDTO) => {
return useQuery({
queryKey: dynamicSecretLeaseKeys.list({ path, environment, projectId, slug }),
enabled: Boolean(projectId && environment && path && slug && enabled),
queryKey: dynamicSecretLeaseKeys.list({ path, environment, projectSlug, slug }),
enabled: Boolean(projectSlug && environment && path && slug && enabled),
queryFn: async () => {
const { data } = await apiRequest.get<{ leases: TDynamicSecretLease[] }>(
`/api/v1/dynamic-secrets/leases/${slug}`,
`/api/v1/dynamic-secrets/${slug}/leases`,
{
params: {
projectId,
projectSlug,
environment,
path
}
@@ -15,7 +15,7 @@ export type TDynamicSecretLease = {
export type TCreateDynamicSecretLeaseDTO = {
slug: string;
projectId: string;
projectSlug: string;
ttl?: string;
path: string;
environment: string;
@@ -25,14 +25,14 @@ export type TRenewDynamicSecretLeaseDTO = {
leaseId: string;
slug: string;
ttl?: string;
projectId: string;
projectSlug: string;
path: string;
environment: string;
};
export type TListDynamicSecretLeaseDTO = {
slug: string;
projectId: string;
projectSlug: string;
path: string;
environment: string;
enabled?: boolean;
@@ -41,7 +41,7 @@ export type TListDynamicSecretLeaseDTO = {
export type TRevokeDynamicSecretLeaseDTO = {
leaseId: string;
slug: string;
projectId: string;
projectSlug: string;
path: string;
environment: string;
};
@@ -69,6 +69,7 @@ export const SecretMainPage = () => {
// env slug
const environment = router.query.env as string;
const workspaceId = currentWorkspace?.id || "";
const projectSlug = currentWorkspace?.slug || "";
const secretPath = (router.query.secretPath as string) || "/";
const canReadSecret = permission.can(
ProjectPermissionActions.Read,
@@ -139,7 +140,7 @@ export const SecretMainPage = () => {
});
const { data: dynamicSecrets, isLoading: isDynamicSecretLoading } = useGetDynamicSecrets({
projectId: workspaceId,
projectSlug,
environment,
path: secretPath
});
@@ -258,6 +259,7 @@ export const SecretMainPage = () => {
importedSecrets={importedSecrets}
environment={environment}
workspaceId={workspaceId}
projectSlug={projectSlug}
secretPath={secretPath}
isVisible={isVisible}
filter={filter}
@@ -316,7 +318,7 @@ export const SecretMainPage = () => {
<DynamicSecretListView
sortDir={sortDir}
environment={environment}
workspaceId={workspaceId}
projectSlug={projectSlug}
secretPath={secretPath}
dynamicSecrets={dynamicSecrets || []}
/>
@@ -62,7 +62,9 @@ type Props = {
// swtich the secrets type as it gets decrypted after api call
importedSecrets?: Array<Omit<TImportedSecrets, "secrets"> & { secrets: DecryptedSecret[] }>;
environment: string;
// @depreciated will be moving all these details to zustand
workspaceId: string;
projectSlug: string;
secretPath?: string;
filter: Filter;
tags?: WsTag[];
@@ -81,6 +83,7 @@ export const ActionBar = ({
importedSecrets = [],
environment,
workspaceId,
projectSlug,
secretPath = "/",
filter,
tags = [],
@@ -443,7 +446,7 @@ export const ActionBar = ({
<CreateDynamicSecretForm
isOpen={popUp.addDynamicSecret.isOpen}
onToggle={(isOpen) => handlePopUpToggle("addDynamicSecret", isOpen)}
workspaceId={workspaceId}
projectSlug={projectSlug}
environment={environment}
secretPath={secretPath}
/>
@@ -11,7 +11,7 @@ import { SqlDatabaseInputForm } from "./SqlDatabaseInputForm";
type Props = {
isOpen?: boolean;
onToggle: (isOpen: boolean) => void;
workspaceId: string;
projectSlug:string;
environment: string;
secretPath: string;
};
@@ -24,7 +24,7 @@ enum WizardSteps {
export const CreateDynamicSecretForm = ({
isOpen,
onToggle,
workspaceId,
projectSlug,
environment,
secretPath
}: Props) => {
@@ -92,7 +92,7 @@ export const CreateDynamicSecretForm = ({
<SqlDatabaseInputForm
onCompleted={handleFormReset}
onCancel={handleFormReset}
projectId={workspaceId}
projectSlug={projectSlug}
secretPath={secretPath}
environment={environment}
/>
@@ -58,7 +58,7 @@ type Props = {
onCompleted: () => void;
onCancel: () => void;
secretPath: string;
projectId: string;
projectSlug: string;
environment: string;
};
@@ -67,7 +67,7 @@ export const SqlDatabaseInputForm = ({
onCancel,
environment,
secretPath,
projectId
projectSlug
}: Props) => {
const {
control,
@@ -89,7 +89,7 @@ export const SqlDatabaseInputForm = ({
slug,
path: secretPath,
defaultTTL,
projectId,
projectSlug,
environment
});
onCompleted();
@@ -13,20 +13,6 @@ import { useTimedReset } from "@app/hooks";
import { useCreateDynamicSecretLease } from "@app/hooks/api";
import { DynamicSecretProviders } from "@app/hooks/api/dynamicSecret/types";
const formSchema = z.object({
ttl: z.string().refine((val) => ms(val) > 0, "TTL must be a positive number")
});
type TForm = z.infer<typeof formSchema>;
type Props = {
onClose: () => void;
slug: string;
provider: DynamicSecretProviders;
projectId: string;
environment: string;
secretPath: string;
};
const OutputDisplay = ({
value,
label,
@@ -68,14 +54,14 @@ const OutputDisplay = ({
};
const renderOutputForm = (provider: DynamicSecretProviders, data: unknown) => {
const { username, password } = data as { username: string; password: string };
const { DB_PASSWORD, DB_USERNAME } = data as { DB_USERNAME: string; DB_PASSWORD: string };
if (provider === DynamicSecretProviders.SqlDatabase) {
return (
<div>
<OutputDisplay label="Database User" value={username} />
<OutputDisplay label="Database User" value={DB_USERNAME} />
<OutputDisplay
label="Database Password"
value={password}
value={DB_PASSWORD}
helperText="Important: Copy this information now. It will disappear after this.opy this values as you won't be able to see it again."
/>
</div>
@@ -84,9 +70,23 @@ const renderOutputForm = (provider: DynamicSecretProviders, data: unknown) => {
return null;
};
const formSchema = z.object({
ttl: z.string().refine((val) => ms(val) > 0, "TTL must be a positive number")
});
type TForm = z.infer<typeof formSchema>;
type Props = {
onClose: () => void;
slug: string;
provider: DynamicSecretProviders;
projectSlug: string;
environment: string;
secretPath: string;
};
export const CreateDynamicSecretLease = ({
onClose,
projectId,
projectSlug,
slug,
provider,
secretPath,
@@ -107,11 +107,11 @@ export const CreateDynamicSecretLease = ({
const createDynamicSecretLease = useCreateDynamicSecretLease();
const handleDynamicSecretLeaseCreate = async ({ ttl }: TForm) => {
if(createDynamicSecretLease.isLoading) return;
if (createDynamicSecretLease.isLoading) return;
try {
await createDynamicSecretLease.mutateAsync({
environment,
projectId,
projectSlug,
path: secretPath,
ttl,
slug
@@ -28,7 +28,7 @@ import { RenewDynamicSecretLease } from "./RenewDynamicSecretLease";
type Props = {
slug: string;
projectId: string;
projectSlug: string;
environment: string;
secretPath: string;
onClickNewLease: () => void;
@@ -36,7 +36,7 @@ type Props = {
};
export const DynamicSecretLease = ({
projectId,
projectSlug,
slug,
environment,
secretPath,
@@ -48,7 +48,7 @@ export const DynamicSecretLease = ({
"renewSecret"
] as const);
const { data: leases, isLoading: isLeaseLoading } = useGetDynamicSecretLeases({
projectId,
projectSlug,
environment,
path: secretPath,
slug
@@ -62,7 +62,7 @@ export const DynamicSecretLease = ({
const { leaseId } = popUp.deleteSecret.data as { leaseId: string };
await deleteDynamicSecretLease.mutateAsync({
environment,
projectId,
projectSlug,
path: secretPath,
slug,
leaseId
@@ -193,7 +193,7 @@ export const DynamicSecretLease = ({
<ModalContent title="Renew Lease">
<RenewDynamicSecretLease
onClose={() => handlePopUpClose("renewSecret")}
projectId={projectId}
projectSlug={projectSlug}
leaseId={(popUp.renewSecret?.data as { leaseId: string })?.leaseId}
slug={slug}
secretPath={secretPath}
@@ -40,7 +40,7 @@ const formatProviderName = (type: DynamicSecretProviders) => {
type Props = {
dynamicSecrets: TDynamicSecret[];
environment: string;
workspaceId: string;
projectSlug: string;
secretPath?: string;
sortDir: SortDir;
};
@@ -48,7 +48,7 @@ type Props = {
export const DynamicSecretListView = ({
dynamicSecrets = [],
environment,
workspaceId,
projectSlug,
secretPath = "/",
sortDir = SortDir.ASC
}: Props) => {
@@ -67,7 +67,7 @@ export const DynamicSecretListView = ({
const { slug } = popUp.deleteDynamicSecret.data as TDynamicSecret;
await deleteDynamicSecret.mutateAsync({
environment,
projectId: workspaceId,
projectSlug,
path: secretPath,
slug
});
@@ -206,7 +206,7 @@ export const DynamicSecretListView = ({
<DynamicSecretLease
onClickNewLease={() => handlePopUpOpen("createDynamicSecretLease", secret)}
onClose={() => handlePopUpClose("dynamicSecretLeases")}
projectId={workspaceId}
projectSlug={projectSlug}
key={secret.id}
slug={secret.slug}
secretPath={secretPath}
@@ -226,7 +226,7 @@ export const DynamicSecretListView = ({
(popUp.createDynamicSecretLease?.data as { type: DynamicSecretProviders })?.type
}
onClose={() => handlePopUpClose("createDynamicSecretLease")}
projectId={workspaceId}
projectSlug={projectSlug}
slug={(popUp.createDynamicSecretLease?.data as { slug: string })?.slug}
secretPath={secretPath}
environment={environment}
@@ -240,7 +240,7 @@ export const DynamicSecretListView = ({
<ModalContent title="Edit dynamic secret" className="max-w-3xl">
<EditDynamicSecretForm
onClose={() => handlePopUpClose("updateDynamicSecret")}
projectId={workspaceId}
projectSlug={projectSlug}
slug={(popUp.updateDynamicSecret?.data as TDynamicSecret)?.slug}
secretPath={secretPath}
environment={environment}
@@ -9,7 +9,7 @@ import { EditDynamicSecretSqlProviderForm } from "./EditDynamicSecretSqlProvider
type Props = {
onClose: () => void;
slug: string;
projectId: string;
projectSlug: string;
environment: string;
secretPath: string;
};
@@ -17,13 +17,13 @@ type Props = {
export const EditDynamicSecretForm = ({
slug,
environment,
projectId,
projectSlug,
onClose,
secretPath
}: Props) => {
const { data: dynamicSecretDetails, isLoading: isDynamicSecretLoading } =
useGetDynamicSecretDetails({
projectId,
projectSlug,
environment,
slug,
path: secretPath
@@ -49,7 +49,7 @@ export const EditDynamicSecretForm = ({
>
<EditDynamicSecretSqlProviderForm
onClose={onClose}
projectId={projectId}
projectSlug={projectSlug}
secretPath={secretPath}
dynamicSecret={dynamicSecretDetails}
environment={environment}
@@ -61,8 +61,8 @@ type Props = {
onClose: () => void;
dynamicSecret: TDynamicSecret & { inputs: unknown };
secretPath: string;
projectId: string;
environment: string;
projectSlug: string;
};
export const EditDynamicSecretSqlProviderForm = ({
@@ -70,7 +70,7 @@ export const EditDynamicSecretSqlProviderForm = ({
dynamicSecret,
environment,
secretPath,
projectId
projectSlug
}: Props) => {
const {
control,
@@ -97,7 +97,7 @@ export const EditDynamicSecretSqlProviderForm = ({
await updateDynamicSecret.mutateAsync({
slug: dynamicSecret.slug,
path: secretPath,
projectId,
projectSlug,
environment,
data: {
maxTTL: maxTTL || undefined,
@@ -25,14 +25,14 @@ type Props = {
onClose: () => void;
leaseId: string;
slug: string;
projectId: string;
projectSlug: string;
environment: string;
secretPath: string;
};
export const RenewDynamicSecretLease = ({
onClose,
projectId,
projectSlug,
slug,
leaseId,
secretPath,
@@ -57,7 +57,7 @@ export const RenewDynamicSecretLease = ({
try {
await renewDynamicSecretLease.mutateAsync({
environment,
projectId,
projectSlug,
path: secretPath,
ttl,
slug,