Skip to content

Commit 6d508ca

Browse files
committed
Added a new env var repository function for getting secrets with redactions
1 parent 6ba85b5 commit 6d508ca

File tree

4 files changed

+40
-26
lines changed

4 files changed

+40
-26
lines changed

apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.$slug.$name.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,10 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
123123

124124
const repository = new EnvironmentVariablesRepository();
125125

126-
const variables = await repository.getEnvironment(environment.project.id, environment.id);
126+
const variables = await repository.getEnvironmentWithRedactedSecrets(
127+
environment.project.id,
128+
environment.id
129+
);
127130

128131
const environmentVariable = variables.find((v) => v.key === parsedParams.data.name);
129132

apps/webapp/app/routes/api.v1.projects.$projectRef.envvars.$slug.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,10 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
8080

8181
const repository = new EnvironmentVariablesRepository();
8282

83-
const variables = await repository.getEnvironment(environment.project.id, environment.id);
83+
const variables = await repository.getEnvironmentWithRedactedSecrets(
84+
environment.project.id,
85+
environment.id
86+
);
8487

8588
return json(
8689
variables.map((variable) => ({

apps/webapp/app/v3/environmentVariables/environmentVariablesRepository.server.ts

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -510,30 +510,11 @@ export class EnvironmentVariablesRepository implements Repository {
510510
return results;
511511
}
512512

513-
async getEnvironment(
513+
async getEnvironmentWithRedactedSecrets(
514514
projectId: string,
515515
environmentId: string
516516
): Promise<EnvironmentVariableWithSecret[]> {
517-
const project = await this.prismaClient.project.findFirst({
518-
where: {
519-
id: projectId,
520-
deletedAt: null,
521-
},
522-
select: {
523-
environments: {
524-
select: {
525-
id: true,
526-
},
527-
where: {
528-
id: environmentId,
529-
},
530-
},
531-
},
532-
});
533-
534-
if (!project || project.environments.length === 0) {
535-
return [];
536-
}
517+
const variables = await this.getEnvironment(projectId, environmentId);
537518

538519
// Get the keys of all secret variables
539520
const secretValues = await this.prismaClient.environmentVariableValue.findMany({
@@ -551,8 +532,6 @@ export class EnvironmentVariablesRepository implements Repository {
551532
});
552533
const secretVarKeys = secretValues.map((r) => r.variable.key);
553534

554-
const variables = await this.getEnvironmentVariables(projectId, environmentId);
555-
556535
// Filter out secret variables if includeSecrets is false
557536
return variables.map((v) => {
558537
if (secretVarKeys.includes(v.key)) {
@@ -567,6 +546,31 @@ export class EnvironmentVariablesRepository implements Repository {
567546
});
568547
}
569548

549+
async getEnvironment(projectId: string, environmentId: string): Promise<EnvironmentVariable[]> {
550+
const project = await this.prismaClient.project.findFirst({
551+
where: {
552+
id: projectId,
553+
deletedAt: null,
554+
},
555+
select: {
556+
environments: {
557+
select: {
558+
id: true,
559+
},
560+
where: {
561+
id: environmentId,
562+
},
563+
},
564+
},
565+
});
566+
567+
if (!project || project.environments.length === 0) {
568+
return [];
569+
}
570+
571+
return this.getEnvironmentVariables(projectId, environmentId);
572+
}
573+
570574
async #getSecretEnvironmentVariables(
571575
projectId: string,
572576
environmentId: string

apps/webapp/app/v3/environmentVariables/repository.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ export interface Repository {
9191
/**
9292
* Get the environment variables for a given environment, it does NOT return values for secret variables
9393
*/
94-
getEnvironment(
94+
getEnvironmentWithRedactedSecrets(
9595
projectId: string,
9696
environmentId: string
9797
): Promise<EnvironmentVariableWithSecret[]>;
98+
/**
99+
* Get the environment variables for a given environment
100+
*/
101+
getEnvironment(projectId: string, environmentId: string): Promise<EnvironmentVariable[]>;
98102
/**
99103
* Return all env vars, including secret variables with values. Should only be used for executing tasks.
100104
*/

0 commit comments

Comments
 (0)