mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 15:40:47 +00:00
feat(secret-sync): Add gitlab secret sync
This commit is contained in:
+278
@@ -0,0 +1,278 @@
|
||||
import { Controller, useFormContext, useWatch } from "react-hook-form";
|
||||
import { SingleValue } from "react-select";
|
||||
import { faCircleInfo } 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 (
|
||||
<div className="flex items-start justify-between rounded-lg border border-mineshaft-600 bg-mineshaft-800/50 p-4 transition-all duration-200 hover:border-mineshaft-500">
|
||||
<div className="flex flex-1 items-start space-x-3">
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="mb-1 flex items-center gap-2">
|
||||
<h4 className="text-sm font-medium text-bunker-100">{title}</h4>
|
||||
{tooltip && (
|
||||
<Tooltip className="max-w-sm" content={tooltip}>
|
||||
<FontAwesomeIcon
|
||||
icon={faCircleInfo}
|
||||
className="cursor-help text-xs text-mineshaft-400 hover:text-mineshaft-300"
|
||||
/>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="ml-4 flex-shrink-0">
|
||||
<Switch id={id} onCheckedChange={onChange} isChecked={isEnabled} isDisabled={isDisabled} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
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 selectedGroup = useWatch({ name: "destinationConfig.groupId", 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,
|
||||
selectedGroup,
|
||||
{
|
||||
enabled: Boolean(connectionId)
|
||||
}
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="h-[calc(100vh-20rem)] overflow-auto">
|
||||
<SecretSyncConnectionField
|
||||
onChange={() => {
|
||||
setValue("destinationConfig.projectId", "");
|
||||
setValue("destinationConfig.projectName", "");
|
||||
setValue("destinationConfig.groupId", "");
|
||||
setValue("destinationConfig.scope", GitlabSyncScope.Individual);
|
||||
}}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="destinationConfig.scope"
|
||||
control={control}
|
||||
defaultValue={GitlabSyncScope.Individual}
|
||||
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", "");
|
||||
}}
|
||||
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 ?? "");
|
||||
}}
|
||||
options={groups}
|
||||
placeholder="Select a group..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<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."
|
||||
>
|
||||
<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 || (scope === GitlabSyncScope.Group && !selectedGroup)}
|
||||
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 Infisical secrets in GitLab as 'Protected' secrets"
|
||||
isEnabled={value || false}
|
||||
onChange={onChange}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
control={control}
|
||||
name="destinationConfig.shouldMaskSecrets"
|
||||
render={({ field: { onChange, value } }) => (
|
||||
<SecretProtectionOption
|
||||
id="should-mask-secrets"
|
||||
title="Mark Infisical secrets in GitLab as 'Masked' secrets"
|
||||
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 Infisical secrets in GitLab as 'Protected' secrets"
|
||||
tooltip="Secrets can only be marked as hidden if they are also masked."
|
||||
isEnabled={value || false}
|
||||
onChange={onChange}
|
||||
isDisabled={!shouldMaskSecrets}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
+3
@@ -14,6 +14,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";
|
||||
@@ -70,6 +71,8 @@ export const SecretSyncDestinationFields = () => {
|
||||
return <RenderSyncFields />;
|
||||
case SecretSync.Flyio:
|
||||
return <FlyioSyncFields />;
|
||||
case SecretSync.Gitlab:
|
||||
return <GitLabSyncFields />;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Config Field: ${destination}`);
|
||||
}
|
||||
|
||||
+1
@@ -55,6 +55,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
|
||||
case SecretSync.Heroku:
|
||||
case SecretSync.Render:
|
||||
case SecretSync.Flyio:
|
||||
case SecretSync.Gitlab:
|
||||
AdditionalSyncOptionsFieldsComponent = null;
|
||||
break;
|
||||
default:
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
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";
|
||||
|
||||
export const GitLabSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.Gitlab }>();
|
||||
const projectId = watch("destinationConfig.projectId");
|
||||
const targetEnvironment = watch("destinationConfig.targetEnvironment");
|
||||
const groupId = watch("destinationConfig.groupId");
|
||||
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>
|
||||
<GenericFieldLabel label="Project ID">{projectId}</GenericFieldLabel>
|
||||
{groupId && <GenericFieldLabel label="Group ID">{groupId}</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
@@ -23,6 +23,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";
|
||||
@@ -116,6 +117,9 @@ export const SecretSyncReviewFields = () => {
|
||||
case SecretSync.Flyio:
|
||||
DestinationFieldsComponent = <FlyioSyncReviewFields />;
|
||||
break;
|
||||
case SecretSync.Gitlab:
|
||||
DestinationFieldsComponent = <GitLabSyncReviewFields />;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Review Fields: ${destination}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
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.Individual),
|
||||
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),
|
||||
projectId: z.string().trim().min(1, "Project ID required"),
|
||||
projectName: z.string().trim().min(1, "Project name required"),
|
||||
targetEnvironment: z.string().optional(),
|
||||
groupId: z.string().trim().min(1, "Group ID required"),
|
||||
shouldProtectSecrets: z.boolean().optional().default(false),
|
||||
shouldMaskSecrets: z.boolean().optional().default(false),
|
||||
shouldHideSecrets: z.boolean().optional().default(false)
|
||||
})
|
||||
])
|
||||
})
|
||||
);
|
||||
@@ -11,6 +11,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";
|
||||
@@ -41,7 +42,8 @@ const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
OnePassSyncDestinationSchema,
|
||||
HerokuSyncDestinationSchema,
|
||||
RenderSyncDestinationSchema,
|
||||
FlyioSyncDestinationSchema
|
||||
FlyioSyncDestinationSchema,
|
||||
GitlabSyncDestinationSchema
|
||||
]);
|
||||
|
||||
export const SecretSyncFormSchema = SecretSyncUnionSchema;
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
GcpConnectionMethod,
|
||||
GitHubConnectionMethod,
|
||||
GitHubRadarConnectionMethod,
|
||||
GitlabConnectionMethod,
|
||||
HCVaultConnectionMethod,
|
||||
HumanitecConnectionMethod,
|
||||
LdapConnectionMethod,
|
||||
@@ -84,7 +85,8 @@ export const APP_CONNECTION_MAP: Record<
|
||||
[AppConnection.OnePass]: { name: "1Password", image: "1Password.png" },
|
||||
[AppConnection.Heroku]: { name: "Heroku", image: "Heroku.png" },
|
||||
[AppConnection.Render]: { name: "Render", image: "Render.png" },
|
||||
[AppConnection.Flyio]: { name: "Fly.io", image: "Flyio.svg" }
|
||||
[AppConnection.Flyio]: { name: "Fly.io", image: "Flyio.svg" },
|
||||
[AppConnection.Gitlab]: { name: "Gitlab", image: "GitLab.png" }
|
||||
};
|
||||
|
||||
export const getAppConnectionMethodDetails = (method: TAppConnection["method"]) => {
|
||||
@@ -98,6 +100,7 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])
|
||||
case AzureDevOpsConnectionMethod.OAuth:
|
||||
case GitHubConnectionMethod.OAuth:
|
||||
case HerokuConnectionMethod.OAuth:
|
||||
case GitlabConnectionMethod.OAuth:
|
||||
return { name: "OAuth", icon: faPassport };
|
||||
case AwsConnectionMethod.AccessKey:
|
||||
case OCIConnectionMethod.AccessKey:
|
||||
|
||||
@@ -73,6 +73,10 @@ export const SECRET_SYNC_MAP: Record<SecretSync, { name: string; image: string }
|
||||
[SecretSync.Flyio]: {
|
||||
name: "Fly.io",
|
||||
image: "Flyio.svg"
|
||||
},
|
||||
[SecretSync.Gitlab]: {
|
||||
name: "Gitlab",
|
||||
image: "GitLab.png"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -96,7 +100,8 @@ export const SECRET_SYNC_CONNECTION_MAP: Record<SecretSync, AppConnection> = {
|
||||
[SecretSync.OnePass]: AppConnection.OnePass,
|
||||
[SecretSync.Heroku]: AppConnection.Heroku,
|
||||
[SecretSync.Render]: AppConnection.Render,
|
||||
[SecretSync.Flyio]: AppConnection.Flyio
|
||||
[SecretSync.Flyio]: AppConnection.Flyio,
|
||||
[SecretSync.Gitlab]: AppConnection.Gitlab
|
||||
};
|
||||
|
||||
export const SECRET_SYNC_INITIAL_SYNC_BEHAVIOR_MAP: Record<
|
||||
|
||||
@@ -25,5 +25,6 @@ export enum AppConnection {
|
||||
OnePass = "1password",
|
||||
Heroku = "heroku",
|
||||
Render = "render",
|
||||
Flyio = "flyio"
|
||||
Flyio = "flyio",
|
||||
Gitlab = "gitlab"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from "./queries";
|
||||
export * from "./types";
|
||||
@@ -0,0 +1,65 @@
|
||||
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { appConnectionKeys } from "../queries";
|
||||
import { TGitLabGroup, TGitLabProject } from "./types";
|
||||
|
||||
const gitlabConnectionKeys = {
|
||||
all: [...appConnectionKeys.all, "gitlab"] as const,
|
||||
listProjects: (connectionId: string, group?: string) =>
|
||||
[...gitlabConnectionKeys.all, "projects", connectionId, group] as const,
|
||||
listGroups: (connectionId: string) =>
|
||||
[...gitlabConnectionKeys.all, "groups", connectionId] as const
|
||||
};
|
||||
|
||||
export const useGitlabConnectionListProjects = (
|
||||
connectionId: string,
|
||||
group?: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TGitLabProject[],
|
||||
unknown,
|
||||
TGitLabProject[],
|
||||
ReturnType<typeof gitlabConnectionKeys.listProjects>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: gitlabConnectionKeys.listProjects(connectionId, group),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TGitLabProject[]>(
|
||||
`/api/v1/app-connections/gitlab/${connectionId}/projects${group ? `?group=${group}` : ""}`
|
||||
);
|
||||
|
||||
return data;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
|
||||
export const useGitlabConnectionListGroups = (
|
||||
connectionId: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
TGitLabGroup[],
|
||||
unknown,
|
||||
TGitLabGroup[],
|
||||
ReturnType<typeof gitlabConnectionKeys.listGroups>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: gitlabConnectionKeys.listGroups(connectionId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<TGitLabGroup[]>(
|
||||
`/api/v1/app-connections/gitlab/${connectionId}/groups`
|
||||
);
|
||||
|
||||
return data;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
export type TGitLabProject = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type TGitLabGroup = {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
@@ -123,6 +123,11 @@ export type TFlyioConnectionOption = TAppConnectionOptionBase & {
|
||||
app: AppConnection.Flyio;
|
||||
};
|
||||
|
||||
export type TGitlabConnectionOption = TAppConnectionOptionBase & {
|
||||
app: AppConnection.Gitlab;
|
||||
oauthClientId?: string;
|
||||
};
|
||||
|
||||
export type TAppConnectionOption =
|
||||
| TAwsConnectionOption
|
||||
| TGitHubConnectionOption
|
||||
@@ -148,7 +153,8 @@ export type TAppConnectionOption =
|
||||
| TOnePassConnectionOption
|
||||
| THerokuConnectionOption
|
||||
| TRenderConnectionOption
|
||||
| TFlyioConnectionOption;
|
||||
| TFlyioConnectionOption
|
||||
| TGitlabConnectionOption;
|
||||
|
||||
export type TAppConnectionOptionMap = {
|
||||
[AppConnection.AWS]: TAwsConnectionOption;
|
||||
@@ -178,4 +184,5 @@ export type TAppConnectionOptionMap = {
|
||||
[AppConnection.Heroku]: THerokuConnectionOption;
|
||||
[AppConnection.Render]: TRenderConnectionOption;
|
||||
[AppConnection.Flyio]: TFlyioConnectionOption;
|
||||
[AppConnection.Gitlab]: TGitlabConnectionOption;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||
import { TRootAppConnection } from "@app/hooks/api/appConnections/types/root-connection";
|
||||
|
||||
export enum GitlabConnectionMethod {
|
||||
AccessToken = "access-token",
|
||||
OAuth = "oauth"
|
||||
}
|
||||
|
||||
export type TGitlabConnection = TRootAppConnection & { app: AppConnection.Gitlab } & (
|
||||
| {
|
||||
method: GitlabConnectionMethod.AccessToken;
|
||||
credentials: {
|
||||
instanceUrl?: string;
|
||||
accessToken: string;
|
||||
};
|
||||
}
|
||||
| {
|
||||
method: GitlabConnectionMethod.OAuth;
|
||||
credentials: {
|
||||
code: string;
|
||||
instanceUrl?: string;
|
||||
};
|
||||
}
|
||||
);
|
||||
@@ -13,6 +13,7 @@ import { TFlyioConnection } from "./flyio-connection";
|
||||
import { TGcpConnection } from "./gcp-connection";
|
||||
import { TGitHubConnection } from "./github-connection";
|
||||
import { TGitHubRadarConnection } from "./github-radar-connection";
|
||||
import { TGitlabConnection } from "./gitlab-connection";
|
||||
import { THCVaultConnection } from "./hc-vault-connection";
|
||||
import { THerokuConnection } from "./heroku-connection";
|
||||
import { THumanitecConnection } from "./humanitec-connection";
|
||||
@@ -41,6 +42,7 @@ export * from "./flyio-connection";
|
||||
export * from "./gcp-connection";
|
||||
export * from "./github-connection";
|
||||
export * from "./github-radar-connection";
|
||||
export * from "./gitlab-connection";
|
||||
export * from "./hc-vault-connection";
|
||||
export * from "./heroku-connection";
|
||||
export * from "./humanitec-connection";
|
||||
@@ -83,7 +85,8 @@ export type TAppConnection =
|
||||
| TOnePassConnection
|
||||
| THerokuConnection
|
||||
| TRenderConnection
|
||||
| TFlyioConnection;
|
||||
| TFlyioConnection
|
||||
| TGitlabConnection;
|
||||
|
||||
export type TAvailableAppConnection = Pick<TAppConnection, "name" | "id">;
|
||||
|
||||
@@ -138,4 +141,5 @@ export type TAppConnectionMap = {
|
||||
[AppConnection.Heroku]: THerokuConnection;
|
||||
[AppConnection.Render]: TRenderConnection;
|
||||
[AppConnection.Flyio]: TFlyioConnection;
|
||||
[AppConnection.Gitlab]: TGitlabConnection;
|
||||
};
|
||||
|
||||
@@ -18,7 +18,8 @@ export enum SecretSync {
|
||||
OnePass = "1password",
|
||||
Heroku = "heroku",
|
||||
Render = "render",
|
||||
Flyio = "flyio"
|
||||
Flyio = "flyio",
|
||||
Gitlab = "gitlab"
|
||||
}
|
||||
|
||||
export enum SecretSyncStatus {
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
import { TRootSecretSync } from "@app/hooks/api/secretSyncs/types/root-sync";
|
||||
|
||||
export enum GitlabSyncScope {
|
||||
Individual = "individual",
|
||||
Group = "group"
|
||||
}
|
||||
|
||||
export type TGitlabSync = TRootSecretSync & {
|
||||
destination: SecretSync.Gitlab;
|
||||
destinationConfig:
|
||||
| {
|
||||
scope: GitlabSyncScope.Individual;
|
||||
projectId: string;
|
||||
projectName: string;
|
||||
targetEnvironment?: string;
|
||||
shouldProtectSecrets?: boolean;
|
||||
shouldMaskSecrets?: boolean;
|
||||
shouldHideSecrets?: boolean;
|
||||
}
|
||||
| {
|
||||
scope: GitlabSyncScope.Group;
|
||||
groupId: string;
|
||||
projectId: string;
|
||||
projectName: string;
|
||||
targetEnvironment?: string;
|
||||
shouldProtectSecrets?: boolean;
|
||||
shouldMaskSecrets?: boolean;
|
||||
shouldHideSecrets?: boolean;
|
||||
};
|
||||
connection: {
|
||||
app: AppConnection.Gitlab;
|
||||
name: string;
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
@@ -13,6 +13,7 @@ import { TDatabricksSync } from "./databricks-sync";
|
||||
import { TFlyioSync } from "./flyio-sync";
|
||||
import { TGcpSync } from "./gcp-sync";
|
||||
import { TGitHubSync } from "./github-sync";
|
||||
import { TGitlabSync } from "./gitlab-sync";
|
||||
import { THCVaultSync } from "./hc-vault-sync";
|
||||
import { THerokuSync } from "./heroku-sync";
|
||||
import { THumanitecSync } from "./humanitec-sync";
|
||||
@@ -49,7 +50,8 @@ export type TSecretSync =
|
||||
| TOnePassSync
|
||||
| THerokuSync
|
||||
| TRenderSync
|
||||
| TFlyioSync;
|
||||
| TFlyioSync
|
||||
| TGitlabSync;
|
||||
|
||||
export type TListSecretSyncs = { secretSyncs: TSecretSync[] };
|
||||
|
||||
|
||||
+5
@@ -22,6 +22,7 @@ import { FlyioConnectionForm } from "./FlyioConnectionForm";
|
||||
import { GcpConnectionForm } from "./GcpConnectionForm";
|
||||
import { GitHubConnectionForm } from "./GitHubConnectionForm";
|
||||
import { GitHubRadarConnectionForm } from "./GitHubRadarConnectionForm";
|
||||
import { GitLabConnectionForm } from "./GitLabConnectionForm";
|
||||
import { HCVaultConnectionForm } from "./HCVaultConnectionForm";
|
||||
import { HerokuConnectionForm } from "./HerokuAppConnectionForm";
|
||||
import { HumanitecConnectionForm } from "./HumanitecConnectionForm";
|
||||
@@ -128,6 +129,8 @@ const CreateForm = ({ app, onComplete }: CreateFormProps) => {
|
||||
return <RenderConnectionForm onSubmit={onSubmit} />;
|
||||
case AppConnection.Flyio:
|
||||
return <FlyioConnectionForm onSubmit={onSubmit} />;
|
||||
case AppConnection.Gitlab:
|
||||
return <GitLabConnectionForm onSubmit={onSubmit} />;
|
||||
default:
|
||||
throw new Error(`Unhandled App ${app}`);
|
||||
}
|
||||
@@ -218,6 +221,8 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
|
||||
return <RenderConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||
case AppConnection.Flyio:
|
||||
return <FlyioConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||
case AppConnection.Gitlab:
|
||||
return <GitLabConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||
default:
|
||||
throw new Error(`Unhandled App ${(appConnection as TAppConnection).app}`);
|
||||
}
|
||||
|
||||
+297
@@ -0,0 +1,297 @@
|
||||
/* eslint-disable no-case-declarations */
|
||||
/* eslint-disable no-nested-ternary */
|
||||
import crypto from "crypto";
|
||||
|
||||
import { useState } from "react";
|
||||
import { Controller, FormProvider, useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
Button,
|
||||
FormControl,
|
||||
Input,
|
||||
ModalClose,
|
||||
SecretInput,
|
||||
Select,
|
||||
SelectItem
|
||||
} from "@app/components/v2";
|
||||
import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
|
||||
import { isInfisicalCloud } from "@app/helpers/platform";
|
||||
import { useGetAppConnectionOption } from "@app/hooks/api/appConnections";
|
||||
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||
import {
|
||||
GitlabConnectionMethod,
|
||||
TGitlabConnection
|
||||
} from "@app/hooks/api/appConnections/types/gitlab-connection";
|
||||
|
||||
import {
|
||||
genericAppConnectionFieldsSchema,
|
||||
GenericAppConnectionsFields
|
||||
} from "./GenericAppConnectionFields";
|
||||
|
||||
type Props = {
|
||||
appConnection?: TGitlabConnection;
|
||||
onSubmit: (formData: FormData) => Promise<void>;
|
||||
};
|
||||
|
||||
const formSchema = z.discriminatedUnion("method", [
|
||||
genericAppConnectionFieldsSchema.extend({
|
||||
app: z.literal(AppConnection.Gitlab),
|
||||
method: z.literal(GitlabConnectionMethod.AccessToken),
|
||||
credentials: z.object({
|
||||
accessToken: z.string().min(1, "Access token is required"),
|
||||
instanceUrl: z
|
||||
.string()
|
||||
.trim()
|
||||
.transform((value) => value || undefined)
|
||||
.refine((value) => (!value ? true : z.string().url().safeParse(value).success), {
|
||||
message: "Invalid instance URL"
|
||||
})
|
||||
.optional()
|
||||
})
|
||||
}),
|
||||
genericAppConnectionFieldsSchema.extend({
|
||||
app: z.literal(AppConnection.Gitlab),
|
||||
method: z.literal(GitlabConnectionMethod.OAuth),
|
||||
credentials: z.object({
|
||||
code: z.string().min(1, "Code is required"),
|
||||
instanceUrl: z
|
||||
.string()
|
||||
.trim()
|
||||
.transform((value) => value || undefined)
|
||||
.refine((value) => (!value ? true : z.string().url().safeParse(value).success), {
|
||||
message: "Invalid instance URL"
|
||||
})
|
||||
.optional()
|
||||
})
|
||||
})
|
||||
]);
|
||||
|
||||
type FormData = z.infer<typeof formSchema>;
|
||||
|
||||
export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Props) => {
|
||||
const isUpdate = Boolean(appConnection);
|
||||
const [isRedirecting, setIsRedirecting] = useState(false);
|
||||
|
||||
const {
|
||||
option: { oauthClientId },
|
||||
isLoading
|
||||
} = useGetAppConnectionOption(AppConnection.Gitlab);
|
||||
|
||||
const form = useForm<FormData>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues:
|
||||
appConnection?.method === GitlabConnectionMethod.OAuth
|
||||
? { ...appConnection, credentials: { code: "custom" } }
|
||||
: (appConnection ??
|
||||
({
|
||||
app: AppConnection.Gitlab,
|
||||
method: GitlabConnectionMethod.AccessToken,
|
||||
credentials: {
|
||||
accessToken: "",
|
||||
instanceUrl: ""
|
||||
}
|
||||
} as FormData))
|
||||
});
|
||||
|
||||
const {
|
||||
handleSubmit,
|
||||
control,
|
||||
watch,
|
||||
setValue,
|
||||
formState: { isSubmitting, isDirty }
|
||||
} = form;
|
||||
|
||||
const selectedMethod = watch("method");
|
||||
const gitLabURL = watch("credentials.instanceUrl");
|
||||
|
||||
const onSubmit = async (formData: FormData) => {
|
||||
try {
|
||||
switch (formData.method) {
|
||||
case GitlabConnectionMethod.AccessToken:
|
||||
await formSubmit(formData);
|
||||
break;
|
||||
|
||||
case GitlabConnectionMethod.OAuth:
|
||||
if (!oauthClientId) {
|
||||
return;
|
||||
}
|
||||
setIsRedirecting(true);
|
||||
|
||||
// Generate CSRF token
|
||||
const state = crypto.randomBytes(16).toString("hex");
|
||||
|
||||
// Store state and form data for callback
|
||||
localStorage.setItem("latestCSRFToken", state);
|
||||
localStorage.setItem(
|
||||
"gitlabConnectionFormData",
|
||||
JSON.stringify({
|
||||
...formData,
|
||||
connectionId: appConnection?.id,
|
||||
isUpdate
|
||||
})
|
||||
);
|
||||
|
||||
// Redirect to Gitlab OAuth
|
||||
const baseURL =
|
||||
gitLabURL && (gitLabURL as string)?.trim() !== ""
|
||||
? (gitLabURL as string)?.trim()
|
||||
: "https://gitlab.com";
|
||||
const oauthUrl = new URL(`${baseURL}/oauth/authorize`);
|
||||
oauthUrl.searchParams.set("client_id", oauthClientId);
|
||||
oauthUrl.searchParams.set(
|
||||
"redirect_uri",
|
||||
`${window.location.origin}/integrations/gitlab/oauth2/callback`
|
||||
);
|
||||
oauthUrl.searchParams.set("response_type", "code");
|
||||
oauthUrl.searchParams.set("state", state);
|
||||
|
||||
window.location.assign(oauthUrl.toString());
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error("Unhandled Gitlab Connection method");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error handling form submission:", error);
|
||||
setIsRedirecting(false);
|
||||
}
|
||||
};
|
||||
|
||||
let isMissingConfig: boolean;
|
||||
|
||||
switch (selectedMethod) {
|
||||
case GitlabConnectionMethod.OAuth:
|
||||
isMissingConfig = !oauthClientId;
|
||||
break;
|
||||
case GitlabConnectionMethod.AccessToken:
|
||||
isMissingConfig = false;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Gitlab Connection method: ${selectedMethod}`);
|
||||
}
|
||||
|
||||
const methodDetails = getAppConnectionMethodDetails(selectedMethod);
|
||||
|
||||
return (
|
||||
<FormProvider {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
{!isUpdate && <GenericAppConnectionsFields />}
|
||||
|
||||
<Controller
|
||||
name="credentials.instanceUrl"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
label="Self-hosted URL (optional)"
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
tooltipText="Will default to GitLab Cloud if not specified."
|
||||
>
|
||||
<Input
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
placeholder="https://gitlab.com"
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="method"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
tooltipText={`The method you would like to use to connect with ${
|
||||
APP_CONNECTION_MAP[AppConnection.Gitlab].name
|
||||
}. This field cannot be changed after creation.`}
|
||||
errorText={
|
||||
!isLoading && isMissingConfig && selectedMethod === GitlabConnectionMethod.OAuth
|
||||
? `Environment variables have not been configured. ${
|
||||
isInfisicalCloud()
|
||||
? "Please contact Infisical."
|
||||
: `See Docs to configure Gitlab ${methodDetails.name} Connections.`
|
||||
}`
|
||||
: error?.message
|
||||
}
|
||||
isError={Boolean(error?.message) || isMissingConfig}
|
||||
label="Method"
|
||||
>
|
||||
<Select
|
||||
isDisabled={isUpdate}
|
||||
value={value}
|
||||
onValueChange={(val) => {
|
||||
onChange(val);
|
||||
if (val === GitlabConnectionMethod.OAuth) {
|
||||
setValue("credentials.code", "custom");
|
||||
}
|
||||
}}
|
||||
className="w-full border border-mineshaft-500"
|
||||
position="popper"
|
||||
dropdownContainerClassName="max-w-none"
|
||||
>
|
||||
{Object.values(GitlabConnectionMethod).map((method) => {
|
||||
return (
|
||||
<SelectItem value={method} key={method}>
|
||||
{getAppConnectionMethodDetails(method).name}{" "}
|
||||
{method === GitlabConnectionMethod.AccessToken ? " (Recommended)" : ""}
|
||||
</SelectItem>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
|
||||
{selectedMethod === GitlabConnectionMethod.AccessToken && (
|
||||
<Controller
|
||||
name="credentials.accessToken"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
label="Access Token"
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
tooltipText="Your Gitlab Access Token"
|
||||
>
|
||||
<SecretInput
|
||||
containerClassName="text-gray-400 group-focus-within:!border-primary-400/50 border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"
|
||||
value={value}
|
||||
onChange={(e) => onChange(e.target.value)}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
<div className="mt-8 flex items-center">
|
||||
<Button
|
||||
className="mr-4"
|
||||
size="sm"
|
||||
type="submit"
|
||||
colorSchema="secondary"
|
||||
isLoading={isSubmitting || isRedirecting}
|
||||
isDisabled={
|
||||
isSubmitting ||
|
||||
(!isUpdate && !isDirty) ||
|
||||
(isMissingConfig && selectedMethod === GitlabConnectionMethod.OAuth) ||
|
||||
isRedirecting
|
||||
}
|
||||
>
|
||||
{isRedirecting && selectedMethod === GitlabConnectionMethod.OAuth
|
||||
? "Redirecting to Gitlab..."
|
||||
: isUpdate
|
||||
? "Reconnect to Gitlab"
|
||||
: "Connect to Gitlab"}
|
||||
</Button>
|
||||
<ModalClose asChild>
|
||||
<Button colorSchema="secondary" variant="plain">
|
||||
Cancel
|
||||
</Button>
|
||||
</ModalClose>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
);
|
||||
};
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import { TGitlabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
|
||||
|
||||
import { getSecretSyncDestinationColValues } from "../helpers";
|
||||
import { SecretSyncTableCell } from "../SecretSyncTableCell";
|
||||
|
||||
type Props = {
|
||||
secretSync: TGitlabSync;
|
||||
};
|
||||
|
||||
export const GitLabSyncDestinationCol = ({ secretSync }: Props) => {
|
||||
const { primaryText, secondaryText } = getSecretSyncDestinationColValues(secretSync);
|
||||
|
||||
return <SecretSyncTableCell primaryText={primaryText} secondaryText={secondaryText} />;
|
||||
};
|
||||
+3
@@ -11,6 +11,7 @@ import { DatabricksSyncDestinationCol } from "./DatabricksSyncDestinationCol";
|
||||
import { FlyioSyncDestinationCol } from "./FlyioSyncDestinationCol";
|
||||
import { GcpSyncDestinationCol } from "./GcpSyncDestinationCol";
|
||||
import { GitHubSyncDestinationCol } from "./GitHubSyncDestinationCol";
|
||||
import { GitLabSyncDestinationCol } from "./GitLabSyncDestinationCol";
|
||||
import { HCVaultSyncDestinationCol } from "./HCVaultSyncDestinationCol";
|
||||
import { HerokuSyncDestinationCol } from "./HerokuSyncDestinationCol";
|
||||
import { HumanitecSyncDestinationCol } from "./HumanitecSyncDestinationCol";
|
||||
@@ -67,6 +68,8 @@ export const SecretSyncDestinationCol = ({ secretSync }: Props) => {
|
||||
return <RenderSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.Flyio:
|
||||
return <FlyioSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.Gitlab:
|
||||
return <GitLabSyncDestinationCol secretSync={secretSync} />;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled Secret Sync Destination Col: ${(secretSync as TSecretSync).destination}`
|
||||
|
||||
+4
@@ -128,6 +128,10 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
|
||||
primaryText = destinationConfig.appId;
|
||||
secondaryText = "App ID";
|
||||
break;
|
||||
case SecretSync.Gitlab:
|
||||
primaryText = destinationConfig.projectName;
|
||||
secondaryText = destinationConfig.projectId;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Col Values ${destination}`);
|
||||
}
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
import { GenericFieldLabel } from "@app/components/secret-syncs";
|
||||
import { TGitlabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
|
||||
|
||||
type Props = {
|
||||
secretSync: TGitlabSync;
|
||||
};
|
||||
|
||||
export const GitLabSyncDestinationSection = ({ secretSync }: Props) => {
|
||||
const {
|
||||
destinationConfig: {
|
||||
projectName,
|
||||
projectId,
|
||||
targetEnvironment,
|
||||
shouldProtectSecrets,
|
||||
shouldMaskSecrets,
|
||||
shouldHideSecrets
|
||||
}
|
||||
} = secretSync;
|
||||
|
||||
return (
|
||||
<>
|
||||
<GenericFieldLabel label="Project Name">{projectName}</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Project ID">{projectId}</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
@@ -22,6 +22,7 @@ import { DatabricksSyncDestinationSection } from "./DatabricksSyncDestinationSec
|
||||
import { FlyioSyncDestinationSection } from "./FlyioSyncDestinationSection";
|
||||
import { GcpSyncDestinationSection } from "./GcpSyncDestinationSection";
|
||||
import { GitHubSyncDestinationSection } from "./GitHubSyncDestinationSection";
|
||||
import { GitLabSyncDestinationSection } from "./GitLabSyncDestinationSection";
|
||||
import { HCVaultSyncDestinationSection } from "./HCVaultSyncDestinationSection";
|
||||
import { HerokuSyncDestinationSection } from "./HerokuSyncDestinationSection";
|
||||
import { HumanitecSyncDestinationSection } from "./HumanitecSyncDestinationSection";
|
||||
@@ -106,6 +107,9 @@ export const SecretSyncDestinationSection = ({ secretSync, onEditDestination }:
|
||||
case SecretSync.Flyio:
|
||||
DestinationComponents = <FlyioSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
case SecretSync.Gitlab:
|
||||
DestinationComponents = <GitLabSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Section components: ${destination}`);
|
||||
}
|
||||
|
||||
+1
@@ -58,6 +58,7 @@ export const SecretSyncOptionsSection = ({ secretSync, onEditOptions }: Props) =
|
||||
case SecretSync.Heroku:
|
||||
case SecretSync.Render:
|
||||
case SecretSync.Flyio:
|
||||
case SecretSync.Gitlab:
|
||||
AdditionalSyncOptionsComponent = null;
|
||||
break;
|
||||
default:
|
||||
|
||||
+71
-23
@@ -3,11 +3,13 @@ import { useNavigate, useSearch } from "@tanstack/react-router";
|
||||
|
||||
import { ROUTE_PATHS } from "@app/const/routes";
|
||||
import { useWorkspace } from "@app/context";
|
||||
import { useAuthorizeIntegration } from "@app/hooks/api";
|
||||
import { useCreateAppConnection, useUpdateAppConnection } from "@app/hooks/api/appConnections";
|
||||
import { GitlabConnectionMethod } from "@app/hooks/api/appConnections/types/gitlab-connection";
|
||||
|
||||
export const GitLabOAuthCallbackPage = () => {
|
||||
const navigate = useNavigate();
|
||||
const { mutateAsync } = useAuthorizeIntegration();
|
||||
const { mutateAsync: createAppConnection } = useCreateAppConnection();
|
||||
const { mutateAsync: updateAppConnection } = useUpdateAppConnection();
|
||||
|
||||
const { code, state } = useSearch({
|
||||
from: ROUTE_PATHS.SecretManager.Integratons.GitlabOauthCallbackPage.id
|
||||
@@ -17,37 +19,83 @@ export const GitLabOAuthCallbackPage = () => {
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
try {
|
||||
// validate state
|
||||
const [csrfToken, url] = (state as string).split("|", 2);
|
||||
// Validate CSRF state token
|
||||
const [csrfToken] = (state as string).split("|", 2);
|
||||
const storedState = localStorage.getItem("latestCSRFToken");
|
||||
if (csrfToken !== storedState) {
|
||||
console.error("CSRF token mismatch");
|
||||
navigate({
|
||||
to: "/organization/app-connections",
|
||||
search: { error: "invalid_state" }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (csrfToken !== localStorage.getItem("latestCSRFToken")) return;
|
||||
localStorage.removeItem("latestCSRFToken");
|
||||
|
||||
const integrationAuth = await mutateAsync({
|
||||
workspaceId: currentWorkspace.id,
|
||||
code: code as string,
|
||||
integration: "gitlab",
|
||||
...(url === ""
|
||||
? {}
|
||||
: {
|
||||
url
|
||||
})
|
||||
});
|
||||
// Retrieve stored form dataAdd commentMore actions
|
||||
const storedFormData = localStorage.getItem("gitlabConnectionFormData");
|
||||
if (!storedFormData) {
|
||||
console.error("No stored form data found");
|
||||
navigate({
|
||||
to: "/organization/app-connections",
|
||||
search: { error: "missing_form_data" }
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = JSON.parse(storedFormData);
|
||||
localStorage.removeItem("gitlabConnectionFormData");
|
||||
|
||||
// Prepare app connection data with OAuth credentials
|
||||
const connectionData = {
|
||||
...formData,
|
||||
method: GitlabConnectionMethod.OAuth,
|
||||
credentials: {
|
||||
code: code as string
|
||||
}
|
||||
};
|
||||
|
||||
let appConnection;
|
||||
|
||||
// Create or update app connection
|
||||
if (formData.isUpdate && formData.connectionId) {
|
||||
appConnection = await updateAppConnection({
|
||||
connectionId: formData.connectionId,
|
||||
...connectionData
|
||||
});
|
||||
} else {
|
||||
appConnection = await createAppConnection({
|
||||
workspaceId: currentWorkspace.id,
|
||||
...connectionData
|
||||
});
|
||||
}
|
||||
|
||||
// Navigate to success page or app connections list
|
||||
|
||||
navigate({
|
||||
to: "/secret-manager/$projectId/integrations/gitlab/create",
|
||||
params: {
|
||||
projectId: currentWorkspace.id
|
||||
},
|
||||
to: "/organization/app-connections",
|
||||
search: {
|
||||
integrationAuthId: integrationAuth.id
|
||||
success: formData.isUpdate ? "connection_updated" : "connection_created",
|
||||
connectionId: appConnection.id
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
console.error("Error handling GitLab OAuth callback:", err);
|
||||
navigate({
|
||||
to: "/organization/app-connections",
|
||||
search: { error: "connection_failed" }
|
||||
});
|
||||
}
|
||||
})();
|
||||
}, []);
|
||||
}, [code, state, navigate, createAppConnection, updateAppConnection, currentWorkspace.id]);
|
||||
|
||||
return <div />;
|
||||
return (
|
||||
<div className="flex h-screen items-center justify-center">
|
||||
<div className="text-center">
|
||||
<div className="mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-b-2 border-primary" />
|
||||
<p className="text-gray-600">Connecting to GitLab...</p>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user