Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

1.2 KB
Raw Blame
import { useQuery } from "@tanstack/react-query";

import { apiRequest } from "@app/config/request";

import { TDynamicSecretLease, TListDynamicSecretLeaseDTO } from "./types";

export const dynamicSecretLeaseKeys = {
  list: ({ projectSlug, environmentSlug, path, dynamicSecretName }: TListDynamicSecretLeaseDTO) =>
    [{ projectSlug, environmentSlug, path, dynamicSecretName }, "dynamic-secret-leases"] as const
};

export const useGetDynamicSecretLeases = ({
  projectSlug,
  environmentSlug,
  path,
  dynamicSecretName,
  enabled = true
}: TListDynamicSecretLeaseDTO) => {
  return useQuery({
    queryKey: dynamicSecretLeaseKeys.list({
      path,
      environmentSlug,
      projectSlug,
      dynamicSecretName
    }),
    enabled: Boolean(projectSlug && environmentSlug && path && dynamicSecretName && enabled),
    staleTime: 0,
    gcTime: 0,
    queryFn: async () => {
      const { data } = await apiRequest.get<{ leases: TDynamicSecretLease[] }>(
        `/api/v1/dynamic-secrets/${dynamicSecretName}/leases`,
        {
          params: {
            projectSlug,
            environmentSlug,
            path
          }
        }
      );

      return data.leases;
    }
  });
};