mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Fix greptile reviews
This commit is contained in:
@@ -53,7 +53,7 @@ export const registerCloudflareConnectionRouter = async (server: FastifyZodProvi
|
|||||||
|
|
||||||
server.route({
|
server.route({
|
||||||
method: "GET",
|
method: "GET",
|
||||||
url: `/:connectionId/cloudflare-workers-projects`,
|
url: `/:connectionId/cloudflare-workers-scripts`,
|
||||||
config: {
|
config: {
|
||||||
rateLimit: readLimit
|
rateLimit: readLimit
|
||||||
},
|
},
|
||||||
@@ -73,7 +73,7 @@ export const registerCloudflareConnectionRouter = async (server: FastifyZodProvi
|
|||||||
handler: async (req) => {
|
handler: async (req) => {
|
||||||
const { connectionId } = req.params;
|
const { connectionId } = req.params;
|
||||||
|
|
||||||
const projects = await server.services.appConnection.cloudflare.listWorkersProjects(connectionId, req.permission);
|
const projects = await server.services.appConnection.cloudflare.listWorkersScripts(connectionId, req.permission);
|
||||||
|
|
||||||
return projects;
|
return projects;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import {
|
|||||||
TCloudflareConnection,
|
TCloudflareConnection,
|
||||||
TCloudflareConnectionConfig,
|
TCloudflareConnectionConfig,
|
||||||
TCloudflarePagesProject,
|
TCloudflarePagesProject,
|
||||||
TCloudflareWorkersProject
|
TCloudflareWorkersScript
|
||||||
} from "./cloudflare-connection-types";
|
} from "./cloudflare-connection-types";
|
||||||
|
|
||||||
export const getCloudflareConnectionListItem = () => {
|
export const getCloudflareConnectionListItem = () => {
|
||||||
@@ -44,9 +44,9 @@ export const listCloudflarePagesProjects = async (
|
|||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|
||||||
export const listCloudflareWorkersProjects = async (
|
export const listCloudflareWorkersScripts = async (
|
||||||
appConnection: TCloudflareConnection
|
appConnection: TCloudflareConnection
|
||||||
): Promise<TCloudflareWorkersProject[]> => {
|
): Promise<TCloudflareWorkersScript[]> => {
|
||||||
const {
|
const {
|
||||||
credentials: { apiToken, accountId }
|
credentials: { apiToken, accountId }
|
||||||
} = appConnection;
|
} = appConnection;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { logger } from "@app/lib/logger";
|
|||||||
import { OrgServiceActor } from "@app/lib/types";
|
import { OrgServiceActor } from "@app/lib/types";
|
||||||
|
|
||||||
import { AppConnection } from "../app-connection-enums";
|
import { AppConnection } from "../app-connection-enums";
|
||||||
import { listCloudflarePagesProjects, listCloudflareWorkersProjects } from "./cloudflare-connection-fns";
|
import { listCloudflarePagesProjects, listCloudflareWorkersScripts } from "./cloudflare-connection-fns";
|
||||||
import { TCloudflareConnection } from "./cloudflare-connection-types";
|
import { TCloudflareConnection } from "./cloudflare-connection-types";
|
||||||
|
|
||||||
type TGetAppConnectionFunc = (
|
type TGetAppConnectionFunc = (
|
||||||
@@ -19,25 +19,31 @@ export const cloudflareConnectionService = (getAppConnection: TGetAppConnectionF
|
|||||||
|
|
||||||
return projects;
|
return projects;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error, "Failed to list Cloudflare Pages projects for Cloudflare connection");
|
logger.error(
|
||||||
|
error,
|
||||||
|
`Failed to list Cloudflare Pages projects for Cloudflare connection [connectionId=${connectionId}]`
|
||||||
|
);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const listWorkersProjects = async (connectionId: string, actor: OrgServiceActor) => {
|
const listWorkersScripts = async (connectionId: string, actor: OrgServiceActor) => {
|
||||||
const appConnection = await getAppConnection(AppConnection.Cloudflare, connectionId, actor);
|
const appConnection = await getAppConnection(AppConnection.Cloudflare, connectionId, actor);
|
||||||
try {
|
try {
|
||||||
const projects = await listCloudflareWorkersProjects(appConnection);
|
const projects = await listCloudflareWorkersScripts(appConnection);
|
||||||
|
|
||||||
return projects;
|
return projects;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(error, "Failed to list Cloudflare Workers projects for Cloudflare connection");
|
logger.error(
|
||||||
|
error,
|
||||||
|
`Failed to list Cloudflare Workers scripts for Cloudflare connection [connectionId=${connectionId}]`
|
||||||
|
);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
listPagesProjects,
|
listPagesProjects,
|
||||||
listWorkersProjects
|
listWorkersScripts
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ export type TCloudflarePagesProject = {
|
|||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TCloudflareWorkersProject = {
|
export type TCloudflareWorkersScript = {
|
||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import RE2 from "re2";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
import { SecretSyncs } from "@app/lib/api-docs";
|
import { SecretSyncs } from "@app/lib/api-docs";
|
||||||
@@ -14,6 +15,8 @@ const CloudflareWorkersSyncDestinationConfigSchema = z.object({
|
|||||||
scriptId: z
|
scriptId: z
|
||||||
.string()
|
.string()
|
||||||
.min(1, "Script ID is required")
|
.min(1, "Script ID is required")
|
||||||
|
.max(64)
|
||||||
|
.regex(new RE2(/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/), "Invalid script ID format")
|
||||||
.describe(SecretSyncs.DESTINATION_CONFIG.CLOUDFLARE_WORKERS.scriptId)
|
.describe(SecretSyncs.DESTINATION_CONFIG.CLOUDFLARE_WORKERS.scriptId)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -75,8 +75,7 @@ description: "Learn how to configure a Cloudflare Workers Sync for Infisical."
|
|||||||
"initialSyncBehavior": "overwrite-destination"
|
"initialSyncBehavior": "overwrite-destination"
|
||||||
},
|
},
|
||||||
"destinationConfig": {
|
"destinationConfig": {
|
||||||
"projectId": "your-cloudflare-workers-project-id",
|
"scriptId": "my-workers-script"
|
||||||
"scriptId": "my-workers-project"
|
|
||||||
}
|
}
|
||||||
}'
|
}'
|
||||||
```
|
```
|
||||||
@@ -119,8 +118,7 @@ description: "Learn how to configure a Cloudflare Workers Sync for Infisical."
|
|||||||
},
|
},
|
||||||
"destination": "cloudflare-workers",
|
"destination": "cloudflare-workers",
|
||||||
"destinationConfig": {
|
"destinationConfig": {
|
||||||
"projectId": "your-cloudflare-workers-project-id",
|
"scriptId": "my-workers-script"
|
||||||
"scriptId": "my-workers-project"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import { SingleValue } from "react-select";
|
|||||||
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
|
import { SecretSyncConnectionField } from "@app/components/secret-syncs/forms/SecretSyncConnectionField";
|
||||||
import { FilterableSelect, FormControl } from "@app/components/v2";
|
import { FilterableSelect, FormControl } from "@app/components/v2";
|
||||||
import {
|
import {
|
||||||
TCloudflareWorkersProject,
|
TCloudflareWorkersScript,
|
||||||
useCloudflareConnectionListWorkersProjects
|
useCloudflareConnectionListWorkersScripts
|
||||||
} from "@app/hooks/api/appConnections/cloudflare";
|
} from "@app/hooks/api/appConnections/cloudflare";
|
||||||
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
import { SecretSync } from "@app/hooks/api/secretSyncs";
|
||||||
|
|
||||||
@@ -18,8 +18,8 @@ export const CloudflareWorkersSyncFields = () => {
|
|||||||
|
|
||||||
const connectionId = useWatch({ name: "connection.id", control });
|
const connectionId = useWatch({ name: "connection.id", control });
|
||||||
|
|
||||||
const { data: projects = [], isPending: isProjectsPending } =
|
const { data: scripts = [], isPending: isScriptsPending } =
|
||||||
useCloudflareConnectionListWorkersProjects(connectionId, {
|
useCloudflareConnectionListWorkersScripts(connectionId, {
|
||||||
enabled: Boolean(connectionId)
|
enabled: Boolean(connectionId)
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -40,13 +40,13 @@ export const CloudflareWorkersSyncFields = () => {
|
|||||||
label="Worker Script"
|
label="Worker Script"
|
||||||
>
|
>
|
||||||
<FilterableSelect
|
<FilterableSelect
|
||||||
isLoading={isProjectsPending && Boolean(connectionId)}
|
isLoading={isScriptsPending && Boolean(connectionId)}
|
||||||
isDisabled={!connectionId}
|
isDisabled={!connectionId}
|
||||||
value={projects ? (projects.find((project) => project.id === value) ?? []) : []}
|
value={scripts?.find((script) => script.id === value) || []}
|
||||||
onChange={(option) => {
|
onChange={(option) => {
|
||||||
onChange((option as SingleValue<TCloudflareWorkersProject>)?.id ?? null);
|
onChange((option as SingleValue<TCloudflareWorkersScript>)?.id ?? null);
|
||||||
}}
|
}}
|
||||||
options={projects}
|
options={scripts}
|
||||||
placeholder="Select a worker script..."
|
placeholder="Select a worker script..."
|
||||||
getOptionLabel={(option) => option.id}
|
getOptionLabel={(option) => option.id}
|
||||||
getOptionValue={(option) => option.id}
|
getOptionValue={(option) => option.id}
|
||||||
|
|||||||
@@ -7,7 +7,12 @@ export const CloudflareWorkersSyncDestinationSchema = BaseSecretSyncSchema().mer
|
|||||||
z.object({
|
z.object({
|
||||||
destination: z.literal(SecretSync.CloudflareWorkers),
|
destination: z.literal(SecretSync.CloudflareWorkers),
|
||||||
destinationConfig: z.object({
|
destinationConfig: z.object({
|
||||||
scriptId: z.string().trim().min(1, "Script ID is required")
|
scriptId: z
|
||||||
|
.string()
|
||||||
|
.trim()
|
||||||
|
.min(1, "Script ID is required")
|
||||||
|
.max(64)
|
||||||
|
.regex(/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/, "Invalid script ID format")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,14 +3,14 @@ import { useQuery, UseQueryOptions } from "@tanstack/react-query";
|
|||||||
import { apiRequest } from "@app/config/request";
|
import { apiRequest } from "@app/config/request";
|
||||||
|
|
||||||
import { appConnectionKeys } from "../queries";
|
import { appConnectionKeys } from "../queries";
|
||||||
import { TCloudflarePagesProject, TCloudflareWorkersProject } from "./types";
|
import { TCloudflarePagesProject, TCloudflareWorkersScript } from "./types";
|
||||||
|
|
||||||
const cloudflareConnectionKeys = {
|
const cloudflareConnectionKeys = {
|
||||||
all: [...appConnectionKeys.all, "cloudflare"] as const,
|
all: [...appConnectionKeys.all, "cloudflare"] as const,
|
||||||
listPagesProjects: (connectionId: string) =>
|
listPagesProjects: (connectionId: string) =>
|
||||||
[...cloudflareConnectionKeys.all, "pages-projects", connectionId] as const,
|
[...cloudflareConnectionKeys.all, "pages-projects", connectionId] as const,
|
||||||
listWorkersProjects: (connectionId: string) =>
|
listWorkersScripts: (connectionId: string) =>
|
||||||
[...cloudflareConnectionKeys.all, "workers-projects", connectionId] as const
|
[...cloudflareConnectionKeys.all, "workers-scripts", connectionId] as const
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useCloudflareConnectionListPagesProjects = (
|
export const useCloudflareConnectionListPagesProjects = (
|
||||||
@@ -38,23 +38,23 @@ export const useCloudflareConnectionListPagesProjects = (
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useCloudflareConnectionListWorkersProjects = (
|
export const useCloudflareConnectionListWorkersScripts = (
|
||||||
connectionId: string,
|
connectionId: string,
|
||||||
options?: Omit<
|
options?: Omit<
|
||||||
UseQueryOptions<
|
UseQueryOptions<
|
||||||
TCloudflareWorkersProject[],
|
TCloudflareWorkersScript[],
|
||||||
unknown,
|
unknown,
|
||||||
TCloudflareWorkersProject[],
|
TCloudflareWorkersScript[],
|
||||||
ReturnType<typeof cloudflareConnectionKeys.listWorkersProjects>
|
ReturnType<typeof cloudflareConnectionKeys.listWorkersScripts>
|
||||||
>,
|
>,
|
||||||
"queryKey" | "queryFn"
|
"queryKey" | "queryFn"
|
||||||
>
|
>
|
||||||
) => {
|
) => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
queryKey: cloudflareConnectionKeys.listWorkersProjects(connectionId),
|
queryKey: cloudflareConnectionKeys.listWorkersScripts(connectionId),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const { data } = await apiRequest.get<TCloudflareWorkersProject[]>(
|
const { data } = await apiRequest.get<TCloudflareWorkersScript[]>(
|
||||||
`/api/v1/app-connections/cloudflare/${connectionId}/cloudflare-workers-projects`
|
`/api/v1/app-connections/cloudflare/${connectionId}/cloudflare-workers-scripts`
|
||||||
);
|
);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ export type TCloudflarePagesProject = {
|
|||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TCloudflareWorkersProject = {
|
export type TCloudflareWorkersScript = {
|
||||||
id: string;
|
id: string;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user