Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: add new endpoint to fetch project environment by projectId and env slug
adilson60d0c3be9f60
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.tsindex 0a4e72a2e7..7ee4503613 100644--- a/backend/src/lib/api-docs/constants.ts+++ b/backend/src/lib/api-docs/constants.ts@@ -1238,6 +1238,10 @@ export const ENVIRONMENTS = {GET: {projectId: "The ID of the project the environment belongs to.",id: "The ID of the environment to fetch."+ },+ GET_BY_SLUG: {+ projectId: "The ID of the project the environment belongs to.",+ slug: "The slug of the environment to fetch."}} as const;diff --git a/backend/src/server/routes/v1/project-env-router.ts b/backend/src/server/routes/v1/project-env-router.tsindex 091b1a7bec..b4d07e5568 100644--- a/backend/src/server/routes/v1/project-env-router.ts+++ b/backend/src/server/routes/v1/project-env-router.ts@@ -64,6 +64,58 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {}});+ server.route({+ method: "GET",+ url: "/:projectId/environments/slug/:envSlug",+ config: {+ rateLimit: readLimit+ },+ schema: {+ hide: false,+ operationId: "getEnvironmentBySlug",+ tags: [ApiDocsTags.Environments],+ description: "Get Environment by slug",+ security: [+ {+ bearerAuth: []+ }+ ],+ params: z.object({+ projectId: z.string().trim().uuid().describe(ENVIRONMENTS.GET_BY_SLUG.projectId),+ envSlug: z.string().trim().describe(ENVIRONMENTS.GET_BY_SLUG.slug)+ }),+ response: {+ 200: z.object({+ environment: ProjectEnvironmentsSchema+ })+ }+ },+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),+ handler: async (req) => {+ const environment = await server.services.projectEnv.getEnvironmentBySlug({+ actorId: req.permission.id,+ actor: req.permission.type,+ actorOrgId: req.permission.orgId,+ actorAuthMethod: req.permission.authMethod,+ projectId: req.params.projectId,+ slug: req.params.envSlug+ });++ await server.services.auditLog.createAuditLog({+ ...req.auditLogInfo,+ projectId: environment.projectId,+ event: {+ type: EventType.GET_ENVIRONMENT,+ metadata: {+ id: environment.id+ }+ }+ });++ return { environment };+ }+ });+server.route({method: "POST",url: "/:projectId/environments",diff --git a/backend/src/services/project-env/project-env-service.ts b/backend/src/services/project-env/project-env-service.tsindex 2ba756c276..ca2032140e 100644--- a/backend/src/services/project-env/project-env-service.ts+++ b/backend/src/services/project-env/project-env-service.ts@@ -14,7 +14,14 @@ import { ActorType } from "../auth/auth-type";import { TSecretFolderDALFactory } from "../secret-folder/secret-folder-dal";import { TProjectEnvDALFactory } from "./project-env-dal";import { SOFT_DELETE_GRACE_MS } from "./project-env-queue";-import { TCreateEnvDTO, TDeleteEnvDTO, TGetEnvDTO, TRestoreEnvDTO, TUpdateEnvDTO } from "./project-env-types";+import {+ TCreateEnvDTO,+ TDeleteEnvDTO,+ TGetEnvBySlugDTO,+ TGetEnvDTO,+ TRestoreEnvDTO,+ TUpdateEnvDTO+} from "./project-env-types";type TProjectEnvServiceFactoryDep = {projectEnvDAL: TProjectEnvDALFactory;@@ -438,11 +445,42 @@ export const projectEnvServiceFactory = ({return environment;};+ const getEnvironmentBySlug = async ({+ actor,+ actorId,+ actorOrgId,+ actorAuthMethod,+ projectId,+ slug+ }: TGetEnvBySlugDTO) => {+ const { permission } = await permissionService.getProjectPermission({+ actor,+ actorId,+ projectId,+ actorAuthMethod,+ actorOrgId,+ actionProjectType: ActionProjectType.SecretManager+ });++ ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Environments);++ const environment = await projectEnvDAL.findOne({ projectId, slug });++ if (!environment) {+ throw new NotFoundError({+ message: `Environment with slug '${slug}' in project with ID '${projectId}' not found`+ });+ }++ return environment;+ };+return {createEnvironment,updateEnvironment,deleteEnvironment,restoreEnvironment,- getEnvironmentById+ getEnvironmentById,+ getEnvironmentBySlug};};diff --git a/backend/src/services/project-env/project-env-types.ts b/backend/src/services/project-env/project-env-types.tsindex 81983fe89c..5587cb3b4e 100644--- a/backend/src/services/project-env/project-env-types.ts+++ b/backend/src/services/project-env/project-env-types.ts@@ -30,3 +30,7 @@ export type TReorderEnvDTO = {export type TGetEnvDTO = {id: string;} & Omit<TProjectPermission, "projectId">;++export type TGetEnvBySlugDTO = {+ slug: string;+} & TProjectPermission;diff --git a/docs/api-reference/endpoints/environments/get.mdx b/docs/api-reference/endpoints/environments/get.mdxnew file mode 100644index 0000000000..0879b604df--- /dev/null+++ b/docs/api-reference/endpoints/environments/get.mdx@@ -0,0 +1,4 @@+---+title: "Get by Slug"+openapi: "GET /api/v1/projects/{projectId}/environments/slug/{envSlug}"+---diff --git a/docs/docs.json b/docs/docs.jsonindex efecebabd6..f5306dd6d6 100644--- a/docs/docs.json+++ b/docs/docs.json@@ -2199,6 +2199,7 @@"group": "Environments","pages": ["api-reference/endpoints/environments/create",+ "api-reference/endpoints/environments/get","api-reference/endpoints/environments/update","api-reference/endpoints/environments/delete","api-reference/endpoints/environments/restore",