Skip to content

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

cleanup

Daniel Hougaard0814245ce66e
diff --git a/backend/src/server/routes/v1/project-env-router.ts b/backend/src/server/routes/v1/project-env-router.ts
index fed6091960..1b0e074c28 100644
--- a/backend/src/server/routes/v1/project-env-router.ts
+++ b/backend/src/server/routes/v1/project-env-router.ts
@@ -4,7 +4,7 @@ import { z } from "zod";
import { ProjectEnvironmentsSchema } from "@app/db/schemas";
import { EventType } from "@app/ee/services/audit-log/audit-log-types";
import { ENVIRONMENTS } from "@app/lib/api-docs";
-import { writeLimit } from "@app/server/config/rateLimiter";
+import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
@@ -23,6 +23,7 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
}
],
params: z.object({
+ // NOTE(daniel): workspaceId isn't used, but we need to keep it for backwards compatibility. The endpoint defined below, uses no project ID, and is takes a pure environment ID.
workspaceId: z.string().trim().describe(ENVIRONMENTS.GET.workspaceId),
envId: z.string().trim().describe(ENVIRONMENTS.GET.id)
}),
@@ -39,7 +40,53 @@ export const registerProjectEnvRouter = async (server: FastifyZodProvider) => {
actor: req.permission.type,
actorOrgId: req.permission.orgId,
actorAuthMethod: req.permission.authMethod,
- projectId: req.params.workspaceId,
+ id: req.params.envId
+ });
+
+ await server.services.auditLog.createAuditLog({
+ ...req.auditLogInfo,
+ projectId: environment.projectId,
+ event: {
+ type: EventType.GET_ENVIRONMENT,
+ metadata: {
+ id: environment.id
+ }
+ }
+ });
+
+ return { environment };
+ }
+ });
+
+ server.route({
+ method: "GET",
+ url: "/environments/:envId",
+ config: {
+ rateLimit: readLimit
+ },
+ schema: {
+ description: "Get Environment by ID",
+ security: [
+ {
+ bearerAuth: []
+ }
+ ],
+ params: z.object({
+ envId: z.string().trim().describe(ENVIRONMENTS.GET.id)
+ }),
+ response: {
+ 200: z.object({
+ environment: ProjectEnvironmentsSchema
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.IDENTITY_ACCESS_TOKEN]),
+ handler: async (req) => {
+ const environment = await server.services.projectEnv.getEnvironmentById({
+ actorId: req.permission.id,
+ actor: req.permission.type,
+ actorOrgId: req.permission.orgId,
+ actorAuthMethod: req.permission.authMethod,
id: req.params.envId
});
diff --git a/backend/src/services/project-env/project-env-service.ts b/backend/src/services/project-env/project-env-service.ts
index 645f34adef..ea826b3a63 100644
--- a/backend/src/services/project-env/project-env-service.ts
+++ b/backend/src/services/project-env/project-env-service.ts
@@ -215,29 +215,26 @@ export const projectEnvServiceFactory = ({
}
};
- const getEnvironmentById = async ({ projectId, actor, actorId, actorOrgId, actorAuthMethod, id }: TGetEnvDTO) => {
+ const getEnvironmentById = async ({ actor, actorId, actorOrgId, actorAuthMethod, id }: TGetEnvDTO) => {
+ const environment = await projectEnvDAL.findById(id);
+
+ if (!environment) {
+ throw new NotFoundError({
+ message: "Environment does not exist"
+ });
+ }
+
const { permission } = await permissionService.getProjectPermission(
actor,
actorId,
- projectId,
+ environment.projectId,
actorAuthMethod,
actorOrgId
);
ForbiddenError.from(permission).throwUnlessCan(ProjectPermissionActions.Read, ProjectPermissionSub.Environments);
- const [env] = await projectEnvDAL.find({
- id,
- projectId
- });
-
- if (!env) {
- throw new NotFoundError({
- message: "Environment does not exist"
- });
- }
-
- return env;
+ return environment;
};
return {
diff --git a/backend/src/services/project-env/project-env-types.ts b/backend/src/services/project-env/project-env-types.ts
index 27d808a474..229e8b195a 100644
--- a/backend/src/services/project-env/project-env-types.ts
+++ b/backend/src/services/project-env/project-env-types.ts
@@ -23,4 +23,4 @@ export type TReorderEnvDTO = {
export type TGetEnvDTO = {
id: string;
-} & TProjectPermission;
+} & Omit<TProjectPermission, "projectId">;