mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 22:27:22 +00:00
feat: added cloudflare app connection
This commit is contained in:
@@ -79,6 +79,10 @@ import {
|
|||||||
WindmillConnectionListItemSchema
|
WindmillConnectionListItemSchema
|
||||||
} from "@app/services/app-connection/windmill";
|
} from "@app/services/app-connection/windmill";
|
||||||
import { AuthMode } from "@app/services/auth/auth-type";
|
import { AuthMode } from "@app/services/auth/auth-type";
|
||||||
|
import {
|
||||||
|
CloudflareConnectionListItemSchema,
|
||||||
|
SanitizedCloudflareConnectionSchema
|
||||||
|
} from "@app/services/app-connection/cloudflare/cloudflare-connection-schema";
|
||||||
|
|
||||||
// can't use discriminated due to multiple schemas for certain apps
|
// can't use discriminated due to multiple schemas for certain apps
|
||||||
const SanitizedAppConnectionSchema = z.union([
|
const SanitizedAppConnectionSchema = z.union([
|
||||||
@@ -107,7 +111,8 @@ const SanitizedAppConnectionSchema = z.union([
|
|||||||
...SanitizedOracleDBConnectionSchema.options,
|
...SanitizedOracleDBConnectionSchema.options,
|
||||||
...SanitizedOnePassConnectionSchema.options,
|
...SanitizedOnePassConnectionSchema.options,
|
||||||
...SanitizedRenderConnectionSchema.options,
|
...SanitizedRenderConnectionSchema.options,
|
||||||
...SanitizedFlyioConnectionSchema.options
|
...SanitizedFlyioConnectionSchema.options,
|
||||||
|
...SanitizedCloudflareConnectionSchema.options
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const AppConnectionOptionsSchema = z.discriminatedUnion("app", [
|
const AppConnectionOptionsSchema = z.discriminatedUnion("app", [
|
||||||
@@ -136,7 +141,8 @@ const AppConnectionOptionsSchema = z.discriminatedUnion("app", [
|
|||||||
OracleDBConnectionListItemSchema,
|
OracleDBConnectionListItemSchema,
|
||||||
OnePassConnectionListItemSchema,
|
OnePassConnectionListItemSchema,
|
||||||
RenderConnectionListItemSchema,
|
RenderConnectionListItemSchema,
|
||||||
FlyioConnectionListItemSchema
|
FlyioConnectionListItemSchema,
|
||||||
|
CloudflareConnectionListItemSchema
|
||||||
]);
|
]);
|
||||||
|
|
||||||
export const registerAppConnectionRouter = async (server: FastifyZodProvider) => {
|
export const registerAppConnectionRouter = async (server: FastifyZodProvider) => {
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||||
|
|
||||||
|
import { registerAppConnectionEndpoints } from "./app-connection-endpoints";
|
||||||
|
import {
|
||||||
|
SanitizedCloudflareConnectionSchema,
|
||||||
|
CreateCloudflareConnectionSchema,
|
||||||
|
UpdateCloudflareConnectionSchema
|
||||||
|
} from "@app/services/app-connection/cloudflare/cloudflare-connection-schema";
|
||||||
|
|
||||||
|
export const registerCloudflareConnectionRouter = async (server: FastifyZodProvider) => {
|
||||||
|
registerAppConnectionEndpoints({
|
||||||
|
app: AppConnection.Cloudflare,
|
||||||
|
server,
|
||||||
|
sanitizedResponseSchema: SanitizedCloudflareConnectionSchema,
|
||||||
|
createSchema: CreateCloudflareConnectionSchema,
|
||||||
|
updateSchema: UpdateCloudflareConnectionSchema
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -26,6 +26,7 @@ import { registerTeamCityConnectionRouter } from "./teamcity-connection-router";
|
|||||||
import { registerTerraformCloudConnectionRouter } from "./terraform-cloud-router";
|
import { registerTerraformCloudConnectionRouter } from "./terraform-cloud-router";
|
||||||
import { registerVercelConnectionRouter } from "./vercel-connection-router";
|
import { registerVercelConnectionRouter } from "./vercel-connection-router";
|
||||||
import { registerWindmillConnectionRouter } from "./windmill-connection-router";
|
import { registerWindmillConnectionRouter } from "./windmill-connection-router";
|
||||||
|
import { registerCloudflareConnectionRouter } from "./cloudflare-connection-router";
|
||||||
|
|
||||||
export * from "./app-connection-router";
|
export * from "./app-connection-router";
|
||||||
|
|
||||||
@@ -56,5 +57,6 @@ export const APP_CONNECTION_REGISTER_ROUTER_MAP: Record<AppConnection, (server:
|
|||||||
[AppConnection.OracleDB]: registerOracleDBConnectionRouter,
|
[AppConnection.OracleDB]: registerOracleDBConnectionRouter,
|
||||||
[AppConnection.OnePass]: registerOnePassConnectionRouter,
|
[AppConnection.OnePass]: registerOnePassConnectionRouter,
|
||||||
[AppConnection.Render]: registerRenderConnectionRouter,
|
[AppConnection.Render]: registerRenderConnectionRouter,
|
||||||
[AppConnection.Flyio]: registerFlyioConnectionRouter
|
[AppConnection.Flyio]: registerFlyioConnectionRouter,
|
||||||
|
[AppConnection.Cloudflare]: registerCloudflareConnectionRouter
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -24,7 +24,8 @@ export enum AppConnection {
|
|||||||
OracleDB = "oracledb",
|
OracleDB = "oracledb",
|
||||||
OnePass = "1password",
|
OnePass = "1password",
|
||||||
Render = "render",
|
Render = "render",
|
||||||
Flyio = "flyio"
|
Flyio = "flyio",
|
||||||
|
Cloudflare = "cloudflare"
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AWSRegion {
|
export enum AWSRegion {
|
||||||
|
|||||||
@@ -98,6 +98,11 @@ import {
|
|||||||
validateWindmillConnectionCredentials,
|
validateWindmillConnectionCredentials,
|
||||||
WindmillConnectionMethod
|
WindmillConnectionMethod
|
||||||
} from "./windmill";
|
} from "./windmill";
|
||||||
|
import {
|
||||||
|
getCloudflareConnectionListItem,
|
||||||
|
validateCloudflareConnectionCredentials
|
||||||
|
} from "./cloudflare/cloudflare-connection-fns";
|
||||||
|
import { CloudflareConnectionMethod } from "./cloudflare/cloudflare-connection-enum";
|
||||||
|
|
||||||
export const listAppConnectionOptions = () => {
|
export const listAppConnectionOptions = () => {
|
||||||
return [
|
return [
|
||||||
@@ -126,7 +131,8 @@ export const listAppConnectionOptions = () => {
|
|||||||
getOracleDBConnectionListItem(),
|
getOracleDBConnectionListItem(),
|
||||||
getOnePassConnectionListItem(),
|
getOnePassConnectionListItem(),
|
||||||
getRenderConnectionListItem(),
|
getRenderConnectionListItem(),
|
||||||
getFlyioConnectionListItem()
|
getFlyioConnectionListItem(),
|
||||||
|
getCloudflareConnectionListItem()
|
||||||
].sort((a, b) => a.name.localeCompare(b.name));
|
].sort((a, b) => a.name.localeCompare(b.name));
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -203,7 +209,8 @@ export const validateAppConnectionCredentials = async (
|
|||||||
[AppConnection.OracleDB]: validateSqlConnectionCredentials as TAppConnectionCredentialsValidator,
|
[AppConnection.OracleDB]: validateSqlConnectionCredentials as TAppConnectionCredentialsValidator,
|
||||||
[AppConnection.OnePass]: validateOnePassConnectionCredentials as TAppConnectionCredentialsValidator,
|
[AppConnection.OnePass]: validateOnePassConnectionCredentials as TAppConnectionCredentialsValidator,
|
||||||
[AppConnection.Render]: validateRenderConnectionCredentials as TAppConnectionCredentialsValidator,
|
[AppConnection.Render]: validateRenderConnectionCredentials as TAppConnectionCredentialsValidator,
|
||||||
[AppConnection.Flyio]: validateFlyioConnectionCredentials as TAppConnectionCredentialsValidator
|
[AppConnection.Flyio]: validateFlyioConnectionCredentials as TAppConnectionCredentialsValidator,
|
||||||
|
[AppConnection.Cloudflare]: validateCloudflareConnectionCredentials as TAppConnectionCredentialsValidator
|
||||||
};
|
};
|
||||||
|
|
||||||
return VALIDATE_APP_CONNECTION_CREDENTIALS_MAP[appConnection.app](appConnection);
|
return VALIDATE_APP_CONNECTION_CREDENTIALS_MAP[appConnection.app](appConnection);
|
||||||
@@ -235,6 +242,7 @@ export const getAppConnectionMethodName = (method: TAppConnection["method"]) =>
|
|||||||
case TerraformCloudConnectionMethod.ApiToken:
|
case TerraformCloudConnectionMethod.ApiToken:
|
||||||
case VercelConnectionMethod.ApiToken:
|
case VercelConnectionMethod.ApiToken:
|
||||||
case OnePassConnectionMethod.ApiToken:
|
case OnePassConnectionMethod.ApiToken:
|
||||||
|
case CloudflareConnectionMethod.APIToken:
|
||||||
return "API Token";
|
return "API Token";
|
||||||
case PostgresConnectionMethod.UsernameAndPassword:
|
case PostgresConnectionMethod.UsernameAndPassword:
|
||||||
case MsSqlConnectionMethod.UsernameAndPassword:
|
case MsSqlConnectionMethod.UsernameAndPassword:
|
||||||
@@ -311,7 +319,8 @@ export const TRANSITION_CONNECTION_CREDENTIALS_TO_PLATFORM: Record<
|
|||||||
[AppConnection.OracleDB]: transferSqlConnectionCredentialsToPlatform as TAppConnectionTransitionCredentialsToPlatform,
|
[AppConnection.OracleDB]: transferSqlConnectionCredentialsToPlatform as TAppConnectionTransitionCredentialsToPlatform,
|
||||||
[AppConnection.OnePass]: platformManagedCredentialsNotSupported,
|
[AppConnection.OnePass]: platformManagedCredentialsNotSupported,
|
||||||
[AppConnection.Render]: platformManagedCredentialsNotSupported,
|
[AppConnection.Render]: platformManagedCredentialsNotSupported,
|
||||||
[AppConnection.Flyio]: platformManagedCredentialsNotSupported
|
[AppConnection.Flyio]: platformManagedCredentialsNotSupported,
|
||||||
|
[AppConnection.Cloudflare]: platformManagedCredentialsNotSupported
|
||||||
};
|
};
|
||||||
|
|
||||||
export const enterpriseAppCheck = async (
|
export const enterpriseAppCheck = async (
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ export const APP_CONNECTION_NAME_MAP: Record<AppConnection, string> = {
|
|||||||
[AppConnection.OracleDB]: "OracleDB",
|
[AppConnection.OracleDB]: "OracleDB",
|
||||||
[AppConnection.OnePass]: "1Password",
|
[AppConnection.OnePass]: "1Password",
|
||||||
[AppConnection.Render]: "Render",
|
[AppConnection.Render]: "Render",
|
||||||
[AppConnection.Flyio]: "Fly.io"
|
[AppConnection.Flyio]: "Fly.io",
|
||||||
|
[AppConnection.Cloudflare]: "Cloudflare"
|
||||||
};
|
};
|
||||||
|
|
||||||
export const APP_CONNECTION_PLAN_MAP: Record<AppConnection, AppConnectionPlanType> = {
|
export const APP_CONNECTION_PLAN_MAP: Record<AppConnection, AppConnectionPlanType> = {
|
||||||
@@ -55,5 +56,6 @@ export const APP_CONNECTION_PLAN_MAP: Record<AppConnection, AppConnectionPlanTyp
|
|||||||
[AppConnection.OnePass]: AppConnectionPlanType.Regular,
|
[AppConnection.OnePass]: AppConnectionPlanType.Regular,
|
||||||
[AppConnection.MySql]: AppConnectionPlanType.Regular,
|
[AppConnection.MySql]: AppConnectionPlanType.Regular,
|
||||||
[AppConnection.Render]: AppConnectionPlanType.Regular,
|
[AppConnection.Render]: AppConnectionPlanType.Regular,
|
||||||
[AppConnection.Flyio]: AppConnectionPlanType.Regular
|
[AppConnection.Flyio]: AppConnectionPlanType.Regular,
|
||||||
|
[AppConnection.Cloudflare]: AppConnectionPlanType.Regular
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import { azureDevOpsConnectionService } from "./azure-devops/azure-devops-servic
|
|||||||
import { ValidateAzureKeyVaultConnectionCredentialsSchema } from "./azure-key-vault";
|
import { ValidateAzureKeyVaultConnectionCredentialsSchema } from "./azure-key-vault";
|
||||||
import { ValidateCamundaConnectionCredentialsSchema } from "./camunda";
|
import { ValidateCamundaConnectionCredentialsSchema } from "./camunda";
|
||||||
import { camundaConnectionService } from "./camunda/camunda-connection-service";
|
import { camundaConnectionService } from "./camunda/camunda-connection-service";
|
||||||
|
import { ValidateCloudflareConnectionCredentialsSchema } from "./cloudflare/cloudflare-connection-schema";
|
||||||
import { ValidateDatabricksConnectionCredentialsSchema } from "./databricks";
|
import { ValidateDatabricksConnectionCredentialsSchema } from "./databricks";
|
||||||
import { databricksConnectionService } from "./databricks/databricks-connection-service";
|
import { databricksConnectionService } from "./databricks/databricks-connection-service";
|
||||||
import { ValidateFlyioConnectionCredentialsSchema } from "./flyio";
|
import { ValidateFlyioConnectionCredentialsSchema } from "./flyio";
|
||||||
@@ -110,7 +111,8 @@ const VALIDATE_APP_CONNECTION_CREDENTIALS_MAP: Record<AppConnection, TValidateAp
|
|||||||
[AppConnection.OracleDB]: ValidateOracleDBConnectionCredentialsSchema,
|
[AppConnection.OracleDB]: ValidateOracleDBConnectionCredentialsSchema,
|
||||||
[AppConnection.OnePass]: ValidateOnePassConnectionCredentialsSchema,
|
[AppConnection.OnePass]: ValidateOnePassConnectionCredentialsSchema,
|
||||||
[AppConnection.Render]: ValidateRenderConnectionCredentialsSchema,
|
[AppConnection.Render]: ValidateRenderConnectionCredentialsSchema,
|
||||||
[AppConnection.Flyio]: ValidateFlyioConnectionCredentialsSchema
|
[AppConnection.Flyio]: ValidateFlyioConnectionCredentialsSchema,
|
||||||
|
[AppConnection.Cloudflare]: ValidateCloudflareConnectionCredentialsSchema
|
||||||
};
|
};
|
||||||
|
|
||||||
export const appConnectionServiceFactory = ({
|
export const appConnectionServiceFactory = ({
|
||||||
|
|||||||
@@ -147,6 +147,12 @@ import {
|
|||||||
TWindmillConnectionConfig,
|
TWindmillConnectionConfig,
|
||||||
TWindmillConnectionInput
|
TWindmillConnectionInput
|
||||||
} from "./windmill";
|
} from "./windmill";
|
||||||
|
import {
|
||||||
|
TCloudflareConnection,
|
||||||
|
TCloudflareConnectionConfig,
|
||||||
|
TCloudflareConnectionInput,
|
||||||
|
TValidateCloudflareConnectionCredentialsSchema
|
||||||
|
} from "./cloudflare/cloudflare-connection-types";
|
||||||
|
|
||||||
export type TAppConnection = { id: string } & (
|
export type TAppConnection = { id: string } & (
|
||||||
| TAwsConnection
|
| TAwsConnection
|
||||||
@@ -175,6 +181,7 @@ export type TAppConnection = { id: string } & (
|
|||||||
| TOnePassConnection
|
| TOnePassConnection
|
||||||
| TRenderConnection
|
| TRenderConnection
|
||||||
| TFlyioConnection
|
| TFlyioConnection
|
||||||
|
| TCloudflareConnection
|
||||||
);
|
);
|
||||||
|
|
||||||
export type TAppConnectionRaw = NonNullable<Awaited<ReturnType<TAppConnectionDALFactory["findById"]>>>;
|
export type TAppConnectionRaw = NonNullable<Awaited<ReturnType<TAppConnectionDALFactory["findById"]>>>;
|
||||||
@@ -208,6 +215,7 @@ export type TAppConnectionInput = { id: string } & (
|
|||||||
| TOnePassConnectionInput
|
| TOnePassConnectionInput
|
||||||
| TRenderConnectionInput
|
| TRenderConnectionInput
|
||||||
| TFlyioConnectionInput
|
| TFlyioConnectionInput
|
||||||
|
| TCloudflareConnectionInput
|
||||||
);
|
);
|
||||||
|
|
||||||
export type TSqlConnectionInput =
|
export type TSqlConnectionInput =
|
||||||
@@ -248,7 +256,8 @@ export type TAppConnectionConfig =
|
|||||||
| TOCIConnectionConfig
|
| TOCIConnectionConfig
|
||||||
| TOnePassConnectionConfig
|
| TOnePassConnectionConfig
|
||||||
| TRenderConnectionConfig
|
| TRenderConnectionConfig
|
||||||
| TFlyioConnectionConfig;
|
| TFlyioConnectionConfig
|
||||||
|
| TCloudflareConnectionConfig;
|
||||||
|
|
||||||
export type TValidateAppConnectionCredentialsSchema =
|
export type TValidateAppConnectionCredentialsSchema =
|
||||||
| TValidateAwsConnectionCredentialsSchema
|
| TValidateAwsConnectionCredentialsSchema
|
||||||
@@ -276,7 +285,8 @@ export type TValidateAppConnectionCredentialsSchema =
|
|||||||
| TValidateOracleDBConnectionCredentialsSchema
|
| TValidateOracleDBConnectionCredentialsSchema
|
||||||
| TValidateOnePassConnectionCredentialsSchema
|
| TValidateOnePassConnectionCredentialsSchema
|
||||||
| TValidateRenderConnectionCredentialsSchema
|
| TValidateRenderConnectionCredentialsSchema
|
||||||
| TValidateFlyioConnectionCredentialsSchema;
|
| TValidateFlyioConnectionCredentialsSchema
|
||||||
|
| TValidateCloudflareConnectionCredentialsSchema;
|
||||||
|
|
||||||
export type TListAwsConnectionKmsKeys = {
|
export type TListAwsConnectionKmsKeys = {
|
||||||
connectionId: string;
|
connectionId: string;
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
export enum CloudflareConnectionMethod {
|
||||||
|
APIToken = "api-token"
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
import { AxiosError } from "axios";
|
||||||
|
|
||||||
|
import { request } from "@app/lib/config/request";
|
||||||
|
import { BadRequestError } from "@app/lib/errors";
|
||||||
|
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||||
|
|
||||||
|
import { CloudflareConnectionMethod } from "./cloudflare-connection-enum";
|
||||||
|
import { TCloudflareConnectionConfig } from "./cloudflare-connection-types";
|
||||||
|
import { IntegrationUrls } from "@app/services/integration-auth/integration-list";
|
||||||
|
|
||||||
|
export const getCloudflareConnectionListItem = () => {
|
||||||
|
return {
|
||||||
|
name: "Cloudflare" as const,
|
||||||
|
app: AppConnection.Cloudflare as const,
|
||||||
|
methods: Object.values(CloudflareConnectionMethod) as [CloudflareConnectionMethod.APIToken]
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const validateCloudflareConnectionCredentials = async (config: TCloudflareConnectionConfig) => {
|
||||||
|
const { apiToken, accountId } = config.credentials;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const resp = await request.get(`${IntegrationUrls.CLOUDFLARE_API_URL}/client/v4/accounts/${accountId}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${apiToken}`,
|
||||||
|
Accept: "application/json"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (resp.data.data === null) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: "Unable to validate connection: Invalid API token provided."
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} catch (error: unknown) {
|
||||||
|
if (error instanceof AxiosError) {
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: `Failed to validate credentials: ${error.response?.data?.errors?.[0]?.message || error.message || "Unknown error"}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
throw new BadRequestError({
|
||||||
|
message: "Unable to validate connection: verify credentials"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.credentials;
|
||||||
|
};
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
import z from "zod";
|
||||||
|
|
||||||
|
import { AppConnections } from "@app/lib/api-docs";
|
||||||
|
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
|
||||||
|
import {
|
||||||
|
BaseAppConnectionSchema,
|
||||||
|
GenericCreateAppConnectionFieldsSchema,
|
||||||
|
GenericUpdateAppConnectionFieldsSchema
|
||||||
|
} from "@app/services/app-connection/app-connection-schemas";
|
||||||
|
|
||||||
|
import { CloudflareConnectionMethod } from "./cloudflare-connection-enum";
|
||||||
|
import { CharacterType, characterValidator } from "@app/lib/validator/validate-string";
|
||||||
|
|
||||||
|
const accountIdCharacterValidator = characterValidator([
|
||||||
|
CharacterType.AlphaNumeric,
|
||||||
|
CharacterType.Underscore,
|
||||||
|
CharacterType.Hyphen
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const CloudflareConnectionApiTokenCredentialsSchema = z.object({
|
||||||
|
accountId: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.min(1, "Account ID required")
|
||||||
|
.max(256, "Account ID cannot exceed 256 characters")
|
||||||
|
.refine(
|
||||||
|
(val) => accountIdCharacterValidator(val),
|
||||||
|
"Account ID can only contain alphanumeric characters, underscores, and hyphens"
|
||||||
|
),
|
||||||
|
apiToken: z.string().trim().min(1, "API token required").max(256, "API token cannot exceed 256 characters")
|
||||||
|
});
|
||||||
|
|
||||||
|
const BaseCloudflareConnectionSchema = BaseAppConnectionSchema.extend({ app: z.literal(AppConnection.Cloudflare) });
|
||||||
|
|
||||||
|
export const CloudflareConnectionSchema = BaseCloudflareConnectionSchema.extend({
|
||||||
|
method: z.literal(CloudflareConnectionMethod.APIToken),
|
||||||
|
credentials: CloudflareConnectionApiTokenCredentialsSchema
|
||||||
|
});
|
||||||
|
|
||||||
|
export const SanitizedCloudflareConnectionSchema = z.discriminatedUnion("method", [
|
||||||
|
BaseCloudflareConnectionSchema.extend({
|
||||||
|
method: z.literal(CloudflareConnectionMethod.APIToken),
|
||||||
|
credentials: CloudflareConnectionApiTokenCredentialsSchema.pick({ accountId: true })
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const ValidateCloudflareConnectionCredentialsSchema = z.discriminatedUnion("method", [
|
||||||
|
z.object({
|
||||||
|
method: z
|
||||||
|
.literal(CloudflareConnectionMethod.APIToken)
|
||||||
|
.describe(AppConnections.CREATE(AppConnection.Cloudflare).method),
|
||||||
|
credentials: CloudflareConnectionApiTokenCredentialsSchema.describe(
|
||||||
|
AppConnections.CREATE(AppConnection.Cloudflare).credentials
|
||||||
|
)
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
export const CreateCloudflareConnectionSchema = ValidateCloudflareConnectionCredentialsSchema.and(
|
||||||
|
GenericCreateAppConnectionFieldsSchema(AppConnection.Cloudflare)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const UpdateCloudflareConnectionSchema = z
|
||||||
|
.object({
|
||||||
|
credentials: CloudflareConnectionApiTokenCredentialsSchema.optional().describe(
|
||||||
|
AppConnections.UPDATE(AppConnection.Cloudflare).credentials
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.and(GenericUpdateAppConnectionFieldsSchema(AppConnection.Cloudflare));
|
||||||
|
|
||||||
|
export const CloudflareConnectionListItemSchema = z.object({
|
||||||
|
name: z.literal("Cloudflare"),
|
||||||
|
app: z.literal(AppConnection.Cloudflare),
|
||||||
|
methods: z.nativeEnum(CloudflareConnectionMethod).array()
|
||||||
|
});
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import z from "zod";
|
||||||
|
|
||||||
|
import { DiscriminativePick } from "@app/lib/types";
|
||||||
|
|
||||||
|
import { AppConnection } from "../app-connection-enums";
|
||||||
|
import {
|
||||||
|
CloudflareConnectionSchema,
|
||||||
|
CreateCloudflareConnectionSchema,
|
||||||
|
ValidateCloudflareConnectionCredentialsSchema
|
||||||
|
} from "./cloudflare-connection-schema";
|
||||||
|
|
||||||
|
export type TCloudflareConnection = z.infer<typeof CloudflareConnectionSchema>;
|
||||||
|
|
||||||
|
export type TCloudflareConnectionInput = z.infer<typeof CreateCloudflareConnectionSchema> & {
|
||||||
|
app: AppConnection.Cloudflare;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type TValidateCloudflareConnectionCredentialsSchema = typeof ValidateCloudflareConnectionCredentialsSchema;
|
||||||
|
|
||||||
|
export type TCloudflareConnectionConfig = DiscriminativePick<
|
||||||
|
TCloudflareConnectionInput,
|
||||||
|
"method" | "app" | "credentials"
|
||||||
|
> & {
|
||||||
|
orgId: string;
|
||||||
|
};
|
||||||
@@ -84,6 +84,7 @@ export enum IntegrationUrls {
|
|||||||
QOVERY_API_URL = "https://api.qovery.com",
|
QOVERY_API_URL = "https://api.qovery.com",
|
||||||
TERRAFORM_CLOUD_API_URL = "https://app.terraform.io",
|
TERRAFORM_CLOUD_API_URL = "https://app.terraform.io",
|
||||||
CLOUDFLARE_PAGES_API_URL = "https://api.cloudflare.com",
|
CLOUDFLARE_PAGES_API_URL = "https://api.cloudflare.com",
|
||||||
|
CLOUDFLARE_API_URL = "https://api.cloudflare.com",
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
CLOUDFLARE_WORKERS_API_URL = "https://api.cloudflare.com",
|
CLOUDFLARE_WORKERS_API_URL = "https://api.cloudflare.com",
|
||||||
BITBUCKET_API_URL = "https://api.bitbucket.org",
|
BITBUCKET_API_URL = "https://api.bitbucket.org",
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
AzureDevOpsConnectionMethod,
|
AzureDevOpsConnectionMethod,
|
||||||
AzureKeyVaultConnectionMethod,
|
AzureKeyVaultConnectionMethod,
|
||||||
CamundaConnectionMethod,
|
CamundaConnectionMethod,
|
||||||
|
CloudflareConnectionMethod,
|
||||||
DatabricksConnectionMethod,
|
DatabricksConnectionMethod,
|
||||||
FlyioConnectionMethod,
|
FlyioConnectionMethod,
|
||||||
GcpConnectionMethod,
|
GcpConnectionMethod,
|
||||||
@@ -82,7 +83,8 @@ export const APP_CONNECTION_MAP: Record<
|
|||||||
[AppConnection.OCI]: { name: "OCI", image: "Oracle.png", enterprise: true },
|
[AppConnection.OCI]: { name: "OCI", image: "Oracle.png", enterprise: true },
|
||||||
[AppConnection.OnePass]: { name: "1Password", image: "1Password.png" },
|
[AppConnection.OnePass]: { name: "1Password", image: "1Password.png" },
|
||||||
[AppConnection.Render]: { name: "Render", image: "Render.png" },
|
[AppConnection.Render]: { name: "Render", image: "Render.png" },
|
||||||
[AppConnection.Flyio]: { name: "Fly.io", image: "Flyio.svg" }
|
[AppConnection.Flyio]: { name: "Fly.io", image: "Flyio.svg" },
|
||||||
|
[AppConnection.Cloudflare]: { name: "Cloudflare", image: "Cloudflare.png" }
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getAppConnectionMethodDetails = (method: TAppConnection["method"]) => {
|
export const getAppConnectionMethodDetails = (method: TAppConnection["method"]) => {
|
||||||
@@ -111,6 +113,7 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])
|
|||||||
case TerraformCloudConnectionMethod.ApiToken:
|
case TerraformCloudConnectionMethod.ApiToken:
|
||||||
case VercelConnectionMethod.ApiToken:
|
case VercelConnectionMethod.ApiToken:
|
||||||
case OnePassConnectionMethod.ApiToken:
|
case OnePassConnectionMethod.ApiToken:
|
||||||
|
case CloudflareConnectionMethod.ApiToken:
|
||||||
return { name: "API Token", icon: faKey };
|
return { name: "API Token", icon: faKey };
|
||||||
case PostgresConnectionMethod.UsernameAndPassword:
|
case PostgresConnectionMethod.UsernameAndPassword:
|
||||||
case MsSqlConnectionMethod.UsernameAndPassword:
|
case MsSqlConnectionMethod.UsernameAndPassword:
|
||||||
|
|||||||
@@ -24,5 +24,6 @@ export enum AppConnection {
|
|||||||
OCI = "oci",
|
OCI = "oci",
|
||||||
OnePass = "1password",
|
OnePass = "1password",
|
||||||
Render = "render",
|
Render = "render",
|
||||||
Flyio = "flyio"
|
Flyio = "flyio",
|
||||||
|
Cloudflare = "cloudflare"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,6 +118,10 @@ export type TFlyioConnectionOption = TAppConnectionOptionBase & {
|
|||||||
app: AppConnection.Flyio;
|
app: AppConnection.Flyio;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type TCloudflareConnectionOption = TAppConnectionOptionBase & {
|
||||||
|
app: AppConnection.Cloudflare;
|
||||||
|
};
|
||||||
|
|
||||||
export type TAppConnectionOption =
|
export type TAppConnectionOption =
|
||||||
| TAwsConnectionOption
|
| TAwsConnectionOption
|
||||||
| TGitHubConnectionOption
|
| TGitHubConnectionOption
|
||||||
@@ -142,7 +146,8 @@ export type TAppConnectionOption =
|
|||||||
| TOCIConnectionOption
|
| TOCIConnectionOption
|
||||||
| TOnePassConnectionOption
|
| TOnePassConnectionOption
|
||||||
| TRenderConnectionOption
|
| TRenderConnectionOption
|
||||||
| TFlyioConnectionOption;
|
| TFlyioConnectionOption
|
||||||
|
| TCloudflareConnectionOption;
|
||||||
|
|
||||||
export type TAppConnectionOptionMap = {
|
export type TAppConnectionOptionMap = {
|
||||||
[AppConnection.AWS]: TAwsConnectionOption;
|
[AppConnection.AWS]: TAwsConnectionOption;
|
||||||
@@ -171,4 +176,5 @@ export type TAppConnectionOptionMap = {
|
|||||||
[AppConnection.OnePass]: TOnePassConnectionOption;
|
[AppConnection.OnePass]: TOnePassConnectionOption;
|
||||||
[AppConnection.Render]: TRenderConnectionOption;
|
[AppConnection.Render]: TRenderConnectionOption;
|
||||||
[AppConnection.Flyio]: TFlyioConnectionOption;
|
[AppConnection.Flyio]: TFlyioConnectionOption;
|
||||||
|
[AppConnection.Cloudflare]: TCloudflareConnectionOption;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||||
|
import { TRootAppConnection } from "@app/hooks/api/appConnections/types/root-connection";
|
||||||
|
|
||||||
|
export enum CloudflareConnectionMethod {
|
||||||
|
ApiToken = "api-token"
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TCloudflareConnection = TRootAppConnection & { app: AppConnection.Cloudflare } & {
|
||||||
|
method: CloudflareConnectionMethod.ApiToken;
|
||||||
|
credentials: {
|
||||||
|
apiToken: string;
|
||||||
|
accountId: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -8,6 +8,7 @@ import { TAzureClientSecretsConnection } from "./azure-client-secrets-connection
|
|||||||
import { TAzureDevOpsConnection } from "./azure-devops-connection";
|
import { TAzureDevOpsConnection } from "./azure-devops-connection";
|
||||||
import { TAzureKeyVaultConnection } from "./azure-key-vault-connection";
|
import { TAzureKeyVaultConnection } from "./azure-key-vault-connection";
|
||||||
import { TCamundaConnection } from "./camunda-connection";
|
import { TCamundaConnection } from "./camunda-connection";
|
||||||
|
import { TCloudflareConnection } from "./cloudflare-connection";
|
||||||
import { TDatabricksConnection } from "./databricks-connection";
|
import { TDatabricksConnection } from "./databricks-connection";
|
||||||
import { TFlyioConnection } from "./flyio-connection";
|
import { TFlyioConnection } from "./flyio-connection";
|
||||||
import { TGcpConnection } from "./gcp-connection";
|
import { TGcpConnection } from "./gcp-connection";
|
||||||
@@ -53,6 +54,7 @@ export * from "./teamcity-connection";
|
|||||||
export * from "./terraform-cloud-connection";
|
export * from "./terraform-cloud-connection";
|
||||||
export * from "./vercel-connection";
|
export * from "./vercel-connection";
|
||||||
export * from "./windmill-connection";
|
export * from "./windmill-connection";
|
||||||
|
export * from "./cloudflare-connection";
|
||||||
|
|
||||||
export type TAppConnection =
|
export type TAppConnection =
|
||||||
| TAwsConnection
|
| TAwsConnection
|
||||||
@@ -80,7 +82,8 @@ export type TAppConnection =
|
|||||||
| TOCIConnection
|
| TOCIConnection
|
||||||
| TOnePassConnection
|
| TOnePassConnection
|
||||||
| TRenderConnection
|
| TRenderConnection
|
||||||
| TFlyioConnection;
|
| TFlyioConnection
|
||||||
|
| TCloudflareConnection;
|
||||||
|
|
||||||
export type TAvailableAppConnection = Pick<TAppConnection, "name" | "id">;
|
export type TAvailableAppConnection = Pick<TAppConnection, "name" | "id">;
|
||||||
|
|
||||||
@@ -134,4 +137,5 @@ export type TAppConnectionMap = {
|
|||||||
[AppConnection.OnePass]: TOnePassConnection;
|
[AppConnection.OnePass]: TOnePassConnection;
|
||||||
[AppConnection.Render]: TRenderConnection;
|
[AppConnection.Render]: TRenderConnection;
|
||||||
[AppConnection.Flyio]: TFlyioConnection;
|
[AppConnection.Flyio]: TFlyioConnection;
|
||||||
|
[AppConnection.Cloudflare]: TCloudflareConnection;
|
||||||
};
|
};
|
||||||
|
|||||||
+5
@@ -35,6 +35,7 @@ import { TeamCityConnectionForm } from "./TeamCityConnectionForm";
|
|||||||
import { TerraformCloudConnectionForm } from "./TerraformCloudConnectionForm";
|
import { TerraformCloudConnectionForm } from "./TerraformCloudConnectionForm";
|
||||||
import { VercelConnectionForm } from "./VercelConnectionForm";
|
import { VercelConnectionForm } from "./VercelConnectionForm";
|
||||||
import { WindmillConnectionForm } from "./WindmillConnectionForm";
|
import { WindmillConnectionForm } from "./WindmillConnectionForm";
|
||||||
|
import { CloudflareConnectionForm } from "./CloudflareConnectionForm";
|
||||||
|
|
||||||
type FormProps = {
|
type FormProps = {
|
||||||
onComplete: (appConnection: TAppConnection) => void;
|
onComplete: (appConnection: TAppConnection) => void;
|
||||||
@@ -125,6 +126,8 @@ const CreateForm = ({ app, onComplete }: CreateFormProps) => {
|
|||||||
return <RenderConnectionForm onSubmit={onSubmit} />;
|
return <RenderConnectionForm onSubmit={onSubmit} />;
|
||||||
case AppConnection.Flyio:
|
case AppConnection.Flyio:
|
||||||
return <FlyioConnectionForm onSubmit={onSubmit} />;
|
return <FlyioConnectionForm onSubmit={onSubmit} />;
|
||||||
|
case AppConnection.Cloudflare:
|
||||||
|
return <CloudflareConnectionForm onSubmit={onSubmit} />;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unhandled App ${app}`);
|
throw new Error(`Unhandled App ${app}`);
|
||||||
}
|
}
|
||||||
@@ -213,6 +216,8 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
|
|||||||
return <RenderConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
return <RenderConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||||
case AppConnection.Flyio:
|
case AppConnection.Flyio:
|
||||||
return <FlyioConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
return <FlyioConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||||
|
case AppConnection.Cloudflare:
|
||||||
|
return <CloudflareConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unhandled App ${(appConnection as TAppConnection).app}`);
|
throw new Error(`Unhandled App ${(appConnection as TAppConnection).app}`);
|
||||||
}
|
}
|
||||||
|
|||||||
+148
@@ -0,0 +1,148 @@
|
|||||||
|
import { Controller, FormProvider, useForm } from "react-hook-form";
|
||||||
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
|
import { z } from "zod";
|
||||||
|
|
||||||
|
import {
|
||||||
|
Button,
|
||||||
|
FormControl,
|
||||||
|
Input,
|
||||||
|
ModalClose,
|
||||||
|
SecretInput,
|
||||||
|
Select,
|
||||||
|
SelectItem
|
||||||
|
} from "@app/components/v2";
|
||||||
|
import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
|
||||||
|
import { CloudflareConnectionMethod, TCloudflareConnection } from "@app/hooks/api/appConnections";
|
||||||
|
import { AppConnection } from "@app/hooks/api/appConnections/enums";
|
||||||
|
|
||||||
|
import {
|
||||||
|
genericAppConnectionFieldsSchema,
|
||||||
|
GenericAppConnectionsFields
|
||||||
|
} from "./GenericAppConnectionFields";
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
appConnection?: TCloudflareConnection;
|
||||||
|
onSubmit: (formData: FormData) => Promise<void>;
|
||||||
|
};
|
||||||
|
|
||||||
|
const rootSchema = genericAppConnectionFieldsSchema.extend({
|
||||||
|
app: z.literal(AppConnection.Cloudflare)
|
||||||
|
});
|
||||||
|
|
||||||
|
const formSchema = z.discriminatedUnion("method", [
|
||||||
|
rootSchema.extend({
|
||||||
|
method: z.literal(CloudflareConnectionMethod.ApiToken),
|
||||||
|
credentials: z.object({
|
||||||
|
apiToken: z.string().trim().min(1, "API Token required"),
|
||||||
|
accountId: z.string().trim().min(1, "Account ID required")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
|
type FormData = z.infer<typeof formSchema>;
|
||||||
|
|
||||||
|
export const CloudflareConnectionForm = ({ appConnection, onSubmit }: Props) => {
|
||||||
|
const isUpdate = Boolean(appConnection);
|
||||||
|
|
||||||
|
const form = useForm<FormData>({
|
||||||
|
resolver: zodResolver(formSchema),
|
||||||
|
defaultValues: appConnection ?? {
|
||||||
|
app: AppConnection.Cloudflare,
|
||||||
|
method: CloudflareConnectionMethod.ApiToken
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
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.Cloudflare].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(CloudflareConnectionMethod).map((method) => {
|
||||||
|
return (
|
||||||
|
<SelectItem value={method} key={method}>
|
||||||
|
{getAppConnectionMethodDetails(method).name}{" "}
|
||||||
|
</SelectItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</Select>
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="credentials.accountId"
|
||||||
|
control={control}
|
||||||
|
shouldUnregister
|
||||||
|
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error?.message)}
|
||||||
|
label="Account ID"
|
||||||
|
>
|
||||||
|
<Input value={value} onChange={(e) => onChange(e.target.value)} />
|
||||||
|
</FormControl>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<Controller
|
||||||
|
name="credentials.apiToken"
|
||||||
|
control={control}
|
||||||
|
shouldUnregister
|
||||||
|
render={({ field: { value, onChange }, fieldState: { error } }) => (
|
||||||
|
<FormControl
|
||||||
|
errorText={error?.message}
|
||||||
|
isError={Boolean(error?.message)}
|
||||||
|
label="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 Cloudflare"}
|
||||||
|
</Button>
|
||||||
|
<ModalClose asChild>
|
||||||
|
<Button colorSchema="secondary" variant="plain">
|
||||||
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</ModalClose>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</FormProvider>
|
||||||
|
);
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user