Skip to content

Commit d509417

Browse files
committed
feat(webapp): allow marking environment variables as secret after creation
Move the secret toggle into the edit form so it submits on Save instead of firing a separate request immediately. Remove the standalone makeSecret action/method and include isSecret as an optional field on the existing editValue flow.
1 parent 72c3571 commit d509417

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.environment-variables/route.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { Fieldset } from "~/components/primitives/Fieldset";
2828
import { FormButtons } from "~/components/primitives/FormButtons";
2929
import { FormError } from "~/components/primitives/FormError";
3030
import { Header2 } from "~/components/primitives/Headers";
31+
import { Hint } from "~/components/primitives/Hint";
3132
import { InfoPanel } from "~/components/primitives/InfoPanel";
3233
import { Input } from "~/components/primitives/Input";
3334
import { InputGroup } from "~/components/primitives/InputGroup";
@@ -68,7 +69,6 @@ import { EnvironmentVariablesRepository } from "~/v3/environmentVariables/enviro
6869
import {
6970
DeleteEnvironmentVariableValue,
7071
EditEnvironmentVariableValue,
71-
EnvironmentVariable,
7272
} from "~/v3/environmentVariables/repository";
7373

7474
export const meta: MetaFunction = () => {
@@ -404,6 +404,7 @@ function EditEnvironmentVariablePanel({
404404
revealAll: boolean;
405405
}) {
406406
const [isOpen, setIsOpen] = useState(false);
407+
const [isSecret, setIsSecret] = useState(variable.isSecret);
407408
const fetcher = useFetcher<typeof action>();
408409
const lastSubmission = fetcher.data as any;
409410

@@ -437,6 +438,7 @@ function EditEnvironmentVariablePanel({
437438
<DialogHeader>Edit environment variable</DialogHeader>
438439
<fetcher.Form method="post" {...form.props}>
439440
<input type="hidden" name="action" value="edit" />
441+
<input type="hidden" name="isSecret" value={isSecret ? "true" : "false"} />
440442
<input {...conform.input(id, { type: "hidden" })} value={variable.id} />
441443
<input
442444
{...conform.input(environmentId, { type: "hidden" })}
@@ -455,6 +457,22 @@ function EditEnvironmentVariablePanel({
455457
<EnvironmentCombo environment={variable.environment} className="text-sm" />
456458
</InputGroup>
457459

460+
<InputGroup className="w-auto">
461+
<Switch
462+
variant="medium"
463+
label={<span className="text-text-bright">Secret value</span>}
464+
checked={isSecret}
465+
disabled={variable.isSecret}
466+
className="-ml-2 inline-flex w-fit"
467+
onCheckedChange={setIsSecret}
468+
/>
469+
<Hint className="-mt-1">
470+
{variable.isSecret
471+
? "This variable is secret and cannot be changed back."
472+
: "Once enabled, the value will be hidden and cannot be revealed again."}
473+
</Hint>
474+
</InputGroup>
475+
458476
<InputGroup fullWidth>
459477
<Label>Value</Label>
460478
<Input

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ export class EnvironmentVariablesRepository implements Repository {
366366
id: string;
367367
environmentId: string;
368368
value: string;
369+
isSecret?: boolean;
369370
}
370371
): Promise<Result> {
371372
const project = await this.prismaClient.project.findFirst({
@@ -426,6 +427,20 @@ export class EnvironmentVariablesRepository implements Repository {
426427
await secretStore.setSecret<{ secret: string }>(key, {
427428
secret: options.value,
428429
});
430+
431+
if (options.isSecret) {
432+
await tx.environmentVariableValue.update({
433+
where: {
434+
variableId_environmentId: {
435+
variableId: environmentVariable.id,
436+
environmentId: options.environmentId,
437+
},
438+
},
439+
data: {
440+
isSecret: true,
441+
},
442+
});
443+
}
429444
});
430445

431446
return {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export const EditEnvironmentVariableValue = z.object({
5151
id: z.string(),
5252
environmentId: z.string(),
5353
value: z.string(),
54+
isSecret: z.preprocess((val) => val === "true" || val === true, z.boolean()).optional(),
5455
});
5556
export type EditEnvironmentVariableValue = z.infer<typeof EditEnvironmentVariableValue>;
5657

0 commit comments

Comments
 (0)