mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 15:40:47 +00:00
Merge pull request #3835 from Infisical/feat/gitlabSecretSync
feat(secret-sync): Add gitlab secret sync
This commit is contained in:
+5
@@ -23,6 +23,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";
|
||||
@@ -129,6 +130,8 @@ const CreateForm = ({ app, onComplete }: CreateFormProps) => {
|
||||
return <RenderConnectionForm onSubmit={onSubmit} />;
|
||||
case AppConnection.Flyio:
|
||||
return <FlyioConnectionForm onSubmit={onSubmit} />;
|
||||
case AppConnection.Gitlab:
|
||||
return <GitLabConnectionForm onSubmit={onSubmit} />;
|
||||
case AppConnection.Cloudflare:
|
||||
return <CloudflareConnectionForm onSubmit={onSubmit} />;
|
||||
default:
|
||||
@@ -221,6 +224,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} />;
|
||||
case AppConnection.Cloudflare:
|
||||
return <CloudflareConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||
default:
|
||||
|
||||
+335
@@ -0,0 +1,335 @@
|
||||
/* 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 { GitLabAccessTokenType } from "@app/hooks/api/appConnections/gitlab";
|
||||
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"),
|
||||
accessTokenType: z.nativeEnum(GitLabAccessTokenType),
|
||||
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: "",
|
||||
accessTokenType: GitLabAccessTokenType.Personal,
|
||||
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}/organization/app-connections/gitlab/oauth/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.accessTokenType"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
label="Access Token Type"
|
||||
>
|
||||
<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(GitLabAccessTokenType).map((method) => {
|
||||
return (
|
||||
<SelectItem value={method} key={method}>
|
||||
{method.charAt(0).toUpperCase() + method.slice(1)} Access Token
|
||||
</SelectItem>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<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>
|
||||
);
|
||||
};
|
||||
+60
@@ -11,12 +11,14 @@ import {
|
||||
AzureDevOpsConnectionMethod,
|
||||
AzureKeyVaultConnectionMethod,
|
||||
GitHubConnectionMethod,
|
||||
GitLabConnectionMethod,
|
||||
TAzureAppConfigurationConnection,
|
||||
TAzureClientSecretsConnection,
|
||||
TAzureDevOpsConnection,
|
||||
TAzureKeyVaultConnection,
|
||||
TGitHubConnection,
|
||||
TGitHubRadarConnection,
|
||||
TGitLabConnection,
|
||||
useCreateAppConnection,
|
||||
useUpdateAppConnection
|
||||
} from "@app/hooks/api/appConnections";
|
||||
@@ -25,6 +27,7 @@ import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||
type BaseFormData = {
|
||||
returnUrl?: string;
|
||||
connectionId?: string;
|
||||
isUpdate?: boolean;
|
||||
};
|
||||
|
||||
type GithubFormData = BaseFormData & Pick<TGitHubConnection, "name" | "method" | "description">;
|
||||
@@ -32,6 +35,8 @@ type GithubFormData = BaseFormData & Pick<TGitHubConnection, "name" | "method" |
|
||||
type GithubRadarFormData = BaseFormData &
|
||||
Pick<TGitHubRadarConnection, "name" | "method" | "description">;
|
||||
|
||||
type GitLabFormData = BaseFormData & Pick<TGitLabConnection, "name" | "method" | "description">;
|
||||
|
||||
type AzureKeyVaultFormData = BaseFormData &
|
||||
Pick<TAzureKeyVaultConnection, "name" | "method" | "description"> &
|
||||
Pick<TAzureKeyVaultConnection["credentials"], "tenantId">;
|
||||
@@ -60,6 +65,7 @@ type AzureDevOpsFormData = BaseFormData &
|
||||
type FormDataMap = {
|
||||
[AppConnection.GitHub]: GithubFormData & { app: AppConnection.GitHub };
|
||||
[AppConnection.GitHubRadar]: GithubRadarFormData & { app: AppConnection.GitHubRadar };
|
||||
[AppConnection.Gitlab]: GitLabFormData & { app: AppConnection.Gitlab };
|
||||
[AppConnection.AzureKeyVault]: AzureKeyVaultFormData & { app: AppConnection.AzureKeyVault };
|
||||
[AppConnection.AzureAppConfiguration]: AzureAppConfigurationFormData & {
|
||||
app: AppConnection.AzureAppConfiguration;
|
||||
@@ -75,6 +81,7 @@ type FormDataMap = {
|
||||
const formDataStorageFieldMap: Partial<Record<AppConnection, string>> = {
|
||||
[AppConnection.GitHub]: "githubConnectionFormData",
|
||||
[AppConnection.GitHubRadar]: "githubRadarConnectionFormData",
|
||||
[AppConnection.Gitlab]: "gitlabConnectionFormData",
|
||||
[AppConnection.AzureKeyVault]: "azureKeyVaultConnectionFormData",
|
||||
[AppConnection.AzureAppConfiguration]: "azureAppConfigurationConnectionFormData",
|
||||
[AppConnection.AzureClientSecrets]: "azureClientSecretsConnectionFormData",
|
||||
@@ -133,6 +140,57 @@ export const OAuthCallbackPage = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleGitlab = useCallback(async () => {
|
||||
const formData = getFormData(AppConnection.Gitlab);
|
||||
if (formData === null) return null;
|
||||
|
||||
clearState(AppConnection.Gitlab);
|
||||
|
||||
const { connectionId, name, description, returnUrl, isUpdate } = formData;
|
||||
|
||||
try {
|
||||
if (isUpdate && connectionId) {
|
||||
await updateAppConnection.mutateAsync({
|
||||
app: AppConnection.Gitlab,
|
||||
connectionId,
|
||||
credentials: {
|
||||
code: code as string
|
||||
}
|
||||
});
|
||||
} else {
|
||||
await createAppConnection.mutateAsync({
|
||||
app: AppConnection.Gitlab,
|
||||
name,
|
||||
description,
|
||||
method: GitLabConnectionMethod.OAuth,
|
||||
credentials: {
|
||||
code: code as string
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
navigate({
|
||||
to: returnUrl ?? "/organization/app-connections"
|
||||
});
|
||||
|
||||
return {
|
||||
connectionId,
|
||||
returnUrl,
|
||||
appConnectionName: formData.app
|
||||
};
|
||||
} catch (err: any) {
|
||||
createNotification({
|
||||
title: `Failed to ${connectionId ? "update" : "add"} GitLab Connection`,
|
||||
text: err?.message,
|
||||
type: "error"
|
||||
});
|
||||
navigate({
|
||||
to: returnUrl ?? "/organization/app-connections"
|
||||
});
|
||||
return null;
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleAzureKeyVault = useCallback(async () => {
|
||||
const formData = getFormData(AppConnection.AzureKeyVault);
|
||||
if (formData === null) return null;
|
||||
@@ -463,6 +521,8 @@ export const OAuthCallbackPage = () => {
|
||||
data = await handleGithub();
|
||||
} else if (appConnection === AppConnection.GitHubRadar) {
|
||||
data = await handleGithubRadar();
|
||||
} else if (appConnection === AppConnection.Gitlab) {
|
||||
data = await handleGitlab();
|
||||
} else if (appConnection === AppConnection.AzureKeyVault) {
|
||||
data = await handleAzureKeyVault();
|
||||
} else if (appConnection === AppConnection.AzureAppConfiguration) {
|
||||
|
||||
+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
@@ -12,6 +12,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";
|
||||
@@ -68,6 +69,8 @@ export const SecretSyncDestinationCol = ({ secretSync }: Props) => {
|
||||
return <RenderSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.Flyio:
|
||||
return <FlyioSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.GitLab:
|
||||
return <GitLabSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.CloudflarePages:
|
||||
return <CloudflarePagesSyncDestinationCol secretSync={secretSync} />;
|
||||
default:
|
||||
|
||||
+12
@@ -5,6 +5,7 @@ import {
|
||||
GitHubSyncScope,
|
||||
GitHubSyncVisibility
|
||||
} from "@app/hooks/api/secretSyncs/types/github-sync";
|
||||
import { GitLabSyncScope } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
|
||||
import { HumanitecSyncScope } from "@app/hooks/api/secretSyncs/types/humanitec-sync";
|
||||
|
||||
// This functional ensures parity across what is displayed in the destination column
|
||||
@@ -128,6 +129,17 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
|
||||
primaryText = destinationConfig.appId;
|
||||
secondaryText = "App ID";
|
||||
break;
|
||||
case SecretSync.GitLab:
|
||||
if (destinationConfig.scope === GitLabSyncScope.Project) {
|
||||
primaryText = destinationConfig.projectName;
|
||||
secondaryText = destinationConfig.projectId;
|
||||
} else if (destinationConfig.scope === GitLabSyncScope.Group) {
|
||||
primaryText = destinationConfig.groupName;
|
||||
secondaryText = destinationConfig.groupId;
|
||||
} else {
|
||||
throw new Error(`Unhandled GitLab Scope Destination Col Values ${destination}`);
|
||||
}
|
||||
break;
|
||||
case SecretSync.CloudflarePages:
|
||||
primaryText = destinationConfig.projectName;
|
||||
secondaryText = destinationConfig.environment;
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
import { GenericFieldLabel } from "@app/components/secret-syncs";
|
||||
import { GitLabSyncScope, TGitLabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
|
||||
|
||||
type Props = {
|
||||
secretSync: TGitLabSync;
|
||||
};
|
||||
|
||||
export const GitLabSyncDestinationSection = ({ secretSync }: Props) => {
|
||||
const {
|
||||
destinationConfig: {
|
||||
targetEnvironment,
|
||||
shouldProtectSecrets,
|
||||
shouldMaskSecrets,
|
||||
shouldHideSecrets
|
||||
}
|
||||
} = secretSync;
|
||||
|
||||
return (
|
||||
<>
|
||||
{secretSync.destinationConfig.scope === GitLabSyncScope.Project && (
|
||||
<>
|
||||
<GenericFieldLabel label="Project Name">
|
||||
{secretSync.destinationConfig.projectName}
|
||||
</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Project ID">
|
||||
{secretSync.destinationConfig.projectId}
|
||||
</GenericFieldLabel>
|
||||
</>
|
||||
)}
|
||||
{secretSync.destinationConfig.scope === GitLabSyncScope.Group && (
|
||||
<>
|
||||
<GenericFieldLabel label="Group Name">
|
||||
{secretSync.destinationConfig.groupName}
|
||||
</GenericFieldLabel>
|
||||
<GenericFieldLabel label="Group ID">
|
||||
{secretSync.destinationConfig.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 { 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";
|
||||
@@ -107,6 +108,9 @@ export const SecretSyncDestinationSection = ({ secretSync, onEditDestination }:
|
||||
case SecretSync.Flyio:
|
||||
DestinationComponents = <FlyioSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
case SecretSync.GitLab:
|
||||
DestinationComponents = <GitLabSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
case SecretSync.CloudflarePages:
|
||||
DestinationComponents = <CloudflarePagesSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
|
||||
+1
@@ -58,6 +58,7 @@ export const SecretSyncOptionsSection = ({ secretSync, onEditOptions }: Props) =
|
||||
case SecretSync.Heroku:
|
||||
case SecretSync.Render:
|
||||
case SecretSync.Flyio:
|
||||
case SecretSync.GitLab:
|
||||
case SecretSync.CloudflarePages:
|
||||
AdditionalSyncOptionsComponent = null;
|
||||
break;
|
||||
|
||||
+70
-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,82 @@ 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
|
||||
})
|
||||
});
|
||||
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