Skip to content

Commit 8c97d18

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 920892b commit 8c97d18

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { Fieldset } from "~/components/primitives/Fieldset";
3636
import { FormButtons } from "~/components/primitives/FormButtons";
3737
import { FormError } from "~/components/primitives/FormError";
3838
import { Header2 } from "~/components/primitives/Headers";
39+
import { Hint } from "~/components/primitives/Hint";
3940
import { Input } from "~/components/primitives/Input";
4041
import { InputGroup } from "~/components/primitives/InputGroup";
4142
import { Label } from "~/components/primitives/Label";
@@ -808,6 +809,7 @@ function EditEnvironmentVariablePanel({
808809
revealAll: boolean;
809810
}) {
810811
const [isOpen, setIsOpen] = useState(false);
812+
const [isSecret, setIsSecret] = useState(variable.isSecret);
811813
const fetcher = useFetcher<typeof action>();
812814
const lastSubmission = fetcher.data as any;
813815

@@ -840,6 +842,7 @@ function EditEnvironmentVariablePanel({
840842
<DialogHeader>Edit environment variable</DialogHeader>
841843
<fetcher.Form method="post" {...getFormProps(form)}>
842844
<input type="hidden" name="action" value="edit" />
845+
<input type="hidden" name="isSecret" value={isSecret ? "true" : "false"} />
843846
<input {...getInputProps(id, { type: "hidden" })} value={variable.id} />
844847
<input
845848
{...getInputProps(environmentId, { type: "hidden" })}
@@ -858,6 +861,22 @@ function EditEnvironmentVariablePanel({
858861
<EnvironmentCombo environment={variable.environment} className="text-sm" />
859862
</InputGroup>
860863

864+
<InputGroup className="w-auto">
865+
<Switch
866+
variant="medium"
867+
label={<span className="text-text-bright">Secret value</span>}
868+
checked={isSecret}
869+
disabled={variable.isSecret}
870+
className="-ml-2 inline-flex w-fit"
871+
onCheckedChange={setIsSecret}
872+
/>
873+
<Hint className="-mt-1">
874+
{variable.isSecret
875+
? "This variable is secret and cannot be changed back."
876+
: "Once enabled, the value will be hidden and cannot be revealed again."}
877+
</Hint>
878+
</InputGroup>
879+
861880
<InputGroup fullWidth>
862881
<Label>Value</Label>
863882
<Input

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ export class EnvironmentVariablesRepository implements Repository {
505505
increment: 1,
506506
},
507507
lastUpdatedBy: options.lastUpdatedBy ? options.lastUpdatedBy : undefined,
508+
isSecret: options.isSecret ? true : undefined,
508509
},
509510
});
510511
});

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export const EditEnvironmentVariableValue = z.object({
6969
environmentId: z.string(),
7070
value: z.string(),
7171
lastUpdatedBy: EnvironmentVariableUpdaterSchema.optional(),
72+
isSecret: z.preprocess((val) => val === "true" || val === true, z.boolean()).optional(),
7273
});
7374
export type EditEnvironmentVariableValue = z.infer<typeof EditEnvironmentVariableValue>;
7475

0 commit comments

Comments
 (0)