secret sync + tweaks

This commit is contained in:
x032205
2025-05-07 17:57:00 -04:00
parent 581840a701
commit 36954a9df9
36 changed files with 799 additions and 28 deletions
@@ -40,7 +40,14 @@ export const SecretSyncStatusBadge = ({ status }: Props) => {
return (
<Badge className="flex h-5 w-min items-center gap-1.5 whitespace-nowrap" variant={variant}>
<FontAwesomeIcon icon={icon} />
<FontAwesomeIcon
icon={icon}
className={
[SecretSyncStatus.Pending, SecretSyncStatus.Running].includes(status)
? "animate-spin"
: ""
}
/>
<span>{text}</span>
</Badge>
);
@@ -0,0 +1,179 @@
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, Tooltip } from "@app/components/v2";
import {
useOCIConnectionListCompartments,
useOCIConnectionListVaultKeys,
useOCIConnectionListVaults
} from "@app/hooks/api/appConnections/oci";
import { SecretSync } from "@app/hooks/api/secretSyncs";
import { TSecretSyncForm } from "../schemas";
export const OCIVaultSyncFields = () => {
const { control, setValue } = useFormContext<
TSecretSyncForm & { destination: SecretSync.OCIVault }
>();
const connectionId = useWatch({ name: "connection.id", control });
// Compartments
const { data: compartments, isLoading: isCompartmentsLoading } = useOCIConnectionListCompartments(
connectionId,
{
enabled: Boolean(connectionId)
}
);
// Vaults
const selectedCompartment = useWatch({ name: "destinationConfig.compartmentOcid", control });
const { data: vaults, isLoading: isVaultsLoading } = useOCIConnectionListVaults(
{ connectionId, compartmentOcid: selectedCompartment },
{
enabled: Boolean(connectionId)
}
);
// Keys
const selectedVault = useWatch({ name: "destinationConfig.vaultOcid", control });
const { data: keys, isLoading: isKeysLoading } = useOCIConnectionListVaultKeys(
{ connectionId, compartmentOcid: selectedCompartment, vaultOcid: selectedVault },
{
enabled: Boolean(connectionId)
}
);
return (
<>
<SecretSyncConnectionField
onChange={() => {
setValue("destinationConfig.compartmentOcid", "");
setValue("destinationConfig.vaultOcid", "");
setValue("destinationConfig.keyOcid", "");
}}
/>
<Controller
name="destinationConfig.compartmentOcid"
control={control}
render={({ field: { value, onChange }, fieldState: { error } }) => (
<FormControl
isError={Boolean(error)}
errorText={error?.message}
label="Compartment"
helperText={
<Tooltip
className="max-w-md"
content="Ensure the compartment exists and that the connection has permission to view it."
>
<div>
<span>Don&#39;t see the compartment you&#39;re looking for?</span>{" "}
<FontAwesomeIcon icon={faCircleInfo} className="text-mineshaft-400" />
</div>
</Tooltip>
}
>
<FilterableSelect
menuPlacement="top"
isLoading={isCompartmentsLoading && Boolean(connectionId)}
isDisabled={!connectionId}
value={compartments?.find((c) => c.id === value) ?? null}
onChange={(option) => {
onChange((option as SingleValue<{ id: string }>)?.id ?? null);
setValue("destinationConfig.vaultOcid", "");
setValue("destinationConfig.keyOcid", "");
}}
options={compartments}
placeholder="Select a compartment..."
getOptionLabel={(option) => option.name}
getOptionValue={(option) => option.id}
/>
</FormControl>
)}
/>
<Controller
name="destinationConfig.vaultOcid"
control={control}
render={({ field: { value, onChange }, fieldState: { error } }) => (
<FormControl
isError={Boolean(error)}
errorText={error?.message}
label="Vault"
helperText={
<Tooltip
className="max-w-md"
content="Ensure the vault exists in the selected compartment and that the connection has permission to view it."
>
<div>
<span>Don&#39;t see the vault you&#39;re looking for?</span>{" "}
<FontAwesomeIcon icon={faCircleInfo} className="text-mineshaft-400" />
</div>
</Tooltip>
}
>
<FilterableSelect
menuPlacement="top"
isLoading={isVaultsLoading && Boolean(connectionId)}
isDisabled={!connectionId || !selectedCompartment || !vaults}
value={vaults?.find((v) => v.id === value) ?? null}
onChange={(option) => {
onChange((option as SingleValue<{ id: string }>)?.id ?? null);
setValue("destinationConfig.keyOcid", "");
}}
options={vaults}
isClearable
placeholder="Select a vault..."
getOptionLabel={(option) => option.displayName}
getOptionValue={(option) => option.id}
/>
</FormControl>
)}
/>
<Controller
name="destinationConfig.keyOcid"
control={control}
render={({ field: { value, onChange }, fieldState: { error } }) => (
<FormControl
isError={Boolean(error)}
errorText={error?.message}
label="Encryption Key"
helperText={
<Tooltip
className="max-w-md"
content="Ensure the key exists in the selected vault and that the connection has permission to view it."
>
<div>
<span>Don&#39;t see the key you&#39;re looking for?</span>{" "}
<FontAwesomeIcon icon={faCircleInfo} className="text-mineshaft-400" />
</div>
</Tooltip>
}
>
<FilterableSelect
menuPlacement="top"
isLoading={isKeysLoading && Boolean(connectionId)}
isDisabled={
!connectionId || !selectedCompartment || !selectedVault || !vaults || !keys
}
value={keys?.find((v) => v.id === value) ?? null}
onChange={(option) => {
onChange((option as SingleValue<{ id: string }>)?.id ?? null);
}}
options={keys}
isClearable
placeholder="Select a key..."
getOptionLabel={(option) => option.displayName}
getOptionValue={(option) => option.id}
/>
</FormControl>
)}
/>
</>
);
};
@@ -13,6 +13,7 @@ import { GcpSyncFields } from "./GcpSyncFields";
import { GitHubSyncFields } from "./GitHubSyncFields";
import { HCVaultSyncFields } from "./HCVaultSyncFields";
import { HumanitecSyncFields } from "./HumanitecSyncFields";
import { OCIVaultSyncFields } from "./OCIVaultSyncFields";
import { TeamCitySyncFields } from "./TeamCitySyncFields";
import { TerraformCloudSyncFields } from "./TerraformCloudSyncFields";
import { VercelSyncFields } from "./VercelSyncFields";
@@ -52,6 +53,8 @@ export const SecretSyncDestinationFields = () => {
return <HCVaultSyncFields />;
case SecretSync.TeamCity:
return <TeamCitySyncFields />;
case SecretSync.OCIVault:
return <OCIVaultSyncFields />;
default:
throw new Error(`Unhandled Destination Config Field: ${destination}`);
}
@@ -45,6 +45,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
case SecretSync.Windmill:
case SecretSync.HCVault:
case SecretSync.TeamCity:
case SecretSync.OCIVault:
AdditionalSyncOptionsFieldsComponent = null;
break;
default:
@@ -0,0 +1,20 @@
import { useFormContext } from "react-hook-form";
import { TSecretSyncForm } from "@app/components/secret-syncs/forms/schemas";
import { GenericFieldLabel } from "@app/components/v2";
import { SecretSync } from "@app/hooks/api/secretSyncs";
export const OCIVaultSyncReviewFields = () => {
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.OCIVault }>();
const compartmentOcid = watch("destinationConfig.compartmentOcid");
const vaultOcid = watch("destinationConfig.vaultOcid");
const keyOcid = watch("destinationConfig.keyOcid");
return (
<>
<GenericFieldLabel label="Compartment OCID">{compartmentOcid}</GenericFieldLabel>
<GenericFieldLabel label="Vault OCID">{vaultOcid}</GenericFieldLabel>
<GenericFieldLabel label="Key OCID">{keyOcid}</GenericFieldLabel>
</>
);
};
@@ -23,6 +23,7 @@ import { GcpSyncReviewFields } from "./GcpSyncReviewFields";
import { GitHubSyncReviewFields } from "./GitHubSyncReviewFields";
import { HCVaultSyncReviewFields } from "./HCVaultSyncReviewFields";
import { HumanitecSyncReviewFields } from "./HumanitecSyncReviewFields";
import { OCIVaultSyncReviewFields } from "./OCIVaultSyncReviewFields";
import { TeamCitySyncReviewFields } from "./TeamCitySyncReviewFields";
import { TerraformCloudSyncReviewFields } from "./TerraformCloudSyncReviewFields";
import { VercelSyncReviewFields } from "./VercelSyncReviewFields";
@@ -96,6 +97,9 @@ export const SecretSyncReviewFields = () => {
case SecretSync.TeamCity:
DestinationFieldsComponent = <TeamCitySyncReviewFields />;
break;
case SecretSync.OCIVault:
DestinationFieldsComponent = <OCIVaultSyncReviewFields />;
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 OCIVaultSyncDestinationSchema = BaseSecretSyncSchema().merge(
z.object({
destination: z.literal(SecretSync.OCIVault),
destinationConfig: z.object({
compartmentOcid: z.string().trim().min(1, "Compartment OCID required"),
vaultOcid: z.string().trim().min(1, "Vault OCID required"),
keyOcid: z.string().trim().min(1, "Key OCID required")
})
})
);
@@ -10,6 +10,7 @@ import { GcpSyncDestinationSchema } from "./gcp-sync-destination-schema";
import { GitHubSyncDestinationSchema } from "./github-sync-destination-schema";
import { HCVaultSyncDestinationSchema } from "./hc-vault-sync-destination-schema";
import { HumanitecSyncDestinationSchema } from "./humanitec-sync-destination-schema";
import { OCIVaultSyncDestinationSchema } from "./oci-vault-sync-destination-schema";
import { TeamCitySyncDestinationSchema } from "./teamcity-sync-destination-schema";
import { TerraformCloudSyncDestinationSchema } from "./terraform-cloud-destination-schema";
import { VercelSyncDestinationSchema } from "./vercel-sync-destination-schema";
@@ -29,7 +30,8 @@ const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
VercelSyncDestinationSchema,
WindmillSyncDestinationSchema,
HCVaultSyncDestinationSchema,
TeamCitySyncDestinationSchema
TeamCitySyncDestinationSchema,
OCIVaultSyncDestinationSchema
]);
export const SecretSyncFormSchema = SecretSyncUnionSchema;
+6 -1
View File
@@ -47,6 +47,10 @@ export const SECRET_SYNC_MAP: Record<SecretSync, { name: string; image: string }
[SecretSync.TeamCity]: {
name: "TeamCity",
image: "TeamCity.png"
},
[SecretSync.OCIVault]: {
name: "OCI Vault",
image: "Oracle.png"
}
};
@@ -64,7 +68,8 @@ export const SECRET_SYNC_CONNECTION_MAP: Record<SecretSync, AppConnection> = {
[SecretSync.Vercel]: AppConnection.Vercel,
[SecretSync.Windmill]: AppConnection.Windmill,
[SecretSync.HCVault]: AppConnection.HCVault,
[SecretSync.TeamCity]: AppConnection.TeamCity
[SecretSync.TeamCity]: AppConnection.TeamCity,
[SecretSync.OCIVault]: AppConnection.OCI
};
export const SECRET_SYNC_INITIAL_SYNC_BEHAVIOR_MAP: Record<
@@ -3,12 +3,47 @@ import { useQuery, UseQueryOptions } from "@tanstack/react-query";
import { apiRequest } from "@app/config/request";
import { appConnectionKeys } from "../queries";
import { TListOCIVaultKeys, TListOCIVaults, TOCIVault, TOCIVaultKey } from "./types";
import {
TListOCIVaultKeys,
TListOCIVaults,
TOCICompartment,
TOCIVault,
TOCIVaultKey
} from "./types";
const ociConnectionKeys = {
all: [...appConnectionKeys.all, "oci"] as const,
listVaults: (connectionId: string) => [...ociConnectionKeys.all, "vaults", connectionId] as const,
listVaultKeys: (connectionId: string) => [...ociConnectionKeys.all, "keys", connectionId] as const
listCompartments: (connectionId: string) =>
[...ociConnectionKeys.all, "compartments", connectionId] as const,
listVaults: (connectionId: string, compartmentOcid: string) =>
[...ociConnectionKeys.all, "vaults", connectionId, compartmentOcid] as const,
listVaultKeys: (connectionId: string, compartmentOcid: string, vaultOcid: string) =>
[...ociConnectionKeys.all, "keys", connectionId, compartmentOcid, vaultOcid] as const
};
export const useOCIConnectionListCompartments = (
connectionId: string,
options?: Omit<
UseQueryOptions<
TOCICompartment[],
unknown,
TOCICompartment[],
ReturnType<typeof ociConnectionKeys.listCompartments>
>,
"queryKey" | "queryFn"
>
) => {
return useQuery({
queryKey: ociConnectionKeys.listCompartments(connectionId),
queryFn: async () => {
const { data } = await apiRequest.get<TOCICompartment[]>(
`/api/v1/app-connections/oci/${connectionId}/compartments`
);
return data;
},
...options
});
};
export const useOCIConnectionListVaults = (
@@ -24,7 +59,7 @@ export const useOCIConnectionListVaults = (
>
) => {
return useQuery({
queryKey: ociConnectionKeys.listVaults(connectionId),
queryKey: ociConnectionKeys.listVaults(connectionId, compartmentOcid),
queryFn: async () => {
const { data } = await apiRequest.get<TOCIVault[]>(
`/api/v1/app-connections/oci/${connectionId}/vaults`,
@@ -54,7 +89,7 @@ export const useOCIConnectionListVaultKeys = (
>
) => {
return useQuery({
queryKey: ociConnectionKeys.listVaultKeys(connectionId),
queryKey: ociConnectionKeys.listVaultKeys(connectionId, compartmentOcid, vaultOcid),
queryFn: async () => {
const { data } = await apiRequest.get<TOCIVaultKey[]>(
`/api/v1/app-connections/oci/${connectionId}/vault-keys`,
@@ -1,10 +1,12 @@
// Response types
export type TOCICompartment = {
id: string;
name: string;
};
export type TOCIVault = {
id: string;
displayName: string;
compartmentId: string;
timeCreated: string;
lifecycleState: string;
};
export type TOCIVaultKey = {
+2 -1
View File
@@ -12,7 +12,8 @@ export enum SecretSync {
Vercel = "vercel",
Windmill = "windmill",
HCVault = "hashicorp-vault",
TeamCity = "teamcity"
TeamCity = "teamcity",
OCIVault = "oci-vault"
}
export enum SecretSyncStatus {
@@ -11,6 +11,7 @@ import { TGcpSync } from "./gcp-sync";
import { TGitHubSync } from "./github-sync";
import { THCVaultSync } from "./hc-vault-sync";
import { THumanitecSync } from "./humanitec-sync";
import { TOCIVaultSync } from "./oci-vault-sync";
import { TTeamCitySync } from "./teamcity-sync";
import { TTerraformCloudSync } from "./terraform-cloud-sync";
import { TVercelSync } from "./vercel-sync";
@@ -36,7 +37,8 @@ export type TSecretSync =
| TVercelSync
| TWindmillSync
| THCVaultSync
| TTeamCitySync;
| TTeamCitySync
| TOCIVaultSync;
export type TListSecretSyncs = { secretSyncs: TSecretSync[] };
@@ -0,0 +1,17 @@
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 TOCIVaultSync = TRootSecretSync & {
destination: SecretSync.OCIVault;
destinationConfig: {
compartmentOcid: string;
vaultOcid: string;
keyOcid: string;
};
connection: {
app: AppConnection.OCI;
name: string;
id: string;
};
};
@@ -0,0 +1,14 @@
import { TOCIVaultSync } from "@app/hooks/api/secretSyncs/types/oci-vault-sync";
import { getSecretSyncDestinationColValues } from "../helpers";
import { SecretSyncTableCell } from "../SecretSyncTableCell";
type Props = {
secretSync: TOCIVaultSync;
};
export const OCIVaultSyncDestinationCol = ({ secretSync }: Props) => {
const { primaryText, secondaryText } = getSecretSyncDestinationColValues(secretSync);
return <SecretSyncTableCell primaryText={primaryText} secondaryText={secondaryText} />;
};
@@ -10,6 +10,7 @@ import { GcpSyncDestinationCol } from "./GcpSyncDestinationCol";
import { GitHubSyncDestinationCol } from "./GitHubSyncDestinationCol";
import { HCVaultSyncDestinationCol } from "./HCVaultSyncDestinationCol";
import { HumanitecSyncDestinationCol } from "./HumanitecSyncDestinationCol";
import { OCIVaultSyncDestinationCol } from "./OCIVaultSyncDestinationCol";
import { TeamCitySyncDestinationCol } from "./TeamCitySyncDestinationCol";
import { TerraformCloudSyncDestinationCol } from "./TerraformCloudSyncDestinationCol";
import { VercelSyncDestinationCol } from "./VercelSyncDestinationCol";
@@ -49,6 +50,8 @@ export const SecretSyncDestinationCol = ({ secretSync }: Props) => {
return <HCVaultSyncDestinationCol secretSync={secretSync} />;
case SecretSync.TeamCity:
return <TeamCitySyncDestinationCol secretSync={secretSync} />;
case SecretSync.OCIVault:
return <OCIVaultSyncDestinationCol secretSync={secretSync} />;
default:
throw new Error(
`Unhandled Secret Sync Destination Col: ${(secretSync as TSecretSync).destination}`
@@ -102,6 +102,11 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
primaryText = destinationConfig.project;
secondaryText = destinationConfig.buildConfig;
break;
case SecretSync.OCIVault:
// TODO(andrey): Truncating these may make them look better
primaryText = destinationConfig.compartmentOcid;
secondaryText = destinationConfig.vaultOcid;
break;
default:
throw new Error(`Unhandled Destination Col Values ${destination}`);
}
@@ -0,0 +1,20 @@
import { GenericFieldLabel } from "@app/components/secret-syncs";
import { TOCIVaultSync } from "@app/hooks/api/secretSyncs/types/oci-vault-sync";
type Props = {
secretSync: TOCIVaultSync;
};
export const OCIVaultSyncDestinationSection = ({ secretSync }: Props) => {
const {
destinationConfig: { compartmentOcid, keyOcid, vaultOcid }
} = secretSync;
return (
<>
<GenericFieldLabel label="Compartment OCID">{compartmentOcid}</GenericFieldLabel>
<GenericFieldLabel label="Vault OCID">{vaultOcid}</GenericFieldLabel>
<GenericFieldLabel label="Key OCID">{keyOcid}</GenericFieldLabel>
</>
);
};
@@ -20,6 +20,7 @@ import { GcpSyncDestinationSection } from "./GcpSyncDestinationSection";
import { GitHubSyncDestinationSection } from "./GitHubSyncDestinationSection";
import { HCVaultSyncDestinationSection } from "./HCVaultSyncDestinationSection";
import { HumanitecSyncDestinationSection } from "./HumanitecSyncDestinationSection";
import { OCIVaultSyncDestinationSection } from "./OCIVaultSyncDestinationSection";
import { TeamCitySyncDestinationSection } from "./TeamCitySyncDestinationSection";
import { TerraformCloudSyncDestinationSection } from "./TerraformCloudSyncDestinationSection";
import { VercelSyncDestinationSection } from "./VercelSyncDestinationSection";
@@ -81,6 +82,9 @@ export const SecretSyncDestinationSection = ({ secretSync, onEditDestination }:
case SecretSync.TeamCity:
DestinationComponents = <TeamCitySyncDestinationSection secretSync={secretSync} />;
break;
case SecretSync.OCIVault:
DestinationComponents = <OCIVaultSyncDestinationSection secretSync={secretSync} />;
break;
default:
throw new Error(`Unhandled Destination Section components: ${destination}`);
}
@@ -54,6 +54,7 @@ export const SecretSyncOptionsSection = ({ secretSync, onEditOptions }: Props) =
case SecretSync.Windmill:
case SecretSync.HCVault:
case SecretSync.TeamCity:
case SecretSync.OCIVault:
AdditionalSyncOptionsComponent = null;
break;
default: