mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Add Humanitec secret sync integration
This commit is contained in:
BIN
frontend/public/images/integrations/Humanitec.png
Normal file
BIN
frontend/public/images/integrations/Humanitec.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -0,0 +1,125 @@
|
||||
import { Controller, useFormContext, useWatch } from "react-hook-form";
|
||||
import { SingleValue } from "react-select";
|
||||
|
||||
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
|
||||
import { FilterableSelect, FormControl } from "@app/components/v2";
|
||||
import {
|
||||
THumanitecConnectionApp,
|
||||
useHumanitecConnectionListOrganizations
|
||||
} from "@app/hooks/api/appConnections/humanitec";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
import { TSecretSyncForm } from "../schemas";
|
||||
|
||||
export const HumanitecSyncFields = () => {
|
||||
const { control, watch, setValue } = useFormContext<
|
||||
TSecretSyncForm & { destination: SecretSync.Humanitec }
|
||||
>();
|
||||
|
||||
const connectionId = useWatch({ name: "connection.id", control });
|
||||
const currentOrg = watch("destinationConfig.org");
|
||||
const currentApp = watch("destinationConfig.app");
|
||||
|
||||
const { data: organizations = [], isPending: isOrganizationsPending } =
|
||||
useHumanitecConnectionListOrganizations(connectionId, {
|
||||
enabled: Boolean(connectionId)
|
||||
});
|
||||
return (
|
||||
<>
|
||||
<SecretSyncConnectionField
|
||||
onChange={() => {
|
||||
setValue("destinationConfig.org", "");
|
||||
setValue("destinationConfig.app", "");
|
||||
}}
|
||||
/>
|
||||
<Controller
|
||||
name="destinationConfig.org"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
label="Organization"
|
||||
>
|
||||
<FilterableSelect
|
||||
isLoading={isOrganizationsPending && Boolean(connectionId)}
|
||||
isDisabled={!connectionId}
|
||||
value={organizations ? (organizations.find((org) => org.id === value) ?? []) : []}
|
||||
onChange={(option) =>
|
||||
onChange((option as SingleValue<THumanitecConnectionApp>)?.id ?? null)
|
||||
}
|
||||
options={organizations}
|
||||
placeholder="Select an organization..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id.toString()}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="destinationConfig.app"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="App">
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isOrganizationsPending && Boolean(connectionId) && Boolean(currentOrg)}
|
||||
isDisabled={!connectionId || !currentOrg}
|
||||
value={
|
||||
organizations
|
||||
.find((org) => org.id === currentOrg)
|
||||
?.apps?.find((app) => app.id === value) ?? null
|
||||
}
|
||||
onChange={(option) =>
|
||||
onChange((option as SingleValue<THumanitecConnectionApp>)?.id ?? null)
|
||||
}
|
||||
options={
|
||||
currentOrg ? (organizations.find((org) => org.id === currentOrg)?.apps ?? []) : []
|
||||
}
|
||||
placeholder="Select an app..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id.toString()}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="destinationConfig.env"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="Environment">
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={
|
||||
isOrganizationsPending &&
|
||||
Boolean(connectionId) &&
|
||||
Boolean(currentOrg) &&
|
||||
Boolean(currentApp)
|
||||
}
|
||||
isDisabled={!connectionId || !currentApp}
|
||||
value={
|
||||
organizations
|
||||
.find((org) => org.id === currentOrg)
|
||||
?.apps?.find((app) => app.id === currentApp)
|
||||
?.envs?.find((env) => env.id === value) ?? null
|
||||
}
|
||||
onChange={(option) =>
|
||||
onChange((option as SingleValue<THumanitecConnectionApp>)?.id ?? null)
|
||||
}
|
||||
options={
|
||||
currentApp
|
||||
? ((organizations.find((org) => org.id === currentOrg)?.apps ?? [])?.find(
|
||||
(app) => app.id === currentApp
|
||||
)?.envs ?? [])
|
||||
: []
|
||||
}
|
||||
placeholder="Select an env..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id.toString()}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -10,6 +10,7 @@ import { AzureKeyVaultSyncFields } from "./AzureKeyVaultSyncFields";
|
||||
import { DatabricksSyncFields } from "./DatabricksSyncFields";
|
||||
import { GcpSyncFields } from "./GcpSyncFields";
|
||||
import { GitHubSyncFields } from "./GitHubSyncFields";
|
||||
import { HumanitecSyncFields } from "./HumanitecSyncFields";
|
||||
|
||||
export const SecretSyncDestinationFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm>();
|
||||
@@ -31,6 +32,8 @@ export const SecretSyncDestinationFields = () => {
|
||||
return <AzureAppConfigurationSyncFields />;
|
||||
case SecretSync.Databricks:
|
||||
return <DatabricksSyncFields />;
|
||||
case SecretSync.Humanitec:
|
||||
return <HumanitecSyncFields />;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Config Field: ${destination}`);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
|
||||
case SecretSync.AzureKeyVault:
|
||||
case SecretSync.AzureAppConfiguration:
|
||||
case SecretSync.Databricks:
|
||||
case SecretSync.Humanitec:
|
||||
AdditionalSyncOptionsFieldsComponent = null;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import { useFormContext } from "react-hook-form";
|
||||
|
||||
import { SecretSyncLabel } from "@app/components/secret-syncs";
|
||||
import { TSecretSyncForm } from "@app/components/secret-syncs/forms/schemas";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
export const HumanitecSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.Humanitec }>();
|
||||
const orgId = watch("destinationConfig.org");
|
||||
const appId = watch("destinationConfig.app");
|
||||
const envId = watch("destinationConfig.env");
|
||||
|
||||
return (
|
||||
<>
|
||||
<SecretSyncLabel label="Organization">{orgId}</SecretSyncLabel>
|
||||
<SecretSyncLabel label="App">{appId}</SecretSyncLabel>
|
||||
<SecretSyncLabel label="Environment">{envId}</SecretSyncLabel>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -20,6 +20,7 @@ import { AzureKeyVaultSyncReviewFields } from "./AzureKeyVaultSyncReviewFields";
|
||||
import { DatabricksSyncReviewFields } from "./DatabricksSyncReviewFields";
|
||||
import { GcpSyncReviewFields } from "./GcpSyncReviewFields";
|
||||
import { GitHubSyncReviewFields } from "./GitHubSyncReviewFields";
|
||||
import { HumanitecSyncReviewFields } from "./HumanitecSyncReviewFields";
|
||||
|
||||
export const SecretSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm>();
|
||||
@@ -67,6 +68,9 @@ export const SecretSyncReviewFields = () => {
|
||||
case SecretSync.Databricks:
|
||||
DestinationFieldsComponent = <DatabricksSyncReviewFields />;
|
||||
break;
|
||||
case SecretSync.Humanitec:
|
||||
DestinationFieldsComponent = <HumanitecSyncReviewFields />;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Review Fields: ${destination}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { BaseSecretSyncSchema } from "@app/components/secret-syncs/forms/schemas/base-secret-sync-schema";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
export const HumanitecSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||
z.object({
|
||||
destination: z.literal(SecretSync.Humanitec),
|
||||
destinationConfig: z.object({
|
||||
org: z.string().trim().min(1, "Organization required"),
|
||||
app: z.string().trim().min(1, "App required"),
|
||||
env: z.string().trim().min(1, "Environment required")
|
||||
})
|
||||
})
|
||||
);
|
||||
@@ -8,6 +8,7 @@ import { AwsParameterStoreSyncDestinationSchema } from "./aws-parameter-store-sy
|
||||
import { AzureAppConfigurationSyncDestinationSchema } from "./azure-app-configuration-sync-destination-schema";
|
||||
import { AzureKeyVaultSyncDestinationSchema } from "./azure-key-vault-sync-destination-schema";
|
||||
import { GcpSyncDestinationSchema } from "./gcp-sync-destination-schema";
|
||||
import { HumanitecSyncDestinationSchema } from "./humanitec-sync-destination-schema";
|
||||
|
||||
const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
AwsParameterStoreSyncDestinationSchema,
|
||||
@@ -16,7 +17,8 @@ const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
GcpSyncDestinationSchema,
|
||||
AzureKeyVaultSyncDestinationSchema,
|
||||
AzureAppConfigurationSyncDestinationSchema,
|
||||
DatabricksSyncDestinationSchema
|
||||
DatabricksSyncDestinationSchema,
|
||||
HumanitecSyncDestinationSchema
|
||||
]);
|
||||
|
||||
export const SecretSyncFormSchema = SecretSyncUnionSchema;
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
TAppConnection
|
||||
} from "@app/hooks/api/appConnections/types";
|
||||
import { DatabricksConnectionMethod } from "@app/hooks/api/appConnections/types/databricks-connection";
|
||||
import { HumanitecConnectionMethod } from "@app/hooks/api/appConnections/types/humanitec-connection";
|
||||
|
||||
export const APP_CONNECTION_MAP: Record<AppConnection, { name: string; image: string }> = {
|
||||
[AppConnection.AWS]: { name: "AWS", image: "Amazon Web Services.png" },
|
||||
@@ -24,7 +25,8 @@ export const APP_CONNECTION_MAP: Record<AppConnection, { name: string; image: st
|
||||
name: "Azure App Configuration",
|
||||
image: "Microsoft Azure.png"
|
||||
},
|
||||
[AppConnection.Databricks]: { name: "Databricks", image: "Databricks.png" }
|
||||
[AppConnection.Databricks]: { name: "Databricks", image: "Databricks.png" },
|
||||
[AppConnection.Humanitec]: { name: "Humanitec", image: "Humanitec.png" }
|
||||
};
|
||||
|
||||
export const getAppConnectionMethodDetails = (method: TAppConnection["method"]) => {
|
||||
@@ -43,6 +45,8 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])
|
||||
return { name: "Service Account Impersonation", icon: faUser };
|
||||
case DatabricksConnectionMethod.ServicePrincipal:
|
||||
return { name: "Service Principal", icon: faUser };
|
||||
case HumanitecConnectionMethod.AccessKey:
|
||||
return { name: "Access Key", icon: faKey };
|
||||
default:
|
||||
throw new Error(`Unhandled App Connection Method: ${method}`);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ export const SECRET_SYNC_MAP: Record<SecretSync, { name: string; image: string }
|
||||
[SecretSync.Databricks]: {
|
||||
name: "Databricks",
|
||||
image: "Databricks.png"
|
||||
},
|
||||
[SecretSync.Humanitec]: {
|
||||
name: "Humanitec",
|
||||
image: "Humanitec.png"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -28,7 +32,8 @@ export const SECRET_SYNC_CONNECTION_MAP: Record<SecretSync, AppConnection> = {
|
||||
[SecretSync.GCPSecretManager]: AppConnection.GCP,
|
||||
[SecretSync.AzureKeyVault]: AppConnection.AzureKeyVault,
|
||||
[SecretSync.AzureAppConfiguration]: AppConnection.AzureAppConfiguration,
|
||||
[SecretSync.Databricks]: AppConnection.Databricks
|
||||
[SecretSync.Databricks]: AppConnection.Databricks,
|
||||
[SecretSync.Humanitec]: AppConnection.Humanitec
|
||||
};
|
||||
|
||||
export const SECRET_SYNC_INITIAL_SYNC_BEHAVIOR_MAP: Record<
|
||||
|
||||
@@ -4,5 +4,6 @@ export enum AppConnection {
|
||||
GCP = "gcp",
|
||||
AzureKeyVault = "azure-key-vault",
|
||||
AzureAppConfiguration = "azure-app-configuration",
|
||||
Databricks = "databricks"
|
||||
Databricks = "databricks",
|
||||
Humanitec = "humanitec"
|
||||
}
|
||||
|
||||
2
frontend/src/hooks/api/appConnections/humanitec/index.ts
Normal file
2
frontend/src/hooks/api/appConnections/humanitec/index.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from "./queries";
|
||||
export * from "./types";
|
||||
37
frontend/src/hooks/api/appConnections/humanitec/queries.tsx
Normal file
37
frontend/src/hooks/api/appConnections/humanitec/queries.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
|
||||
import { appConnectionKeys } from "../queries";
|
||||
import { THumanitecOrganization } from "./types";
|
||||
|
||||
const humanitecConnectionKeys = {
|
||||
all: [...appConnectionKeys.all, "humanitec"] as const,
|
||||
listOrganizations: (connectionId: string) =>
|
||||
[...humanitecConnectionKeys.all, "organizations", connectionId] as const
|
||||
};
|
||||
|
||||
export const useHumanitecConnectionListOrganizations = (
|
||||
connectionId: string,
|
||||
options?: Omit<
|
||||
UseQueryOptions<
|
||||
THumanitecOrganization[],
|
||||
unknown,
|
||||
THumanitecOrganization[],
|
||||
ReturnType<typeof humanitecConnectionKeys.listOrganizations>
|
||||
>,
|
||||
"queryKey" | "queryFn"
|
||||
>
|
||||
) => {
|
||||
return useQuery({
|
||||
queryKey: humanitecConnectionKeys.listOrganizations(connectionId),
|
||||
queryFn: async () => {
|
||||
const { data } = await apiRequest.get<THumanitecOrganization[]>(
|
||||
`/api/v1/app-connections/humanitec/${connectionId}/organizations`
|
||||
);
|
||||
|
||||
return data;
|
||||
},
|
||||
...options
|
||||
});
|
||||
};
|
||||
15
frontend/src/hooks/api/appConnections/humanitec/types.ts
Normal file
15
frontend/src/hooks/api/appConnections/humanitec/types.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
export type THumanitecOrganization = {
|
||||
name: string;
|
||||
id: string;
|
||||
apps: THumanitecApp[];
|
||||
};
|
||||
|
||||
export type THumanitecApp = {
|
||||
id: string;
|
||||
name: string;
|
||||
envs: { id: string; name: string }[];
|
||||
};
|
||||
|
||||
export type THumanitecConnectionApp = {
|
||||
id: string;
|
||||
};
|
||||
@@ -34,6 +34,10 @@ export type TDatabricksConnectionOption = TAppConnectionOptionBase & {
|
||||
app: AppConnection.Databricks;
|
||||
};
|
||||
|
||||
export type THumanitecConnectionOption = TAppConnectionOptionBase & {
|
||||
app: AppConnection.Humanitec;
|
||||
};
|
||||
|
||||
export type TAppConnectionOption =
|
||||
| TAwsConnectionOption
|
||||
| TGitHubConnectionOption
|
||||
@@ -49,4 +53,5 @@ export type TAppConnectionOptionMap = {
|
||||
[AppConnection.AzureKeyVault]: TAzureKeyVaultConnectionOption;
|
||||
[AppConnection.AzureAppConfiguration]: TAzureAppConfigurationConnectionOption;
|
||||
[AppConnection.Databricks]: TDatabricksConnectionOption;
|
||||
[AppConnection.Humanitec]: THumanitecConnectionOption;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||
import { TRootAppConnection } from "@app/hooks/api/appConnections/types/root-connection";
|
||||
|
||||
export enum HumanitecConnectionMethod {
|
||||
AccessKey = "access-key"
|
||||
}
|
||||
|
||||
export type THumanitecConnection = TRootAppConnection & { app: AppConnection.Humanitec } & {
|
||||
method: HumanitecConnectionMethod.AccessKey;
|
||||
credentials: {
|
||||
accessKeyId: string;
|
||||
};
|
||||
};
|
||||
@@ -3,6 +3,7 @@ import { TAppConnectionOption } from "@app/hooks/api/appConnections/types/app-op
|
||||
import { TAwsConnection } from "@app/hooks/api/appConnections/types/aws-connection";
|
||||
import { TDatabricksConnection } from "@app/hooks/api/appConnections/types/databricks-connection";
|
||||
import { TGitHubConnection } from "@app/hooks/api/appConnections/types/github-connection";
|
||||
import { THumanitecConnection } from "@app/hooks/api/appConnections/types/humanitec-connection";
|
||||
|
||||
import { TAzureAppConfigurationConnection } from "./azure-app-configuration-connection";
|
||||
import { TAzureKeyVaultConnection } from "./azure-key-vault-connection";
|
||||
@@ -13,6 +14,7 @@ export * from "./azure-app-configuration-connection";
|
||||
export * from "./azure-key-vault-connection";
|
||||
export * from "./gcp-connection";
|
||||
export * from "./github-connection";
|
||||
export * from "./humanitec-connection";
|
||||
|
||||
export type TAppConnection =
|
||||
| TAwsConnection
|
||||
@@ -20,7 +22,8 @@ export type TAppConnection =
|
||||
| TGcpConnection
|
||||
| TAzureKeyVaultConnection
|
||||
| TAzureAppConfigurationConnection
|
||||
| TDatabricksConnection;
|
||||
| TDatabricksConnection
|
||||
| THumanitecConnection;
|
||||
|
||||
export type TAvailableAppConnection = Pick<TAppConnection, "name" | "id">;
|
||||
|
||||
@@ -54,4 +57,5 @@ export type TAppConnectionMap = {
|
||||
[AppConnection.AzureKeyVault]: TAzureKeyVaultConnection;
|
||||
[AppConnection.AzureAppConfiguration]: TAzureAppConfigurationConnection;
|
||||
[AppConnection.Databricks]: TDatabricksConnection;
|
||||
[AppConnection.Humanitec]: THumanitecConnection;
|
||||
};
|
||||
|
||||
@@ -5,7 +5,8 @@ export enum SecretSync {
|
||||
GCPSecretManager = "gcp-secret-manager",
|
||||
AzureKeyVault = "azure-key-vault",
|
||||
AzureAppConfiguration = "azure-app-configuration",
|
||||
Databricks = "databricks"
|
||||
Databricks = "databricks",
|
||||
Humanitec = "humanitec"
|
||||
}
|
||||
|
||||
export enum SecretSyncStatus {
|
||||
|
||||
16
frontend/src/hooks/api/secretSyncs/types/humanitec-sync.ts
Normal file
16
frontend/src/hooks/api/secretSyncs/types/humanitec-sync.ts
Normal file
@@ -0,0 +1,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 type THumanitecSync = TRootSecretSync & {
|
||||
destination: SecretSync.Humanitec;
|
||||
destinationConfig: {
|
||||
org: string;
|
||||
app: string;
|
||||
};
|
||||
connection: {
|
||||
app: AppConnection.Humanitec;
|
||||
name: string;
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
@@ -8,6 +8,7 @@ import { TAwsSecretsManagerSync } from "./aws-secrets-manager-sync";
|
||||
import { TAzureAppConfigurationSync } from "./azure-app-configuration-sync";
|
||||
import { TAzureKeyVaultSync } from "./azure-key-vault-sync";
|
||||
import { TGcpSync } from "./gcp-sync";
|
||||
import { THumanitecSync } from "./humanitec-sync";
|
||||
|
||||
export type TSecretSyncOption = {
|
||||
name: string;
|
||||
@@ -22,7 +23,8 @@ export type TSecretSync =
|
||||
| TGcpSync
|
||||
| TAzureKeyVaultSync
|
||||
| TAzureAppConfigurationSync
|
||||
| TDatabricksSync;
|
||||
| TDatabricksSync
|
||||
| THumanitecSync;
|
||||
|
||||
export type TListSecretSyncs = { secretSyncs: TSecretSync[] };
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ import { AzureKeyVaultConnectionForm } from "./AzureKeyVaultConnectionForm";
|
||||
import { DatabricksConnectionForm } from "./DatabricksConnectionForm";
|
||||
import { GcpConnectionForm } from "./GcpConnectionForm";
|
||||
import { GitHubConnectionForm } from "./GitHubConnectionForm";
|
||||
import { HumanitecConnectionForm } from "./HumanitecConnectionForm";
|
||||
|
||||
type FormProps = {
|
||||
onComplete: (appConnection: TAppConnection) => void;
|
||||
@@ -62,6 +63,8 @@ const CreateForm = ({ app, onComplete }: CreateFormProps) => {
|
||||
return <AzureAppConfigurationConnectionForm />;
|
||||
case AppConnection.Databricks:
|
||||
return <DatabricksConnectionForm onSubmit={onSubmit} />;
|
||||
case AppConnection.Humanitec:
|
||||
return <HumanitecConnectionForm onSubmit={onSubmit} />;
|
||||
default:
|
||||
throw new Error(`Unhandled App ${app}`);
|
||||
}
|
||||
@@ -107,6 +110,8 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
|
||||
return <AzureAppConfigurationConnectionForm appConnection={appConnection} />;
|
||||
case AppConnection.Databricks:
|
||||
return <DatabricksConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||
case AppConnection.Humanitec:
|
||||
return <HumanitecConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||
default:
|
||||
throw new Error(`Unhandled App ${(appConnection as TAppConnection).app}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
import { Controller, FormProvider, useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
|
||||
import {
|
||||
Button,
|
||||
FormControl,
|
||||
ModalClose,
|
||||
SecretInput,
|
||||
Select,
|
||||
SelectItem
|
||||
} from "@app/components/v2";
|
||||
import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
|
||||
import { HumanitecConnectionMethod, THumanitecConnection } from "@app/hooks/api/appConnections";
|
||||
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||
|
||||
import {
|
||||
genericAppConnectionFieldsSchema,
|
||||
GenericAppConnectionsFields
|
||||
} from "./GenericAppConnectionFields";
|
||||
|
||||
type Props = {
|
||||
appConnection?: THumanitecConnection;
|
||||
onSubmit: (formData: FormData) => void;
|
||||
};
|
||||
|
||||
const rootSchema = genericAppConnectionFieldsSchema.extend({
|
||||
app: z.literal(AppConnection.Humanitec)
|
||||
});
|
||||
|
||||
const formSchema = z.discriminatedUnion("method", [
|
||||
rootSchema.extend({
|
||||
method: z.literal(HumanitecConnectionMethod.AccessKey),
|
||||
credentials: z.object({
|
||||
accessKeyId: z.string().trim().min(1, "Service API Token required")
|
||||
})
|
||||
})
|
||||
]);
|
||||
|
||||
type FormData = z.infer<typeof formSchema>;
|
||||
|
||||
export const HumanitecConnectionForm = ({ appConnection, onSubmit }: Props) => {
|
||||
const isUpdate = Boolean(appConnection);
|
||||
|
||||
const form = useForm<FormData>({
|
||||
resolver: zodResolver(formSchema),
|
||||
defaultValues: appConnection ?? {
|
||||
app: AppConnection.Humanitec,
|
||||
method: HumanitecConnectionMethod.AccessKey
|
||||
}
|
||||
});
|
||||
|
||||
const {
|
||||
handleSubmit,
|
||||
control,
|
||||
formState: { isSubmitting, isDirty }
|
||||
} = form;
|
||||
|
||||
return (
|
||||
<FormProvider {...form}>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
{!isUpdate && <GenericAppConnectionsFields />}
|
||||
<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.AWS].name
|
||||
}. This field cannot be changed after creation.`}
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
label="Method"
|
||||
>
|
||||
<Select
|
||||
isDisabled={isUpdate}
|
||||
value={value}
|
||||
onValueChange={(val) => onChange(val)}
|
||||
className="w-full border border-mineshaft-500"
|
||||
position="popper"
|
||||
dropdownContainerClassName="max-w-none"
|
||||
>
|
||||
{Object.values(HumanitecConnectionMethod).map((method) => {
|
||||
return (
|
||||
<SelectItem value={method} key={method}>
|
||||
{getAppConnectionMethodDetails(method).name}{" "}
|
||||
</SelectItem>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
<Controller
|
||||
name="credentials.accessKeyId"
|
||||
control={control}
|
||||
shouldUnregister
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl
|
||||
errorText={error?.message}
|
||||
isError={Boolean(error?.message)}
|
||||
label="Service API 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}
|
||||
isDisabled={isSubmitting || !isDirty}
|
||||
>
|
||||
{isUpdate ? "Update Credentials" : "Connect to Humanitec"}
|
||||
</Button>
|
||||
<ModalClose asChild>
|
||||
<Button colorSchema="secondary" variant="plain">
|
||||
Cancel
|
||||
</Button>
|
||||
</ModalClose>
|
||||
</div>
|
||||
</form>
|
||||
</FormProvider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,14 @@
|
||||
import { THumanitecSync } from "@app/hooks/api/secretSyncs/types/humanitec-sync";
|
||||
|
||||
import { getSecretSyncDestinationColValues } from "../helpers";
|
||||
import { SecretSyncTableCell } from "../SecretSyncTableCell";
|
||||
|
||||
type Props = {
|
||||
secretSync: THumanitecSync;
|
||||
};
|
||||
|
||||
export const HumanitecSyncDestinationCol = ({ secretSync }: Props) => {
|
||||
const { primaryText, secondaryText } = getSecretSyncDestinationColValues(secretSync);
|
||||
|
||||
return <SecretSyncTableCell primaryText={primaryText} secondaryText={secondaryText} />;
|
||||
};
|
||||
@@ -7,6 +7,7 @@ import { AzureKeyVaultDestinationSyncCol } from "./AzureKeyVaultDestinationSyncC
|
||||
import { DatabricksSyncDestinationCol } from "./DatabricksSyncDestinationCol";
|
||||
import { GcpSyncDestinationCol } from "./GcpSyncDestinationCol";
|
||||
import { GitHubSyncDestinationCol } from "./GitHubSyncDestinationCol";
|
||||
import { HumanitecSyncDestinationCol } from "./HumanitecSyncDestinationCol";
|
||||
|
||||
type Props = {
|
||||
secretSync: TSecretSync;
|
||||
@@ -28,6 +29,8 @@ export const SecretSyncDestinationCol = ({ secretSync }: Props) => {
|
||||
return <AzureAppConfigurationDestinationSyncCol secretSync={secretSync} />;
|
||||
case SecretSync.Databricks:
|
||||
return <DatabricksSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.Humanitec:
|
||||
return <HumanitecSyncDestinationCol secretSync={secretSync} />;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled Secret Sync Destination Col: ${(secretSync as TSecretSync).destination}`
|
||||
|
||||
@@ -59,6 +59,10 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
|
||||
case SecretSync.Databricks:
|
||||
primaryText = destinationConfig.scope;
|
||||
break;
|
||||
case SecretSync.Humanitec:
|
||||
primaryText = destinationConfig.app;
|
||||
secondaryText = `Org - ${destinationConfig.org}`;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Col Values ${destination}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { SecretSyncLabel } from "@app/components/secret-syncs";
|
||||
import { THumanitecSync } from "@app/hooks/api/secretSyncs/types/humanitec-sync";
|
||||
|
||||
type Props = {
|
||||
secretSync: THumanitecSync;
|
||||
};
|
||||
|
||||
export const HumanitecSyncDestinationSection = ({ secretSync }: Props) => {
|
||||
const {
|
||||
destinationConfig: { app, org }
|
||||
} = secretSync;
|
||||
|
||||
return (
|
||||
<>
|
||||
<SecretSyncLabel label="App">{app}</SecretSyncLabel>
|
||||
<SecretSyncLabel label="Org">{org}</SecretSyncLabel>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -17,6 +17,7 @@ import { GitHubSyncDestinationSection } from "@app/pages/secret-manager/SecretSy
|
||||
import { AzureAppConfigurationSyncDestinationSection } from "./AzureAppConfigurationSyncDestinationSection";
|
||||
import { AzureKeyVaultSyncDestinationSection } from "./AzureKeyVaultSyncDestinationSection";
|
||||
import { GcpSyncDestinationSection } from "./GcpSyncDestinationSection";
|
||||
import { HumanitecSyncDestinationSection } from "./HumanitecSyncDestinationSection";
|
||||
|
||||
type Props = {
|
||||
secretSync: TSecretSync;
|
||||
@@ -53,6 +54,9 @@ export const SecretSyncDestinationSection = ({ secretSync, onEditDestination }:
|
||||
case SecretSync.Databricks:
|
||||
DestinationComponents = <DatabricksSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
case SecretSync.Humanitec:
|
||||
DestinationComponents = <HumanitecSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Section components: ${destination}`);
|
||||
}
|
||||
|
||||
@@ -46,6 +46,7 @@ export const SecretSyncOptionsSection = ({ secretSync, onEditOptions }: Props) =
|
||||
case SecretSync.AzureKeyVault:
|
||||
case SecretSync.AzureAppConfiguration:
|
||||
case SecretSync.Databricks:
|
||||
case SecretSync.Humanitec:
|
||||
AdditionalSyncOptionsComponent = null;
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user