Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Fieldset } from "~/components/primitives/Fieldset";
import { FormButtons } from "~/components/primitives/FormButtons";
import { FormError } from "~/components/primitives/FormError";
import { Header2 } from "~/components/primitives/Headers";
import { Hint } from "~/components/primitives/Hint";
import { InfoPanel } from "~/components/primitives/InfoPanel";
import { Input } from "~/components/primitives/Input";
import { InputGroup } from "~/components/primitives/InputGroup";
Expand Down Expand Up @@ -68,7 +69,6 @@ import { EnvironmentVariablesRepository } from "~/v3/environmentVariables/enviro
import {
DeleteEnvironmentVariableValue,
EditEnvironmentVariableValue,
EnvironmentVariable,
} from "~/v3/environmentVariables/repository";

export const meta: MetaFunction = () => {
Expand Down Expand Up @@ -404,6 +404,7 @@ function EditEnvironmentVariablePanel({
revealAll: boolean;
}) {
const [isOpen, setIsOpen] = useState(false);
const [isSecret, setIsSecret] = useState(variable.isSecret);
const fetcher = useFetcher<typeof action>();
const lastSubmission = fetcher.data as any;

Expand Down Expand Up @@ -437,6 +438,7 @@ function EditEnvironmentVariablePanel({
<DialogHeader>Edit environment variable</DialogHeader>
<fetcher.Form method="post" {...form.props}>
<input type="hidden" name="action" value="edit" />
<input type="hidden" name="isSecret" value={isSecret ? "true" : "false"} />
<input {...conform.input(id, { type: "hidden" })} value={variable.id} />
<input
{...conform.input(environmentId, { type: "hidden" })}
Expand All @@ -455,6 +457,22 @@ function EditEnvironmentVariablePanel({
<EnvironmentCombo environment={variable.environment} className="text-sm" />
</InputGroup>

<InputGroup className="w-auto">
<Switch
variant="medium"
label={<span className="text-text-bright">Secret value</span>}
checked={isSecret}
disabled={variable.isSecret}
className="-ml-2 inline-flex w-fit"
onCheckedChange={setIsSecret}
/>
<Hint className="-mt-1">
{variable.isSecret
? "This variable is secret and cannot be changed back."
: "Once enabled, the value will be hidden and cannot be revealed again."}
</Hint>
</InputGroup>

<InputGroup fullWidth>
<Label>Value</Label>
<Input
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ export class EnvironmentVariablesRepository implements Repository {
id: string;
environmentId: string;
value: string;
isSecret?: boolean;
}
): Promise<Result> {
const project = await this.prismaClient.project.findFirst({
Expand Down Expand Up @@ -426,6 +427,20 @@ export class EnvironmentVariablesRepository implements Repository {
await secretStore.setSecret<{ secret: string }>(key, {
secret: options.value,
});

if (options.isSecret) {
await tx.environmentVariableValue.update({
where: {
variableId_environmentId: {
variableId: environmentVariable.id,
environmentId: options.environmentId,
},
},
data: {
isSecret: true,
},
});
}
});

return {
Expand Down
1 change: 1 addition & 0 deletions apps/webapp/app/v3/environmentVariables/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export const EditEnvironmentVariableValue = z.object({
id: z.string(),
environmentId: z.string(),
value: z.string(),
isSecret: z.preprocess((val) => val === "true" || val === true, z.boolean()).optional(),
});
export type EditEnvironmentVariableValue = z.infer<typeof EditEnvironmentVariableValue>;

Expand Down