-
-
Notifications
You must be signed in to change notification settings - Fork 645
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Override local env vars with env vars in the server (#914)
- Loading branch information
Showing
15 changed files
with
213 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ActionFunctionArgs, LoaderFunctionArgs, json } from "@remix-run/server-runtime"; | ||
import { CreateBackgroundWorkerRequestBody } from "@trigger.dev/core/v3"; | ||
import { z } from "zod"; | ||
import { prisma } from "~/db.server"; | ||
import { authenticateApiRequest } from "~/services/apiAuth.server"; | ||
import { logger } from "~/services/logger.server"; | ||
import { EnvironmentVariablesRepository } from "~/v3/environmentVariables/environmentVariablesRepository.server"; | ||
import { CreateBackgroundWorkerService } from "~/v3/services/createBackgroundWorker.server"; | ||
|
||
const ParamsSchema = z.object({ | ||
projectRef: z.string(), | ||
}); | ||
|
||
export async function loader({ request, params }: LoaderFunctionArgs) { | ||
const parsedParams = ParamsSchema.safeParse(params); | ||
|
||
if (!parsedParams.success) { | ||
return json({ error: "Invalid params" }, { status: 400 }); | ||
} | ||
|
||
// Next authenticate the request | ||
const authenticationResult = await authenticateApiRequest(request); | ||
|
||
if (!authenticationResult) { | ||
return json({ error: "Invalid or Missing API key" }, { status: 401 }); | ||
} | ||
|
||
const authenticatedEnv = authenticationResult.environment; | ||
|
||
const { projectRef } = parsedParams.data; | ||
|
||
const project = await prisma.project.findUnique({ | ||
where: { | ||
externalRef: projectRef, | ||
environments: { | ||
some: { | ||
id: authenticatedEnv.id, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!project) { | ||
return json({ error: "Project not found" }, { status: 404 }); | ||
} | ||
|
||
const repository = new EnvironmentVariablesRepository(); | ||
|
||
const variables = await repository.getEnvironmentVariables(project.id, authenticatedEnv.id); | ||
|
||
return json({ | ||
variables: variables.reduce((acc: Record<string, string>, variable) => { | ||
acc[variable.key] = variable.value; | ||
return acc; | ||
}, {}), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.