import { useEffect } from "react"; import { Helmet } from "react-helmet"; import { Controller, useForm } from "react-hook-form"; import { faArrowUpRightFromSquare, faBookOpen } from "@fortawesome/free-solid-svg-icons"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { zodResolver } from "@hookform/resolvers/zod"; import { useNavigate, useSearch } from "@tanstack/react-router"; import { z } from "zod"; import { createNotification } from "@app/components/notifications"; import { Button, Card, CardTitle, FormControl, FormLabel, Input, Select, SelectItem, Switch } from "@app/components/v2"; import { SecretPathInput } from "@app/components/v2/SecretPathInput"; import { ROUTE_PATHS } from "@app/const/routes"; import { useWorkspace } from "@app/context"; import { useCreateIntegration } from "@app/hooks/api"; import { useGetIntegrationAuthById } from "@app/hooks/api/integrationAuth"; import { IntegrationSyncBehavior } from "@app/hooks/api/integrations/types"; import { useGetWorkspaceById } from "@app/hooks/api/workspace"; import { IntegrationsListPageTabs } from "@app/types/integrations"; const schema = z.object({ baseUrl: z .string() .trim() .min(1, { message: "Azure App Configuration URL is required" }) .url() .refine( (val) => val.endsWith(".azconfig.io"), "URL should have the following format: https://resource-name-here.azconfig.io" ), secretPath: z.string().trim().min(1, { message: "Secret path is required" }), sourceEnvironment: z.string().trim().min(1, { message: "Source environment is required" }), initialSyncBehavior: z.nativeEnum(IntegrationSyncBehavior), secretPrefix: z.string().default(""), useLabels: z.boolean().default(false), azureLabel: z.string().min(1).optional() }); type TFormSchema = z.infer; const initialSyncBehaviors = [ { label: "No Import - Overwrite all values in Azure App Configuration", value: IntegrationSyncBehavior.OVERWRITE_TARGET }, { label: "Import - Prefer values from Azure App Configuration", value: IntegrationSyncBehavior.PREFER_TARGET }, { label: "Import - Prefer values from Infisical", value: IntegrationSyncBehavior.PREFER_SOURCE } ]; export const AzureAppConfigurationConfigurePage = () => { const navigate = useNavigate(); const { control, watch, setValue, handleSubmit, formState: { isSubmitting } } = useForm({ resolver: zodResolver(schema), defaultValues: { secretPath: "/", secretPrefix: "", initialSyncBehavior: IntegrationSyncBehavior.PREFER_SOURCE } }); const selectedEnvironment = watch("sourceEnvironment"); const { mutateAsync } = useCreateIntegration(); const integrationAuthId = useSearch({ from: ROUTE_PATHS.SecretManager.Integratons.AzureAppConfigurationsConfigurePage.id, select: (el) => el.integrationAuthId }); const { currentWorkspace } = useWorkspace(); const { data: workspace } = useGetWorkspaceById(currentWorkspace.id); const { data: integrationAuth } = useGetIntegrationAuthById((integrationAuthId as string) ?? ""); useEffect(() => { if (workspace) { setValue("sourceEnvironment", workspace.environments[0].slug); } }, [workspace]); const shouldUseLabels = watch("useLabels"); const handleIntegrationSubmit = async ({ secretPath, useLabels, sourceEnvironment, baseUrl, initialSyncBehavior, secretPrefix, azureLabel }: TFormSchema) => { try { if (!integrationAuth?.id) return; if (useLabels && !azureLabel) { createNotification({ type: "error", text: "Label must be provided when 'Use Labels' is enabled" }); return; } await mutateAsync({ integrationAuthId: integrationAuth?.id, isActive: true, app: baseUrl, sourceEnvironment, secretPath, metadata: { initialSyncBehavior, secretPrefix, ...(useLabels && { azureLabel }) } }); navigate({ to: "/projects/$projectId/secret-manager/integrations", params: { projectId: currentWorkspace.id }, search: { selectedTab: IntegrationsListPageTabs.NativeIntegrations } }); } catch (err) { console.error(err); } }; return integrationAuth && workspace ? (
Set Up Azure App Configuration Integration
Azure logo
Azure App Configuration
Docs
( )} />
( onChange(isChecked)} isChecked={value} > )} /> {shouldUseLabels && ( ( )} /> )}
( )} /> ( )} /> ( )} /> ( )} />
) : (
); };