This commit is contained in:
carlosmonastyrski
2025-06-25 00:24:24 -03:00
parent 18e733c71f
commit 0366e58a5b
14 changed files with 64 additions and 63 deletions

View File

@@ -20,7 +20,7 @@ import {
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 { GitLabSyncScope } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
import { TSecretSyncForm } from "../schemas";
@@ -71,7 +71,7 @@ export const GitLabSyncFields = () => {
const shouldMaskSecrets = useWatch({ name: "destinationConfig.shouldMaskSecrets", control });
const { data: groups, isLoading: isGroupsLoading } = useGitlabConnectionListGroups(connectionId, {
enabled: Boolean(connectionId) && scope === GitlabSyncScope.Group
enabled: Boolean(connectionId) && scope === GitLabSyncScope.Group
});
const { data: projects, isLoading: isProjectsLoading } = useGitlabConnectionListProjects(
@@ -82,21 +82,21 @@ export const GitLabSyncFields = () => {
);
return (
<div className="h-[calc(100vh-28rem)] overflow-auto">
<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);
setValue("destinationConfig.scope", GitLabSyncScope.Project);
}}
/>
<Controller
name="destinationConfig.scope"
control={control}
defaultValue={GitlabSyncScope.Project}
defaultValue={GitLabSyncScope.Project}
render={({ field: { value, onChange }, fieldState: { error } }) => (
<FormControl errorText={error?.message} isError={Boolean(error?.message)} label="Scope">
<Select
@@ -113,7 +113,7 @@ export const GitLabSyncFields = () => {
placeholder="Select a scope..."
dropdownContainerClassName="max-w-none"
>
{Object.values(GitlabSyncScope).map((projectScope) => (
{Object.values(GitLabSyncScope).map((projectScope) => (
<SelectItem className="capitalize" value={projectScope} key={projectScope}>
{projectScope.replace("-", " ")}
</SelectItem>
@@ -123,7 +123,7 @@ export const GitLabSyncFields = () => {
)}
/>
{scope === GitlabSyncScope.Group && (
{scope === GitLabSyncScope.Group && (
<Controller
name="destinationConfig.groupId"
control={control}
@@ -166,7 +166,7 @@ export const GitLabSyncFields = () => {
/>
)}
{scope === GitlabSyncScope.Project && (
{scope === GitLabSyncScope.Project && (
<Controller
name="destinationConfig.projectId"
control={control}

View File

@@ -3,6 +3,7 @@ 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 }>();
@@ -17,10 +18,10 @@ export const GitLabSyncReviewFields = () => {
return (
<>
<GenericFieldLabel label="Scope">{scope}</GenericFieldLabel>
{scope === GitlabSyncScope.Project && (
{scope === GitLabSyncScope.Project && (
<GenericFieldLabel label="Project Name">{projectName}</GenericFieldLabel>
)}
{scope === GitlabSyncScope.Group && (
{scope === GitLabSyncScope.Group && (
<GenericFieldLabel label="Group Name">{groupName}</GenericFieldLabel>
)}
{targetEnvironment && (

View File

@@ -2,14 +2,14 @@ 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";
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),
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(),
@@ -18,7 +18,7 @@ export const GitlabSyncDestinationSchema = BaseSecretSyncSchema().merge(
shouldHideSecrets: z.boolean().optional().default(false)
}),
z.object({
scope: z.literal(GitlabSyncScope.Group),
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"),

View File

@@ -24,7 +24,7 @@ import {
GcpConnectionMethod,
GitHubConnectionMethod,
GitHubRadarConnectionMethod,
GitlabConnectionMethod,
GitLabConnectionMethod,
HCVaultConnectionMethod,
HumanitecConnectionMethod,
LdapConnectionMethod,
@@ -102,7 +102,7 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])
case AzureDevOpsConnectionMethod.OAuth:
case GitHubConnectionMethod.OAuth:
case HerokuConnectionMethod.OAuth:
case GitlabConnectionMethod.OAuth:
case GitLabConnectionMethod.OAuth:
return { name: "OAuth", icon: faPassport };
case AwsConnectionMethod.AccessKey:
case OCIConnectionMethod.AccessKey:

View File

@@ -3,14 +3,14 @@ import { TRootAppConnection } from "@app/hooks/api/appConnections/types/root-con
import { GitLabAccessTokenType } from "../gitlab";
export enum GitlabConnectionMethod {
export enum GitLabConnectionMethod {
AccessToken = "access-token",
OAuth = "oauth"
}
export type TGitlabConnection = TRootAppConnection & { app: AppConnection.Gitlab } & (
export type TGitLabConnection = TRootAppConnection & { app: AppConnection.Gitlab } & (
| {
method: GitlabConnectionMethod.AccessToken;
method: GitLabConnectionMethod.AccessToken;
credentials: {
instanceUrl?: string;
accessToken: string;
@@ -18,7 +18,7 @@ export type TGitlabConnection = TRootAppConnection & { app: AppConnection.Gitlab
};
}
| {
method: GitlabConnectionMethod.OAuth;
method: GitLabConnectionMethod.OAuth;
credentials: {
code: string;
instanceUrl?: string;

View File

@@ -14,7 +14,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 { TGitLabConnection } from "./gitlab-connection";
import { THCVaultConnection } from "./hc-vault-connection";
import { THerokuConnection } from "./heroku-connection";
import { THumanitecConnection } from "./humanitec-connection";
@@ -88,7 +88,7 @@ export type TAppConnection =
| THerokuConnection
| TRenderConnection
| TFlyioConnection
| TGitlabConnection
| TGitLabConnection
| TCloudflareConnection;
export type TAvailableAppConnection = Pick<TAppConnection, "name" | "id">;
@@ -144,6 +144,6 @@ export type TAppConnectionMap = {
[AppConnection.Heroku]: THerokuConnection;
[AppConnection.Render]: TRenderConnection;
[AppConnection.Flyio]: TFlyioConnection;
[AppConnection.Gitlab]: TGitlabConnection;
[AppConnection.Gitlab]: TGitLabConnection;
[AppConnection.Cloudflare]: TCloudflareConnection;
};

View File

@@ -2,16 +2,16 @@ 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 {
export enum GitLabSyncScope {
Project = "project",
Group = "group"
}
export type TGitlabSync = TRootSecretSync & {
export type TGitLabSync = TRootSecretSync & {
destination: SecretSync.GitLab;
destinationConfig:
| {
scope: GitlabSyncScope.Project;
scope: GitLabSyncScope.Project;
projectId: string;
projectName: string;
targetEnvironment?: string;
@@ -20,7 +20,7 @@ export type TGitlabSync = TRootSecretSync & {
shouldHideSecrets?: boolean;
}
| {
scope: GitlabSyncScope.Group;
scope: GitLabSyncScope.Group;
groupId: string;
groupName: string;
targetEnvironment?: string;

View File

@@ -14,7 +14,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 { TGitLabSync } from "./gitlab-sync";
import { THCVaultSync } from "./hc-vault-sync";
import { THerokuSync } from "./heroku-sync";
import { THumanitecSync } from "./humanitec-sync";
@@ -52,7 +52,7 @@ export type TSecretSync =
| THerokuSync
| TRenderSync
| TFlyioSync
| TGitlabSync
| TGitLabSync
| TCloudflarePagesSync;
export type TListSecretSyncs = { secretSyncs: TSecretSync[] };

View File

@@ -22,8 +22,8 @@ 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
GitLabConnectionMethod,
TGitLabConnection
} from "@app/hooks/api/appConnections/types/gitlab-connection";
import {
@@ -32,14 +32,14 @@ import {
} from "./GenericAppConnectionFields";
type Props = {
appConnection?: TGitlabConnection;
appConnection?: TGitLabConnection;
onSubmit: (formData: FormData) => Promise<void>;
};
const formSchema = z.discriminatedUnion("method", [
genericAppConnectionFieldsSchema.extend({
app: z.literal(AppConnection.Gitlab),
method: z.literal(GitlabConnectionMethod.AccessToken),
method: z.literal(GitLabConnectionMethod.AccessToken),
credentials: z.object({
accessToken: z.string().min(1, "Access token is required"),
accessTokenType: z.nativeEnum(GitLabAccessTokenType),
@@ -55,7 +55,7 @@ const formSchema = z.discriminatedUnion("method", [
}),
genericAppConnectionFieldsSchema.extend({
app: z.literal(AppConnection.Gitlab),
method: z.literal(GitlabConnectionMethod.OAuth),
method: z.literal(GitLabConnectionMethod.OAuth),
credentials: z.object({
code: z.string().min(1, "Code is required"),
instanceUrl: z
@@ -84,12 +84,12 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
const form = useForm<FormData>({
resolver: zodResolver(formSchema),
defaultValues:
appConnection?.method === GitlabConnectionMethod.OAuth
appConnection?.method === GitLabConnectionMethod.OAuth
? { ...appConnection, credentials: { code: "custom" } }
: (appConnection ??
({
app: AppConnection.Gitlab,
method: GitlabConnectionMethod.AccessToken,
method: GitLabConnectionMethod.AccessToken,
credentials: {
accessToken: "",
accessTokenType: GitLabAccessTokenType.Personal,
@@ -112,11 +112,11 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
const onSubmit = async (formData: FormData) => {
try {
switch (formData.method) {
case GitlabConnectionMethod.AccessToken:
case GitLabConnectionMethod.AccessToken:
await formSubmit(formData);
break;
case GitlabConnectionMethod.OAuth:
case GitLabConnectionMethod.OAuth:
if (!oauthClientId) {
return;
}
@@ -165,10 +165,10 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
let isMissingConfig: boolean;
switch (selectedMethod) {
case GitlabConnectionMethod.OAuth:
case GitLabConnectionMethod.OAuth:
isMissingConfig = !oauthClientId;
break;
case GitlabConnectionMethod.AccessToken:
case GitLabConnectionMethod.AccessToken:
isMissingConfig = false;
break;
default:
@@ -210,7 +210,7 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
APP_CONNECTION_MAP[AppConnection.Gitlab].name
}. This field cannot be changed after creation.`}
errorText={
!isLoading && isMissingConfig && selectedMethod === GitlabConnectionMethod.OAuth
!isLoading && isMissingConfig && selectedMethod === GitLabConnectionMethod.OAuth
? `Environment variables have not been configured. ${
isInfisicalCloud()
? "Please contact Infisical."
@@ -226,7 +226,7 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
value={value}
onValueChange={(val) => {
onChange(val);
if (val === GitlabConnectionMethod.OAuth) {
if (val === GitLabConnectionMethod.OAuth) {
setValue("credentials.code", "custom");
}
}}
@@ -234,11 +234,11 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
position="popper"
dropdownContainerClassName="max-w-none"
>
{Object.values(GitlabConnectionMethod).map((method) => {
{Object.values(GitLabConnectionMethod).map((method) => {
return (
<SelectItem value={method} key={method}>
{getAppConnectionMethodDetails(method).name}{" "}
{method === GitlabConnectionMethod.AccessToken ? " (Recommended)" : ""}
{method === GitLabConnectionMethod.AccessToken ? " (Recommended)" : ""}
</SelectItem>
);
})}
@@ -247,7 +247,7 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
)}
/>
{selectedMethod === GitlabConnectionMethod.AccessToken && (
{selectedMethod === GitLabConnectionMethod.AccessToken && (
<>
<Controller
name="credentials.accessTokenType"
@@ -263,7 +263,7 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
value={value}
onValueChange={(val) => {
onChange(val);
if (val === GitlabConnectionMethod.OAuth) {
if (val === GitLabConnectionMethod.OAuth) {
setValue("credentials.code", "custom");
}
}}
@@ -313,11 +313,11 @@ export const GitLabConnectionForm = ({ appConnection, onSubmit: formSubmit }: Pr
isDisabled={
isSubmitting ||
(!isUpdate && !isDirty) ||
(isMissingConfig && selectedMethod === GitlabConnectionMethod.OAuth) ||
(isMissingConfig && selectedMethod === GitLabConnectionMethod.OAuth) ||
isRedirecting
}
>
{isRedirecting && selectedMethod === GitlabConnectionMethod.OAuth
{isRedirecting && selectedMethod === GitLabConnectionMethod.OAuth
? "Redirecting to GitLab..."
: isUpdate
? "Reconnect to GitLab"

View File

@@ -11,14 +11,14 @@ import {
AzureDevOpsConnectionMethod,
AzureKeyVaultConnectionMethod,
GitHubConnectionMethod,
GitlabConnectionMethod,
GitLabConnectionMethod,
TAzureAppConfigurationConnection,
TAzureClientSecretsConnection,
TAzureDevOpsConnection,
TAzureKeyVaultConnection,
TGitHubConnection,
TGitHubRadarConnection,
TGitlabConnection,
TGitLabConnection,
useCreateAppConnection,
useUpdateAppConnection
} from "@app/hooks/api/appConnections";
@@ -35,7 +35,7 @@ type GithubFormData = BaseFormData & Pick<TGitHubConnection, "name" | "method" |
type GithubRadarFormData = BaseFormData &
Pick<TGitHubRadarConnection, "name" | "method" | "description">;
type GitlabFormData = BaseFormData & Pick<TGitlabConnection, "name" | "method" | "description">;
type GitLabFormData = BaseFormData & Pick<TGitLabConnection, "name" | "method" | "description">;
type AzureKeyVaultFormData = BaseFormData &
Pick<TAzureKeyVaultConnection, "name" | "method" | "description"> &
@@ -65,7 +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.Gitlab]: GitLabFormData & { app: AppConnection.Gitlab };
[AppConnection.AzureKeyVault]: AzureKeyVaultFormData & { app: AppConnection.AzureKeyVault };
[AppConnection.AzureAppConfiguration]: AzureAppConfigurationFormData & {
app: AppConnection.AzureAppConfiguration;
@@ -162,7 +162,7 @@ export const OAuthCallbackPage = () => {
app: AppConnection.Gitlab,
name,
description,
method: GitlabConnectionMethod.OAuth,
method: GitLabConnectionMethod.OAuth,
credentials: {
code: code as string
}

View File

@@ -1,10 +1,10 @@
import { TGitlabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
import { TGitLabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
import { getSecretSyncDestinationColValues } from "../helpers";
import { SecretSyncTableCell } from "../SecretSyncTableCell";
type Props = {
secretSync: TGitlabSync;
secretSync: TGitLabSync;
};
export const GitLabSyncDestinationCol = ({ secretSync }: Props) => {

View File

@@ -5,7 +5,7 @@ import {
GitHubSyncScope,
GitHubSyncVisibility
} from "@app/hooks/api/secretSyncs/types/github-sync";
import { GitlabSyncScope } from "@app/hooks/api/secretSyncs/types/gitlab-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
@@ -130,10 +130,10 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
secondaryText = "App ID";
break;
case SecretSync.GitLab:
if (destinationConfig.scope === GitlabSyncScope.Project) {
if (destinationConfig.scope === GitLabSyncScope.Project) {
primaryText = destinationConfig.projectName;
secondaryText = destinationConfig.projectId;
} else if (destinationConfig.scope === GitlabSyncScope.Group) {
} else if (destinationConfig.scope === GitLabSyncScope.Group) {
primaryText = destinationConfig.groupName;
secondaryText = destinationConfig.groupId;
} else {

View File

@@ -1,8 +1,8 @@
import { GenericFieldLabel } from "@app/components/secret-syncs";
import { GitlabSyncScope, TGitlabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
import { GitLabSyncScope, TGitLabSync } from "@app/hooks/api/secretSyncs/types/gitlab-sync";
type Props = {
secretSync: TGitlabSync;
secretSync: TGitLabSync;
};
export const GitLabSyncDestinationSection = ({ secretSync }: Props) => {
@@ -17,7 +17,7 @@ export const GitLabSyncDestinationSection = ({ secretSync }: Props) => {
return (
<>
{secretSync.destinationConfig.scope === GitlabSyncScope.Project && (
{secretSync.destinationConfig.scope === GitLabSyncScope.Project && (
<>
<GenericFieldLabel label="Project Name">
{secretSync.destinationConfig.projectName}
@@ -27,7 +27,7 @@ export const GitLabSyncDestinationSection = ({ secretSync }: Props) => {
</GenericFieldLabel>
</>
)}
{secretSync.destinationConfig.scope === GitlabSyncScope.Group && (
{secretSync.destinationConfig.scope === GitLabSyncScope.Group && (
<>
<GenericFieldLabel label="Group Name">
{secretSync.destinationConfig.groupName}

View File

@@ -4,7 +4,7 @@ import { useNavigate, useSearch } from "@tanstack/react-router";
import { ROUTE_PATHS } from "@app/const/routes";
import { useWorkspace } from "@app/context";
import { useCreateAppConnection, useUpdateAppConnection } from "@app/hooks/api/appConnections";
import { GitlabConnectionMethod } from "@app/hooks/api/appConnections/types/gitlab-connection";
import { GitLabConnectionMethod } from "@app/hooks/api/appConnections/types/gitlab-connection";
export const GitLabOAuthCallbackPage = () => {
const navigate = useNavigate();
@@ -49,7 +49,7 @@ export const GitLabOAuthCallbackPage = () => {
// Prepare app connection data with OAuth credentials
const connectionData = {
...formData,
method: GitlabConnectionMethod.OAuth,
method: GitLabConnectionMethod.OAuth,
credentials: {
code: code as string
}