mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 09:30:09 +00:00
Merge pull request #3835 from Infisical/feat/gitlabSecretSync
feat(secret-sync): Add gitlab secret sync
This commit is contained in:
+282
@@ -0,0 +1,282 @@
|
||||
import { Controller, useFormContext, useWatch } from "react-hook-form";
|
||||
import { SingleValue } from "react-select";
|
||||
import { faCircleInfo, faQuestionCircle } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
|
||||
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
|
||||
import {
|
||||
FilterableSelect,
|
||||
FormControl,
|
||||
Input,
|
||||
Select,
|
||||
SelectItem,
|
||||
Switch,
|
||||
Tooltip
|
||||
} from "@app/components/v2";
|
||||
import {
|
||||
TGitLabGroup,
|
||||
TGitLabProject,
|
||||
useGitlabConnectionListGroups,
|
||||
useGitlabConnectionListProjects
|
||||
} from "@app/hooks/api/appConnections/gitlab";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
import { GitLabSyncScope } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
|
||||
|
||||
import { TSecretSyncForm } from "../schemas";
|
||||
|
||||
const SecretProtectionOption = ({
|
||||
title,
|
||||
isEnabled,
|
||||
onChange,
|
||||
id,
|
||||
isDisabled = false,
|
||||
tooltip
|
||||
}: {
|
||||
title: string;
|
||||
isEnabled: boolean;
|
||||
onChange: (checked: boolean) => void;
|
||||
id: string;
|
||||
isDisabled?: boolean;
|
||||
tooltip?: string;
|
||||
}) => {
|
||||
return (
|
||||
<Switch
|
||||
className="bg-mineshaft-400/80 shadow-inner data-[state=checked]:bg-green/80"
|
||||
id={id}
|
||||
thumbClassName="bg-mineshaft-800"
|
||||
onCheckedChange={onChange}
|
||||
isChecked={isEnabled}
|
||||
isDisabled={isDisabled}
|
||||
containerClassName="w-full"
|
||||
>
|
||||
<p>
|
||||
{title}{" "}
|
||||
{tooltip && (
|
||||
<Tooltip className="max-w-md" content={tooltip}>
|
||||
<FontAwesomeIcon icon={faQuestionCircle} size="sm" className="ml-1" />
|
||||
</Tooltip>
|
||||
)}
|
||||
</p>
|
||||
</Switch>
|
||||
);
|
||||
};
|
||||
|
||||
export const GitLabSyncFields = () => {
|
||||
const { control, setValue } = useFormContext<
|
||||
TSecretSyncForm & { destination: SecretSync.GitLab }
|
||||
>();
|
||||
|
||||
const connectionId = useWatch({ name: "connection.id", control });
|
||||
const scope = useWatch({ name: "destinationConfig.scope", control });
|
||||
const shouldMaskSecrets = useWatch({ name: "destinationConfig.shouldMaskSecrets", control });
|
||||
|
||||
const { data: groups, isLoading: isGroupsLoading } = useGitlabConnectionListGroups(connectionId, {
|
||||
enabled: Boolean(connectionId) && scope === GitLabSyncScope.Group
|
||||
});
|
||||
|
||||
const { data: projects, isLoading: isProjectsLoading } = useGitlabConnectionListProjects(
|
||||
connectionId,
|
||||
{
|
||||
enabled: Boolean(connectionId)
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="h-full overflow-auto">
|
||||
<SecretSyncConnectionField
|
||||
onChange={() => {
|
||||
setValue("destinationConfig.projectId", "");
|
||||
setValue("destinationConfig.projectName", "");
|
||||
setValue("destinationConfig.groupId", "");
|
||||
setValue("destinationConfig.groupName", "");
|
||||
setValue("destinationConfig.scope", GitLabSyncScope.Project);
|
||||
}}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="destinationConfig.scope"
|
||||
control={control}
|
||||
defaultValue={GitLabSyncScope.Project}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl errorText={error?.message} isError={Boolean(error?.message)} label="Scope">
|
||||
<Select
|
||||
value={value}
|
||||
onValueChange={(val) => {
|
||||
onChange(val);
|
||||
setValue("destinationConfig.projectId", "");
|
||||
setValue("destinationConfig.projectName", "");
|
||||
setValue("destinationConfig.groupId", "");
|
||||
setValue("destinationConfig.groupName", "");
|
||||
}}
|
||||
className="w-full border border-mineshaft-500 capitalize"
|
||||
position="popper"
|
||||
placeholder="Select a scope..."
|
||||
dropdownContainerClassName="max-w-none"
|
||||
>
|
||||
{Object.values(GitLabSyncScope).map((projectScope) => (
|
||||
<SelectItem className="capitalize" value={projectScope} key={projectScope}>
|
||||
{projectScope.replace("-", " ")}
|
||||
</SelectItem>
|
||||
))}
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
{scope === GitLabSyncScope.Group && (
|
||||
<Controller
|
||||
name="destinationConfig.groupId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
label="Group"
|
||||
helperText={
|
||||
<Tooltip
|
||||
className="max-w-md"
|
||||
content="Ensure the group exists in the connection's GitLab instance URL."
|
||||
>
|
||||
<div>
|
||||
<span>Don't see the group you're looking for?</span>{" "}
|
||||
<FontAwesomeIcon icon={faCircleInfo} className="text-mineshaft-400" />
|
||||
</div>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isGroupsLoading && Boolean(connectionId)}
|
||||
isDisabled={!connectionId}
|
||||
value={groups?.find((group) => group.id === value) ?? null}
|
||||
onChange={(option) => {
|
||||
onChange((option as SingleValue<TGitLabGroup>)?.id ?? "");
|
||||
setValue(
|
||||
"destinationConfig.groupName",
|
||||
(option as SingleValue<TGitLabGroup>)?.name ?? ""
|
||||
);
|
||||
}}
|
||||
options={groups}
|
||||
placeholder="Select a group..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{scope === GitLabSyncScope.Project && (
|
||||
<Controller
|
||||
name="destinationConfig.projectId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
label="GitLab Project"
|
||||
helperText={
|
||||
<Tooltip
|
||||
className="max-w-md"
|
||||
content="Ensure the project exists in the connection's GitLab instance URL and the connection has access to it."
|
||||
>
|
||||
<div>
|
||||
<span>Don't see the project you're looking for?</span>{" "}
|
||||
<FontAwesomeIcon icon={faCircleInfo} className="text-mineshaft-400" />
|
||||
</div>
|
||||
</Tooltip>
|
||||
}
|
||||
>
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isProjectsLoading && Boolean(connectionId)}
|
||||
isDisabled={!connectionId}
|
||||
value={projects?.find((project) => project.id === value) ?? null}
|
||||
onChange={(option) => {
|
||||
onChange((option as SingleValue<TGitLabProject>)?.id ?? "");
|
||||
setValue(
|
||||
"destinationConfig.projectName",
|
||||
(option as SingleValue<TGitLabProject>)?.name ?? ""
|
||||
);
|
||||
}}
|
||||
options={projects}
|
||||
placeholder="Select a project..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
defaultValue=""
|
||||
name="destinationConfig.targetEnvironment"
|
||||
render={({ field, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
label="GitLab Environment Scope (Optional)"
|
||||
isError={Boolean(error)}
|
||||
errorText={error?.message}
|
||||
>
|
||||
<Input {...field} placeholder="*" />
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
{/* Secret Protection Settings Section */}
|
||||
<div className="mt-6">
|
||||
<div className="space-y-4">
|
||||
<Controller
|
||||
control={control}
|
||||
name="destinationConfig.shouldProtectSecrets"
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<SecretProtectionOption
|
||||
id="should-protect-secrets"
|
||||
title="Mark secrets as Protected"
|
||||
isEnabled={value || false}
|
||||
onChange={onChange}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
name="destinationConfig.shouldMaskSecrets"
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<SecretProtectionOption
|
||||
id="should-mask-secrets"
|
||||
title="Mark secrets as Masked"
|
||||
tooltip="GitLab has limitations for masked variables: secrets must be at least 8 characters long and not match existing CI/CD variable names. Secrets not meeting these criteria won't be masked."
|
||||
isEnabled={value || false}
|
||||
onChange={(checked) => {
|
||||
onChange(checked);
|
||||
if (!checked) {
|
||||
setValue("destinationConfig.shouldHideSecrets", false);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
name="destinationConfig.shouldHideSecrets"
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<div className="max-h-32 opacity-100 transition-all duration-300">
|
||||
<SecretProtectionOption
|
||||
id="should-hide-secrets"
|
||||
title="Mark secrets as Hidden"
|
||||
tooltip="Secrets can only be marked as hidden if they are also masked. If this is enabled, Infisical will not be able to unhide/unmask secrets from the sync destination if you disable the option later."
|
||||
isEnabled={value || false}
|
||||
onChange={onChange}
|
||||
isDisabled={!shouldMaskSecrets}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
+3
@@ -15,6 +15,7 @@ import { DatabricksSyncFields } from "./DatabricksSyncFields";
|
||||
import { FlyioSyncFields } from "./FlyioSyncFields";
|
||||
import { GcpSyncFields } from "./GcpSyncFields";
|
||||
import { GitHubSyncFields } from "./GitHubSyncFields";
|
||||
import { GitLabSyncFields } from "./GitLabSyncFields";
|
||||
import { HCVaultSyncFields } from "./HCVaultSyncFields";
|
||||
import { HerokuSyncFields } from "./HerokuSyncFields";
|
||||
import { HumanitecSyncFields } from "./HumanitecSyncFields";
|
||||
@@ -71,6 +72,8 @@ export const SecretSyncDestinationFields = () => {
|
||||
return <RenderSyncFields />;
|
||||
case SecretSync.Flyio:
|
||||
return <FlyioSyncFields />;
|
||||
case SecretSync.GitLab:
|
||||
return <GitLabSyncFields />;
|
||||
case SecretSync.CloudflarePages:
|
||||
return <CloudflarePagesSyncFields />;
|
||||
default:
|
||||
|
||||
+1
@@ -55,6 +55,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
|
||||
case SecretSync.Heroku:
|
||||
case SecretSync.Render:
|
||||
case SecretSync.Flyio:
|
||||
case SecretSync.GitLab:
|
||||
case SecretSync.CloudflarePages:
|
||||
AdditionalSyncOptionsFieldsComponent = null;
|
||||
break;
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
import { useFormContext } from "react-hook-form";
|
||||
|
||||
import { GenericFieldLabel } from "@app/components/secret-syncs";
|
||||
import { TSecretSyncForm } from "@app/components/secret-syncs/forms/schemas";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
import { GitLabSyncScope } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
|
||||
|
||||
export const GitLabSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.GitLab }>();
|
||||
const projectName = watch("destinationConfig.projectName");
|
||||
const targetEnvironment = watch("destinationConfig.targetEnvironment");
|
||||
const groupName = watch("destinationConfig.groupName");
|
||||
const scope = watch("destinationConfig.scope");
|
||||
const shouldProtectSecrets = watch("destinationConfig.shouldProtectSecrets");
|
||||
const shouldMaskSecrets = watch("destinationConfig.shouldMaskSecrets");
|
||||
const shouldHideSecrets = watch("destinationConfig.shouldHideSecrets");
|
||||
|
||||
return (
|
||||
<>
|
||||
<GenericFieldLabel label="Scope">{scope}</GenericFieldLabel>
|
||||
{scope === GitLabSyncScope.Project && (
|
||||
<GenericFieldLabel label="Project Name">{projectName}</GenericFieldLabel>
|
||||
)}
|
||||
{scope === GitLabSyncScope.Group && (
|
||||
<GenericFieldLabel label="Group Name">{groupName}</GenericFieldLabel>
|
||||
)}
|
||||
{targetEnvironment && (
|
||||
<GenericFieldLabel label="Environment">{targetEnvironment}</GenericFieldLabel>
|
||||
)}
|
||||
<GenericFieldLabel label="Protect Secrets">
|
||||
{shouldProtectSecrets ? "Yes" : "No"}
|
||||
</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Mask Secrets">{shouldMaskSecrets ? "Yes" : "No"}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Hide Secrets">{shouldHideSecrets ? "Yes" : "No"}</GenericFieldLabel>
|
||||
</>
|
||||
);
|
||||
};
|
||||
+4
@@ -24,6 +24,7 @@ import { DatabricksSyncReviewFields } from "./DatabricksSyncReviewFields";
|
||||
import { FlyioSyncReviewFields } from "./FlyioSyncReviewFields";
|
||||
import { GcpSyncReviewFields } from "./GcpSyncReviewFields";
|
||||
import { GitHubSyncReviewFields } from "./GitHubSyncReviewFields";
|
||||
import { GitLabSyncReviewFields } from "./GitLabSyncReviewFields";
|
||||
import { HCVaultSyncReviewFields } from "./HCVaultSyncReviewFields";
|
||||
import { HerokuSyncReviewFields } from "./HerokuSyncReviewFields";
|
||||
import { HumanitecSyncReviewFields } from "./HumanitecSyncReviewFields";
|
||||
@@ -117,6 +118,9 @@ export const SecretSyncReviewFields = () => {
|
||||
case SecretSync.Flyio:
|
||||
DestinationFieldsComponent = <FlyioSyncReviewFields />;
|
||||
break;
|
||||
case SecretSync.GitLab:
|
||||
DestinationFieldsComponent = <GitLabSyncReviewFields />;
|
||||
break;
|
||||
case SecretSync.CloudflarePages:
|
||||
DestinationFieldsComponent = <CloudflarePagesSyncReviewFields />;
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { BaseSecretSyncSchema } from "@app/components/secret-syncs/forms/schemas/base-secret-sync-schema";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
import { GitLabSyncScope } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
|
||||
|
||||
export const GitlabSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||
z.object({
|
||||
destination: z.literal(SecretSync.GitLab),
|
||||
destinationConfig: z.discriminatedUnion("scope", [
|
||||
z.object({
|
||||
scope: z.literal(GitLabSyncScope.Project),
|
||||
projectId: z.string().trim().min(1, "Project ID required"),
|
||||
projectName: z.string().trim().min(1, "Project name required"),
|
||||
targetEnvironment: z.string().optional(),
|
||||
shouldProtectSecrets: z.boolean().optional().default(false),
|
||||
shouldMaskSecrets: z.boolean().optional().default(false),
|
||||
shouldHideSecrets: z.boolean().optional().default(false)
|
||||
}),
|
||||
z.object({
|
||||
scope: z.literal(GitLabSyncScope.Group),
|
||||
targetEnvironment: z.string().optional(),
|
||||
groupId: z.string().trim().min(1, "Group ID required"),
|
||||
groupName: z.string().trim().min(1, "Group name required"),
|
||||
shouldProtectSecrets: z.boolean().optional().default(false),
|
||||
shouldMaskSecrets: z.boolean().optional().default(false),
|
||||
shouldHideSecrets: z.boolean().optional().default(false)
|
||||
})
|
||||
])
|
||||
})
|
||||
);
|
||||
@@ -12,6 +12,7 @@ import { DatabricksSyncDestinationSchema } from "./databricks-sync-destination-s
|
||||
import { FlyioSyncDestinationSchema } from "./flyio-sync-destination-schema";
|
||||
import { GcpSyncDestinationSchema } from "./gcp-sync-destination-schema";
|
||||
import { GitHubSyncDestinationSchema } from "./github-sync-destination-schema";
|
||||
import { GitlabSyncDestinationSchema } from "./gitlab-sync-destination-schema";
|
||||
import { HCVaultSyncDestinationSchema } from "./hc-vault-sync-destination-schema";
|
||||
import { HerokuSyncDestinationSchema } from "./heroku-sync-destination-schema";
|
||||
import { HumanitecSyncDestinationSchema } from "./humanitec-sync-destination-schema";
|
||||
@@ -43,6 +44,7 @@ const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
HerokuSyncDestinationSchema,
|
||||
RenderSyncDestinationSchema,
|
||||
FlyioSyncDestinationSchema,
|
||||
GitlabSyncDestinationSchema,
|
||||
CloudflarePagesSyncDestinationSchema
|
||||
]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user