mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Fly.io secret sync
This commit is contained in:
@@ -2387,6 +2387,9 @@ export const SecretSyncs = {
|
||||
},
|
||||
ONEPASS: {
|
||||
vaultId: "The ID of the 1Password vault to sync secrets to."
|
||||
},
|
||||
FLYIO: {
|
||||
appId: "The ID of the Fly.io app to sync secrets to."
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -35,7 +35,6 @@ export const registerFlyioConnectionRouter = async (server: FastifyZodProvider)
|
||||
response: {
|
||||
200: z
|
||||
.object({
|
||||
// TODO(andrey): apps
|
||||
id: z.string(),
|
||||
name: z.string()
|
||||
})
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { CreateFlyioSyncSchema, FlyioSyncSchema, UpdateFlyioSyncSchema } from "@app/services/secret-sync/flyio";
|
||||
import { SecretSync } from "@app/services/secret-sync/secret-sync-enums";
|
||||
|
||||
import { registerSyncSecretsEndpoints } from "./secret-sync-endpoints";
|
||||
|
||||
export const registerFlyioSyncRouter = async (server: FastifyZodProvider) =>
|
||||
registerSyncSecretsEndpoints({
|
||||
destination: SecretSync.Flyio,
|
||||
server,
|
||||
responseSchema: FlyioSyncSchema,
|
||||
createSchema: CreateFlyioSyncSchema,
|
||||
updateSchema: UpdateFlyioSyncSchema
|
||||
});
|
||||
@@ -9,6 +9,7 @@ import { registerAzureDevOpsSyncRouter } from "./azure-devops-sync-router";
|
||||
import { registerAzureKeyVaultSyncRouter } from "./azure-key-vault-sync-router";
|
||||
import { registerCamundaSyncRouter } from "./camunda-sync-router";
|
||||
import { registerDatabricksSyncRouter } from "./databricks-sync-router";
|
||||
import { registerFlyioSyncRouter } from "./flyio-sync-router";
|
||||
import { registerGcpSyncRouter } from "./gcp-sync-router";
|
||||
import { registerGitHubSyncRouter } from "./github-sync-router";
|
||||
import { registerHCVaultSyncRouter } from "./hc-vault-sync-router";
|
||||
@@ -37,5 +38,6 @@ export const SECRET_SYNC_REGISTER_ROUTER_MAP: Record<SecretSync, (server: Fastif
|
||||
[SecretSync.HCVault]: registerHCVaultSyncRouter,
|
||||
[SecretSync.TeamCity]: registerTeamCitySyncRouter,
|
||||
[SecretSync.OCIVault]: registerOCIVaultSyncRouter,
|
||||
[SecretSync.OnePass]: registerOnePassSyncRouter
|
||||
[SecretSync.OnePass]: registerOnePassSyncRouter,
|
||||
[SecretSync.Flyio]: registerFlyioSyncRouter
|
||||
};
|
||||
|
||||
@@ -23,6 +23,7 @@ import { AzureDevOpsSyncListItemSchema, AzureDevOpsSyncSchema } from "@app/servi
|
||||
import { AzureKeyVaultSyncListItemSchema, AzureKeyVaultSyncSchema } from "@app/services/secret-sync/azure-key-vault";
|
||||
import { CamundaSyncListItemSchema, CamundaSyncSchema } from "@app/services/secret-sync/camunda";
|
||||
import { DatabricksSyncListItemSchema, DatabricksSyncSchema } from "@app/services/secret-sync/databricks";
|
||||
import { FlyioSyncListItemSchema, FlyioSyncSchema } from "@app/services/secret-sync/flyio";
|
||||
import { GcpSyncListItemSchema, GcpSyncSchema } from "@app/services/secret-sync/gcp";
|
||||
import { GitHubSyncListItemSchema, GitHubSyncSchema } from "@app/services/secret-sync/github";
|
||||
import { HCVaultSyncListItemSchema, HCVaultSyncSchema } from "@app/services/secret-sync/hc-vault";
|
||||
@@ -49,7 +50,8 @@ const SecretSyncSchema = z.discriminatedUnion("destination", [
|
||||
HCVaultSyncSchema,
|
||||
TeamCitySyncSchema,
|
||||
OCIVaultSyncSchema,
|
||||
OnePassSyncSchema
|
||||
OnePassSyncSchema,
|
||||
FlyioSyncSchema
|
||||
]);
|
||||
|
||||
const SecretSyncOptionsSchema = z.discriminatedUnion("destination", [
|
||||
@@ -69,7 +71,8 @@ const SecretSyncOptionsSchema = z.discriminatedUnion("destination", [
|
||||
HCVaultSyncListItemSchema,
|
||||
TeamCitySyncListItemSchema,
|
||||
OCIVaultSyncListItemSchema,
|
||||
OnePassSyncListItemSchema
|
||||
OnePassSyncListItemSchema,
|
||||
FlyioSyncListItemSchema
|
||||
]);
|
||||
|
||||
export const registerSecretSyncRouter = async (server: FastifyZodProvider) => {
|
||||
|
||||
@@ -21,7 +21,6 @@ export type TFlyioConnectionConfig = DiscriminativePick<TFlyioConnectionInput, "
|
||||
orgId: string;
|
||||
};
|
||||
|
||||
// TODO(andrey): apps
|
||||
export type TFlyioApp = {
|
||||
id: string;
|
||||
name: string;
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||
import { SecretSync } from "@app/services/secret-sync/secret-sync-enums";
|
||||
import { TSecretSyncListItem } from "@app/services/secret-sync/secret-sync-types";
|
||||
|
||||
export const FLYIO_SYNC_LIST_OPTION: TSecretSyncListItem = {
|
||||
name: "Fly.io",
|
||||
destination: SecretSync.Flyio,
|
||||
connection: AppConnection.Flyio,
|
||||
canImportSecrets: false
|
||||
};
|
||||
132
backend/src/services/secret-sync/flyio/flyio-sync-fns.ts
Normal file
132
backend/src/services/secret-sync/flyio/flyio-sync-fns.ts
Normal file
@@ -0,0 +1,132 @@
|
||||
import { request } from "@app/lib/config/request";
|
||||
import {
|
||||
TDeleteFlyioVariable,
|
||||
TFlyioListVariables,
|
||||
TFlyioSecret,
|
||||
TFlyioSyncWithCredentials,
|
||||
TPutFlyioVariable
|
||||
} from "@app/services/secret-sync/flyio/flyio-sync-types";
|
||||
import { SecretSyncError } from "@app/services/secret-sync/secret-sync-errors";
|
||||
import { matchesSchema } from "@app/services/secret-sync/secret-sync-fns";
|
||||
import { TSecretMap } from "@app/services/secret-sync/secret-sync-types";
|
||||
|
||||
import { SECRET_SYNC_NAME_MAP } from "../secret-sync-maps";
|
||||
|
||||
const listFlyioSecrets = async ({ accessToken, appId }: TFlyioListVariables) => {
|
||||
const { data } = await request.post<{ data: { app: { secrets: TFlyioSecret[] } } }>(
|
||||
"https://api.fly.io/graphql",
|
||||
{
|
||||
query: "query GetAppSecrets($appId: String!) { app(id: $appId) { id name secrets { name createdAt } } }",
|
||||
variables: { appId }
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json"
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return data.data.app.secrets.map((s) => s.name);
|
||||
};
|
||||
|
||||
const putFlyioSecrets = async ({ accessToken, appId, secretMap }: TPutFlyioVariable) => {
|
||||
return request.post(
|
||||
"https://api.fly.io/graphql",
|
||||
{
|
||||
query:
|
||||
"mutation SetAppSecrets($appId: ID!, $secrets: [SecretInput!]!) { setSecrets(input: { appId: $appId, secrets: $secrets }) { app { name } release { version } } }",
|
||||
variables: {
|
||||
appId,
|
||||
secrets: Object.entries(secretMap).map(([key, { value }]) => ({ key, value }))
|
||||
}
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
const deleteFlyioSecrets = async ({ accessToken, appId, keys }: TDeleteFlyioVariable) => {
|
||||
return request.post(
|
||||
"https://api.fly.io/graphql",
|
||||
{
|
||||
query:
|
||||
"mutation UnsetAppSecrets($appId: ID!, $keys: [String!]!) { unsetSecrets(input: { appId: $appId, keys: $keys }) { app { name } release { version } } }",
|
||||
variables: {
|
||||
appId,
|
||||
keys
|
||||
}
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
export const FlyioSyncFns = {
|
||||
syncSecrets: async (secretSync: TFlyioSyncWithCredentials, secretMap: TSecretMap) => {
|
||||
const {
|
||||
connection,
|
||||
environment,
|
||||
destinationConfig: { appId }
|
||||
} = secretSync;
|
||||
|
||||
const { accessToken } = connection.credentials;
|
||||
|
||||
try {
|
||||
await putFlyioSecrets({ accessToken, appId, secretMap });
|
||||
} catch (error) {
|
||||
throw new SecretSyncError({
|
||||
error
|
||||
});
|
||||
}
|
||||
|
||||
if (secretSync.syncOptions.disableSecretDeletion) return;
|
||||
|
||||
const secrets = await listFlyioSecrets({ accessToken, appId });
|
||||
|
||||
const keys = secrets.filter(
|
||||
(secret) =>
|
||||
matchesSchema(secret, environment?.slug || "", secretSync.syncOptions.keySchema) && !(secret in secretMap)
|
||||
);
|
||||
|
||||
try {
|
||||
await deleteFlyioSecrets({ accessToken, appId, keys });
|
||||
} catch (error) {
|
||||
throw new SecretSyncError({
|
||||
error
|
||||
});
|
||||
}
|
||||
},
|
||||
removeSecrets: async (secretSync: TFlyioSyncWithCredentials, secretMap: TSecretMap) => {
|
||||
const {
|
||||
connection,
|
||||
destinationConfig: { appId }
|
||||
} = secretSync;
|
||||
|
||||
const { accessToken } = connection.credentials;
|
||||
|
||||
const secrets = await listFlyioSecrets({ accessToken, appId });
|
||||
|
||||
const keys = secrets.filter((secret) => secret in secretMap);
|
||||
|
||||
try {
|
||||
await deleteFlyioSecrets({ accessToken, appId, keys });
|
||||
} catch (error) {
|
||||
throw new SecretSyncError({
|
||||
error
|
||||
});
|
||||
}
|
||||
},
|
||||
getSecrets: async (secretSync: TFlyioSyncWithCredentials) => {
|
||||
throw new Error(`${SECRET_SYNC_NAME_MAP[secretSync.destination]} does not support importing secrets.`);
|
||||
}
|
||||
};
|
||||
43
backend/src/services/secret-sync/flyio/flyio-sync-schemas.ts
Normal file
43
backend/src/services/secret-sync/flyio/flyio-sync-schemas.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { SecretSyncs } from "@app/lib/api-docs";
|
||||
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||
import { SecretSync } from "@app/services/secret-sync/secret-sync-enums";
|
||||
import {
|
||||
BaseSecretSyncSchema,
|
||||
GenericCreateSecretSyncFieldsSchema,
|
||||
GenericUpdateSecretSyncFieldsSchema
|
||||
} from "@app/services/secret-sync/secret-sync-schemas";
|
||||
import { TSyncOptionsConfig } from "@app/services/secret-sync/secret-sync-types";
|
||||
|
||||
const FlyioSyncDestinationConfigSchema = z.object({
|
||||
appId: z.string().trim().min(1, "App required").describe(SecretSyncs.DESTINATION_CONFIG.FLYIO.appId)
|
||||
});
|
||||
|
||||
const FlyioSyncOptionsConfig: TSyncOptionsConfig = { canImportSecrets: false };
|
||||
|
||||
export const FlyioSyncSchema = BaseSecretSyncSchema(SecretSync.Flyio, FlyioSyncOptionsConfig).extend({
|
||||
destination: z.literal(SecretSync.Flyio),
|
||||
destinationConfig: FlyioSyncDestinationConfigSchema
|
||||
});
|
||||
|
||||
export const CreateFlyioSyncSchema = GenericCreateSecretSyncFieldsSchema(
|
||||
SecretSync.Flyio,
|
||||
FlyioSyncOptionsConfig
|
||||
).extend({
|
||||
destinationConfig: FlyioSyncDestinationConfigSchema
|
||||
});
|
||||
|
||||
export const UpdateFlyioSyncSchema = GenericUpdateSecretSyncFieldsSchema(
|
||||
SecretSync.Flyio,
|
||||
FlyioSyncOptionsConfig
|
||||
).extend({
|
||||
destinationConfig: FlyioSyncDestinationConfigSchema.optional()
|
||||
});
|
||||
|
||||
export const FlyioSyncListItemSchema = z.object({
|
||||
name: z.literal("Fly.io"),
|
||||
connection: z.literal(AppConnection.Flyio),
|
||||
destination: z.literal(SecretSync.Flyio),
|
||||
canImportSecrets: z.literal(false)
|
||||
});
|
||||
32
backend/src/services/secret-sync/flyio/flyio-sync-types.ts
Normal file
32
backend/src/services/secret-sync/flyio/flyio-sync-types.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { z } from "zod";
|
||||
|
||||
import { TFlyioConnection } from "@app/services/app-connection/flyio";
|
||||
|
||||
import { CreateFlyioSyncSchema, FlyioSyncListItemSchema, FlyioSyncSchema } from "./flyio-sync-schemas";
|
||||
|
||||
export type TFlyioSync = z.infer<typeof FlyioSyncSchema>;
|
||||
|
||||
export type TFlyioSyncInput = z.infer<typeof CreateFlyioSyncSchema>;
|
||||
|
||||
export type TFlyioSyncListItem = z.infer<typeof FlyioSyncListItemSchema>;
|
||||
|
||||
export type TFlyioSyncWithCredentials = TFlyioSync & {
|
||||
connection: TFlyioConnection;
|
||||
};
|
||||
|
||||
export type TFlyioSecret = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type TFlyioListVariables = {
|
||||
accessToken: string;
|
||||
appId: string;
|
||||
};
|
||||
|
||||
export type TPutFlyioVariable = TFlyioListVariables & {
|
||||
secretMap: { [key: string]: { value: string } };
|
||||
};
|
||||
|
||||
export type TDeleteFlyioVariable = TFlyioListVariables & {
|
||||
keys: string[];
|
||||
};
|
||||
4
backend/src/services/secret-sync/flyio/index.ts
Normal file
4
backend/src/services/secret-sync/flyio/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from "./flyio-sync-constants";
|
||||
export * from "./flyio-sync-fns";
|
||||
export * from "./flyio-sync-schemas";
|
||||
export * from "./flyio-sync-types";
|
||||
@@ -15,7 +15,8 @@ export enum SecretSync {
|
||||
HCVault = "hashicorp-vault",
|
||||
TeamCity = "teamcity",
|
||||
OCIVault = "oci-vault",
|
||||
OnePass = "1password"
|
||||
OnePass = "1password",
|
||||
Flyio = "flyio"
|
||||
}
|
||||
|
||||
export enum SecretSyncInitialSyncBehavior {
|
||||
|
||||
@@ -29,6 +29,7 @@ import { AZURE_APP_CONFIGURATION_SYNC_LIST_OPTION, azureAppConfigurationSyncFact
|
||||
import { AZURE_DEVOPS_SYNC_LIST_OPTION, azureDevOpsSyncFactory } from "./azure-devops";
|
||||
import { AZURE_KEY_VAULT_SYNC_LIST_OPTION, azureKeyVaultSyncFactory } from "./azure-key-vault";
|
||||
import { CAMUNDA_SYNC_LIST_OPTION, camundaSyncFactory } from "./camunda";
|
||||
import { FLYIO_SYNC_LIST_OPTION, FlyioSyncFns } from "./flyio";
|
||||
import { GCP_SYNC_LIST_OPTION } from "./gcp";
|
||||
import { GcpSyncFns } from "./gcp/gcp-sync-fns";
|
||||
import { HC_VAULT_SYNC_LIST_OPTION, HCVaultSyncFns } from "./hc-vault";
|
||||
@@ -57,7 +58,8 @@ const SECRET_SYNC_LIST_OPTIONS: Record<SecretSync, TSecretSyncListItem> = {
|
||||
[SecretSync.HCVault]: HC_VAULT_SYNC_LIST_OPTION,
|
||||
[SecretSync.TeamCity]: TEAMCITY_SYNC_LIST_OPTION,
|
||||
[SecretSync.OCIVault]: OCI_VAULT_SYNC_LIST_OPTION,
|
||||
[SecretSync.OnePass]: ONEPASS_SYNC_LIST_OPTION
|
||||
[SecretSync.OnePass]: ONEPASS_SYNC_LIST_OPTION,
|
||||
[SecretSync.Flyio]: FLYIO_SYNC_LIST_OPTION
|
||||
};
|
||||
|
||||
export const listSecretSyncOptions = () => {
|
||||
@@ -215,6 +217,8 @@ export const SecretSyncFns = {
|
||||
return OCIVaultSyncFns.syncSecrets(secretSync, schemaSecretMap);
|
||||
case SecretSync.OnePass:
|
||||
return OnePassSyncFns.syncSecrets(secretSync, schemaSecretMap);
|
||||
case SecretSync.Flyio:
|
||||
return FlyioSyncFns.syncSecrets(secretSync, schemaSecretMap);
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled sync destination for sync secrets fns: ${(secretSync as TSecretSyncWithCredentials).destination}`
|
||||
@@ -292,6 +296,9 @@ export const SecretSyncFns = {
|
||||
case SecretSync.OnePass:
|
||||
secretMap = await OnePassSyncFns.getSecrets(secretSync);
|
||||
break;
|
||||
case SecretSync.Flyio:
|
||||
secretMap = await FlyioSyncFns.getSecrets(secretSync);
|
||||
break;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled sync destination for get secrets fns: ${(secretSync as TSecretSyncWithCredentials).destination}`
|
||||
@@ -359,6 +366,8 @@ export const SecretSyncFns = {
|
||||
return OCIVaultSyncFns.removeSecrets(secretSync, schemaSecretMap);
|
||||
case SecretSync.OnePass:
|
||||
return OnePassSyncFns.removeSecrets(secretSync, schemaSecretMap);
|
||||
case SecretSync.Flyio:
|
||||
return FlyioSyncFns.removeSecrets(secretSync, schemaSecretMap);
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled sync destination for remove secrets fns: ${(secretSync as TSecretSyncWithCredentials).destination}`
|
||||
|
||||
@@ -18,7 +18,8 @@ export const SECRET_SYNC_NAME_MAP: Record<SecretSync, string> = {
|
||||
[SecretSync.HCVault]: "Hashicorp Vault",
|
||||
[SecretSync.TeamCity]: "TeamCity",
|
||||
[SecretSync.OCIVault]: "OCI Vault",
|
||||
[SecretSync.OnePass]: "1Password"
|
||||
[SecretSync.OnePass]: "1Password",
|
||||
[SecretSync.Flyio]: "Fly.io"
|
||||
};
|
||||
|
||||
export const SECRET_SYNC_CONNECTION_MAP: Record<SecretSync, AppConnection> = {
|
||||
@@ -38,7 +39,8 @@ export const SECRET_SYNC_CONNECTION_MAP: Record<SecretSync, AppConnection> = {
|
||||
[SecretSync.HCVault]: AppConnection.HCVault,
|
||||
[SecretSync.TeamCity]: AppConnection.TeamCity,
|
||||
[SecretSync.OCIVault]: AppConnection.OCI,
|
||||
[SecretSync.OnePass]: AppConnection.OnePass
|
||||
[SecretSync.OnePass]: AppConnection.OnePass,
|
||||
[SecretSync.Flyio]: AppConnection.Flyio
|
||||
};
|
||||
|
||||
export const SECRET_SYNC_PLAN_MAP: Record<SecretSync, SecretSyncPlanType> = {
|
||||
@@ -58,5 +60,6 @@ export const SECRET_SYNC_PLAN_MAP: Record<SecretSync, SecretSyncPlanType> = {
|
||||
[SecretSync.HCVault]: SecretSyncPlanType.Regular,
|
||||
[SecretSync.TeamCity]: SecretSyncPlanType.Regular,
|
||||
[SecretSync.OCIVault]: SecretSyncPlanType.Enterprise,
|
||||
[SecretSync.OnePass]: SecretSyncPlanType.Regular
|
||||
[SecretSync.OnePass]: SecretSyncPlanType.Regular,
|
||||
[SecretSync.Flyio]: SecretSyncPlanType.Regular
|
||||
};
|
||||
|
||||
@@ -72,6 +72,7 @@ import {
|
||||
TAzureKeyVaultSyncListItem,
|
||||
TAzureKeyVaultSyncWithCredentials
|
||||
} from "./azure-key-vault";
|
||||
import { TFlyioSync, TFlyioSyncInput, TFlyioSyncListItem, TFlyioSyncWithCredentials } from "./flyio/flyio-sync-types";
|
||||
import { TGcpSync, TGcpSyncInput, TGcpSyncListItem, TGcpSyncWithCredentials } from "./gcp";
|
||||
import {
|
||||
THCVaultSync,
|
||||
@@ -116,7 +117,8 @@ export type TSecretSync =
|
||||
| THCVaultSync
|
||||
| TTeamCitySync
|
||||
| TOCIVaultSync
|
||||
| TOnePassSync;
|
||||
| TOnePassSync
|
||||
| TFlyioSync;
|
||||
|
||||
export type TSecretSyncWithCredentials =
|
||||
| TAwsParameterStoreSyncWithCredentials
|
||||
@@ -135,7 +137,8 @@ export type TSecretSyncWithCredentials =
|
||||
| THCVaultSyncWithCredentials
|
||||
| TTeamCitySyncWithCredentials
|
||||
| TOCIVaultSyncWithCredentials
|
||||
| TOnePassSyncWithCredentials;
|
||||
| TOnePassSyncWithCredentials
|
||||
| TFlyioSyncWithCredentials;
|
||||
|
||||
export type TSecretSyncInput =
|
||||
| TAwsParameterStoreSyncInput
|
||||
@@ -154,7 +157,8 @@ export type TSecretSyncInput =
|
||||
| THCVaultSyncInput
|
||||
| TTeamCitySyncInput
|
||||
| TOCIVaultSyncInput
|
||||
| TOnePassSyncInput;
|
||||
| TOnePassSyncInput
|
||||
| TFlyioSyncInput;
|
||||
|
||||
export type TSecretSyncListItem =
|
||||
| TAwsParameterStoreSyncListItem
|
||||
@@ -173,7 +177,8 @@ export type TSecretSyncListItem =
|
||||
| THCVaultSyncListItem
|
||||
| TTeamCitySyncListItem
|
||||
| TOCIVaultSyncListItem
|
||||
| TOnePassSyncListItem;
|
||||
| TOnePassSyncListItem
|
||||
| TFlyioSyncListItem;
|
||||
|
||||
export type TSyncOptionsConfig = {
|
||||
canImportSecrets: boolean;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
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 { TFlyioApp, useFlyioConnectionListApps } from "@app/hooks/api/appConnections/flyio";
|
||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||
|
||||
import { TSecretSyncForm } from "../schemas";
|
||||
|
||||
export const FlyioSyncFields = () => {
|
||||
const { control, setValue } = useFormContext<
|
||||
TSecretSyncForm & { destination: SecretSync.Flyio }
|
||||
>();
|
||||
|
||||
const connectionId = useWatch({ name: "connection.id", control });
|
||||
|
||||
const { data: apps, isLoading: isAppsLoading } = useFlyioConnectionListApps(connectionId, {
|
||||
enabled: Boolean(connectionId)
|
||||
});
|
||||
|
||||
return (
|
||||
<>
|
||||
<SecretSyncConnectionField
|
||||
onChange={() => {
|
||||
setValue("destinationConfig.appId", "");
|
||||
}}
|
||||
/>
|
||||
|
||||
<Controller
|
||||
name="destinationConfig.appId"
|
||||
control={control}
|
||||
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||
<FormControl isError={Boolean(error)} errorText={error?.message} label="App">
|
||||
<FilterableSelect
|
||||
menuPlacement="top"
|
||||
isLoading={isAppsLoading && Boolean(connectionId)}
|
||||
isDisabled={!connectionId}
|
||||
value={apps?.find((v) => v.id === value) ?? null}
|
||||
onChange={(option) => onChange((option as SingleValue<TFlyioApp>)?.id ?? null)}
|
||||
options={apps}
|
||||
placeholder="Select an app..."
|
||||
getOptionLabel={(option) => option.name}
|
||||
getOptionValue={(option) => option.id}
|
||||
/>
|
||||
</FormControl>
|
||||
)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -11,6 +11,7 @@ import { AzureDevOpsSyncFields } from "./AzureDevOpsSyncFields";
|
||||
import { AzureKeyVaultSyncFields } from "./AzureKeyVaultSyncFields";
|
||||
import { CamundaSyncFields } from "./CamundaSyncFields";
|
||||
import { DatabricksSyncFields } from "./DatabricksSyncFields";
|
||||
import { FlyioSyncFields } from "./FlyioSyncFields";
|
||||
import { GcpSyncFields } from "./GcpSyncFields";
|
||||
import { GitHubSyncFields } from "./GitHubSyncFields";
|
||||
import { HCVaultSyncFields } from "./HCVaultSyncFields";
|
||||
@@ -61,6 +62,8 @@ export const SecretSyncDestinationFields = () => {
|
||||
return <OCIVaultSyncFields />;
|
||||
case SecretSync.OnePass:
|
||||
return <OnePassSyncFields />;
|
||||
case SecretSync.Flyio:
|
||||
return <FlyioSyncFields />;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Config Field: ${destination}`);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ export const SecretSyncOptionsFields = ({ hideInitialSync }: Props) => {
|
||||
case SecretSync.TeamCity:
|
||||
case SecretSync.OnePass:
|
||||
case SecretSync.OCIVault:
|
||||
case SecretSync.Flyio:
|
||||
AdditionalSyncOptionsFieldsComponent = null;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
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 FlyioSyncReviewFields = () => {
|
||||
const { watch } = useFormContext<TSecretSyncForm & { destination: SecretSync.Flyio }>();
|
||||
const appId = watch("destinationConfig.appId");
|
||||
|
||||
return <GenericFieldLabel label="App ID">{appId}</GenericFieldLabel>;
|
||||
};
|
||||
@@ -20,6 +20,7 @@ import { AzureDevOpsSyncReviewFields } from "./AzureDevOpsSyncReviewFields";
|
||||
import { AzureKeyVaultSyncReviewFields } from "./AzureKeyVaultSyncReviewFields";
|
||||
import { CamundaSyncReviewFields } from "./CamundaSyncReviewFields";
|
||||
import { DatabricksSyncReviewFields } from "./DatabricksSyncReviewFields";
|
||||
import { FlyioSyncReviewFields } from "./FlyioSyncReviewFields";
|
||||
import { GcpSyncReviewFields } from "./GcpSyncReviewFields";
|
||||
import { GitHubSyncReviewFields } from "./GitHubSyncReviewFields";
|
||||
import { HCVaultSyncReviewFields } from "./HCVaultSyncReviewFields";
|
||||
@@ -104,6 +105,9 @@ export const SecretSyncReviewFields = () => {
|
||||
case SecretSync.OnePass:
|
||||
DestinationFieldsComponent = <OnePassSyncReviewFields />;
|
||||
break;
|
||||
case SecretSync.Flyio:
|
||||
DestinationFieldsComponent = <FlyioSyncReviewFields />;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Review Fields: ${destination}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
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 FlyioSyncDestinationSchema = BaseSecretSyncSchema().merge(
|
||||
z.object({
|
||||
destination: z.literal(SecretSync.Flyio),
|
||||
destinationConfig: z.object({
|
||||
appId: z.string().trim().min(1, "App ID required")
|
||||
})
|
||||
})
|
||||
);
|
||||
@@ -8,6 +8,7 @@ import { AzureDevOpsSyncDestinationSchema } from "./azure-devops-sync-destinatio
|
||||
import { AzureKeyVaultSyncDestinationSchema } from "./azure-key-vault-sync-destination-schema";
|
||||
import { CamundaSyncDestinationSchema } from "./camunda-sync-destination-schema";
|
||||
import { DatabricksSyncDestinationSchema } from "./databricks-sync-destination-schema";
|
||||
import { FlyioSyncDestinationSchema } from "./flyio-sync-destination-schema";
|
||||
import { GcpSyncDestinationSchema } from "./gcp-sync-destination-schema";
|
||||
import { GitHubSyncDestinationSchema } from "./github-sync-destination-schema";
|
||||
import { HCVaultSyncDestinationSchema } from "./hc-vault-sync-destination-schema";
|
||||
@@ -35,7 +36,8 @@ const SecretSyncUnionSchema = z.discriminatedUnion("destination", [
|
||||
HCVaultSyncDestinationSchema,
|
||||
TeamCitySyncDestinationSchema,
|
||||
OCIVaultSyncDestinationSchema,
|
||||
OnePassSyncDestinationSchema
|
||||
OnePassSyncDestinationSchema,
|
||||
FlyioSyncDestinationSchema
|
||||
]);
|
||||
|
||||
export const SecretSyncFormSchema = SecretSyncUnionSchema;
|
||||
|
||||
@@ -60,6 +60,10 @@ export const SECRET_SYNC_MAP: Record<SecretSync, { name: string; image: string }
|
||||
[SecretSync.OnePass]: {
|
||||
name: "1Password",
|
||||
image: "1Password.png"
|
||||
},
|
||||
[SecretSync.Flyio]: {
|
||||
name: "Fly.io",
|
||||
image: "Flyio.svg"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -80,7 +84,8 @@ export const SECRET_SYNC_CONNECTION_MAP: Record<SecretSync, AppConnection> = {
|
||||
[SecretSync.HCVault]: AppConnection.HCVault,
|
||||
[SecretSync.TeamCity]: AppConnection.TeamCity,
|
||||
[SecretSync.OCIVault]: AppConnection.OCI,
|
||||
[SecretSync.OnePass]: AppConnection.OnePass
|
||||
[SecretSync.OnePass]: AppConnection.OnePass,
|
||||
[SecretSync.Flyio]: AppConnection.Flyio
|
||||
};
|
||||
|
||||
export const SECRET_SYNC_INITIAL_SYNC_BEHAVIOR_MAP: Record<
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// TODO(andrey): apps
|
||||
export type TFlyioApp = {
|
||||
id: string;
|
||||
name: string;
|
||||
|
||||
@@ -15,7 +15,8 @@ export enum SecretSync {
|
||||
HCVault = "hashicorp-vault",
|
||||
TeamCity = "teamcity",
|
||||
OCIVault = "oci-vault",
|
||||
OnePass = "1password"
|
||||
OnePass = "1password",
|
||||
Flyio = "flyio"
|
||||
}
|
||||
|
||||
export enum SecretSyncStatus {
|
||||
|
||||
15
frontend/src/hooks/api/secretSyncs/types/flyio-sync.ts
Normal file
15
frontend/src/hooks/api/secretSyncs/types/flyio-sync.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
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 TFlyioSync = TRootSecretSync & {
|
||||
destination: SecretSync.Flyio;
|
||||
destinationConfig: {
|
||||
appId: string;
|
||||
};
|
||||
connection: {
|
||||
app: AppConnection.Flyio;
|
||||
name: string;
|
||||
id: string;
|
||||
};
|
||||
};
|
||||
@@ -9,6 +9,7 @@ import { TAzureDevOpsSync } from "./azure-devops-sync";
|
||||
import { TAzureKeyVaultSync } from "./azure-key-vault-sync";
|
||||
import { TCamundaSync } from "./camunda-sync";
|
||||
import { TDatabricksSync } from "./databricks-sync";
|
||||
import { TFlyioSync } from "./flyio-sync";
|
||||
import { TGcpSync } from "./gcp-sync";
|
||||
import { TGitHubSync } from "./github-sync";
|
||||
import { THCVaultSync } from "./hc-vault-sync";
|
||||
@@ -43,7 +44,8 @@ export type TSecretSync =
|
||||
| THCVaultSync
|
||||
| TTeamCitySync
|
||||
| TOCIVaultSync
|
||||
| TOnePassSync;
|
||||
| TOnePassSync
|
||||
| TFlyioSync;
|
||||
|
||||
export type TListSecretSyncs = { secretSyncs: TSecretSync[] };
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { TFlyioSync } from "@app/hooks/api/secretSyncs/types/flyio-sync";
|
||||
|
||||
import { getSecretSyncDestinationColValues } from "../helpers";
|
||||
import { SecretSyncTableCell } from "../SecretSyncTableCell";
|
||||
|
||||
type Props = {
|
||||
secretSync: TFlyioSync;
|
||||
};
|
||||
|
||||
export const FlyioSyncDestinationCol = ({ secretSync }: Props) => {
|
||||
const { primaryText, secondaryText } = getSecretSyncDestinationColValues(secretSync);
|
||||
|
||||
return <SecretSyncTableCell primaryText={primaryText} secondaryText={secondaryText} />;
|
||||
};
|
||||
@@ -8,6 +8,7 @@ import { AzureDevOpsSyncDestinationCol } from "./AzureDevOpsSyncDestinationCol";
|
||||
import { AzureKeyVaultDestinationSyncCol } from "./AzureKeyVaultDestinationSyncCol";
|
||||
import { CamundaSyncDestinationCol } from "./CamundaSyncDestinationCol";
|
||||
import { DatabricksSyncDestinationCol } from "./DatabricksSyncDestinationCol";
|
||||
import { FlyioSyncDestinationCol } from "./FlyioSyncDestinationCol";
|
||||
import { GcpSyncDestinationCol } from "./GcpSyncDestinationCol";
|
||||
import { GitHubSyncDestinationCol } from "./GitHubSyncDestinationCol";
|
||||
import { HCVaultSyncDestinationCol } from "./HCVaultSyncDestinationCol";
|
||||
@@ -58,6 +59,8 @@ export const SecretSyncDestinationCol = ({ secretSync }: Props) => {
|
||||
return <OnePassSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.AzureDevOps:
|
||||
return <AzureDevOpsSyncDestinationCol secretSync={secretSync} />;
|
||||
case SecretSync.Flyio:
|
||||
return <FlyioSyncDestinationCol secretSync={secretSync} />;
|
||||
default:
|
||||
throw new Error(
|
||||
`Unhandled Secret Sync Destination Col: ${(secretSync as TSecretSync).destination}`
|
||||
|
||||
@@ -116,6 +116,10 @@ export const getSecretSyncDestinationColValues = (secretSync: TSecretSync) => {
|
||||
primaryText = destinationConfig.devopsProjectName;
|
||||
secondaryText = destinationConfig.devopsProjectId;
|
||||
break;
|
||||
case SecretSync.Flyio:
|
||||
primaryText = destinationConfig.appId;
|
||||
secondaryText = "App ID";
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Col Values ${destination}`);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import { GenericFieldLabel } from "@app/components/secret-syncs";
|
||||
import { TFlyioSync } from "@app/hooks/api/secretSyncs/types/flyio-sync";
|
||||
|
||||
type Props = {
|
||||
secretSync: TFlyioSync;
|
||||
};
|
||||
|
||||
export const FlyioSyncDestinationSection = ({ secretSync }: Props) => {
|
||||
const {
|
||||
destinationConfig: { appId }
|
||||
} = secretSync;
|
||||
|
||||
return <GenericFieldLabel label="App ID">{appId}</GenericFieldLabel>;
|
||||
};
|
||||
@@ -18,6 +18,7 @@ import { AzureDevOpsSyncDestinationSection } from "./AzureDevOpsSyncDestinationS
|
||||
import { AzureKeyVaultSyncDestinationSection } from "./AzureKeyVaultSyncDestinationSection";
|
||||
import { CamundaSyncDestinationSection } from "./CamundaSyncDestinationSection";
|
||||
import { DatabricksSyncDestinationSection } from "./DatabricksSyncDestinationSection";
|
||||
import { FlyioSyncDestinationSection } from "./FlyioSyncDestinationSection";
|
||||
import { GcpSyncDestinationSection } from "./GcpSyncDestinationSection";
|
||||
import { GitHubSyncDestinationSection } from "./GitHubSyncDestinationSection";
|
||||
import { HCVaultSyncDestinationSection } from "./HCVaultSyncDestinationSection";
|
||||
@@ -93,6 +94,9 @@ export const SecretSyncDestinationSection = ({ secretSync, onEditDestination }:
|
||||
case SecretSync.AzureDevOps:
|
||||
DestinationComponents = <AzureDevOpsSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
case SecretSync.Flyio:
|
||||
DestinationComponents = <FlyioSyncDestinationSection secretSync={secretSync} />;
|
||||
break;
|
||||
default:
|
||||
throw new Error(`Unhandled Destination Section components: ${destination}`);
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ export const SecretSyncOptionsSection = ({ secretSync, onEditOptions }: Props) =
|
||||
case SecretSync.TeamCity:
|
||||
case SecretSync.OCIVault:
|
||||
case SecretSync.OnePass:
|
||||
case SecretSync.Flyio:
|
||||
AdditionalSyncOptionsComponent = null;
|
||||
break;
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user