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
@@ -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,