History

Rename local workspace route resolver

Rhys Sullivan committed 8 months ago

Commit b0414971 parent 0e8ffe35 files · +25 −25Browse files

Unified · Split

5 files
  1. packages/control-plane/src/api/executions/http.ts +4 −4
  2. packages/control-plane/src/api/local-context.ts +2 −2
  3. packages/control-plane/src/api/oauth/http.ts +2 −2
  4. packages/control-plane/src/api/policies/http.ts +6 −6
  5. packages/control-plane/src/api/sources/http.ts +11 −11
packages/control-plane/src/api/executions/http.ts+4−4
@@ -7,7 +7,7 @@ import { · 6 unmodified lines
7} from "../../runtime/execution-service";7} from "../../runtime/execution-service";
8 8
9import { ControlPlaneApi } from "../api";9import { ControlPlaneApi } from "../api";
10import { requireLocalWorkspaceAccess } from "../local-context";10import { resolveRequestedLocalWorkspace } from "../local-context";
11 11
12export const ControlPlaneExecutionsLive = HttpApiBuilder.group(12export const ControlPlaneExecutionsLive = HttpApiBuilder.group(
13 ControlPlaneApi,13 ControlPlaneApi,
@@ -15,7 +15,7 @@ export const ControlPlaneExecutionsLive = HttpApiBuilder.group( · 1 unmodified line
15 (handlers) =>15 (handlers) =>
16 handlers16 handlers
17 .handle("create", ({ path, payload }) =>17 .handle("create", ({ path, payload }) =>
18 requireLocalWorkspaceAccess("executions.create", path.workspaceId).pipe(18 resolveRequestedLocalWorkspace("executions.create", path.workspaceId).pipe(
19 Effect.flatMap((runtimeLocalWorkspace) =>19 Effect.flatMap((runtimeLocalWorkspace) =>
20 createExecution({20 createExecution({
21 workspaceId: path.workspaceId,21 workspaceId: path.workspaceId,
@@ -26,7 +26,7 @@ export const ControlPlaneExecutionsLive = HttpApiBuilder.group( · 4 unmodified lines
26 ),26 ),
27 )27 )
28 .handle("get", ({ path }) =>28 .handle("get", ({ path }) =>
29 requireLocalWorkspaceAccess("executions.get", path.workspaceId).pipe(29 resolveRequestedLocalWorkspace("executions.get", path.workspaceId).pipe(
30 Effect.zipRight(30 Effect.zipRight(
31 getExecution({31 getExecution({
32 workspaceId: path.workspaceId,32 workspaceId: path.workspaceId,
@@ -36,7 +36,7 @@ export const ControlPlaneExecutionsLive = HttpApiBuilder.group( · 3 unmodified lines
36 ),36 ),
37 )37 )
38 .handle("resume", ({ path, payload }) =>38 .handle("resume", ({ path, payload }) =>
39 requireLocalWorkspaceAccess("executions.resume", path.workspaceId).pipe(39 resolveRequestedLocalWorkspace("executions.resume", path.workspaceId).pipe(
40 Effect.flatMap((runtimeLocalWorkspace) =>40 Effect.flatMap((runtimeLocalWorkspace) =>
41 resumeExecution({41 resumeExecution({
42 workspaceId: path.workspaceId,42 workspaceId: path.workspaceId,
packages/control-plane/src/api/local-context.ts+2−2
@@ -4,7 +4,7 @@ import * as Effect from "effect/Effect"; · 3 unmodified lines
4import { requireRuntimeLocalWorkspace } from "../runtime/local-runtime-context";4import { requireRuntimeLocalWorkspace } from "../runtime/local-runtime-context";
5import { ControlPlaneForbiddenError } from "./errors";5import { ControlPlaneForbiddenError } from "./errors";
6 6
7export const requireLocalWorkspaceAccess = (7export const resolveRequestedLocalWorkspace = (
8 operation: string,8 operation: string,
9 workspaceId: WorkspaceId,9 workspaceId: WorkspaceId,
10) =>10) =>
@@ -12,7 +12,7 @@ export const requireLocalWorkspaceAccess = ( · 1 unmodified line
12 Effect.mapError((cause) =>12 Effect.mapError((cause) =>
13 new ControlPlaneForbiddenError({13 new ControlPlaneForbiddenError({
14 operation,14 operation,
15 message: "Workspace is not the active local workspace",15 message: "Requested workspace is not the active local workspace",
16 details: cause instanceof Error ? cause.message : String(cause),16 details: cause instanceof Error ? cause.message : String(cause),
17 })17 })
18 ),18 ),
packages/control-plane/src/api/oauth/http.ts+2−2
@@ -14,7 +14,7 @@ import { · 13 unmodified lines
14 ControlPlaneBadRequestError,14 ControlPlaneBadRequestError,
15 ControlPlaneStorageError,15 ControlPlaneStorageError,
16} from "../errors";16} from "../errors";
17import { requireLocalWorkspaceAccess } from "../local-context";17import { resolveRequestedLocalWorkspace } from "../local-context";
18import {18import {
19 SourceOAuthPopupResultSchema,19 SourceOAuthPopupResultSchema,
20 type SourceOAuthPopupResult,20 type SourceOAuthPopupResult,
@@ -234,7 +234,7 @@ export const ControlPlaneOAuthLive = HttpApiBuilder.group( · 213 unmodified lines
234 (handlers) =>234 (handlers) =>
235 handlers235 handlers
236 .handle("startSourceAuth", ({ path, payload }) =>236 .handle("startSourceAuth", ({ path, payload }) =>
237 requireLocalWorkspaceAccess("oauth.start_source_auth", path.workspaceId).pipe(237 resolveRequestedLocalWorkspace("oauth.start_source_auth", path.workspaceId).pipe(
238 Effect.flatMap((runtimeLocalWorkspace) =>238 Effect.flatMap((runtimeLocalWorkspace) =>
239 Effect.gen(function* () {239 Effect.gen(function* () {
240 const request = yield* HttpServerRequest.HttpServerRequest;240 const request = yield* HttpServerRequest.HttpServerRequest;
packages/control-plane/src/api/policies/http.ts+6−6
@@ -9,7 +9,7 @@ import { · 8 unmodified lines
9} from "../../runtime/policies-operations";9} from "../../runtime/policies-operations";
10 10
11import { ControlPlaneApi } from "../api";11import { ControlPlaneApi } from "../api";
12import { requireLocalWorkspaceAccess } from "../local-context";12import { resolveRequestedLocalWorkspace } from "../local-context";
13 13
14export const ControlPlanePoliciesLive = HttpApiBuilder.group(14export const ControlPlanePoliciesLive = HttpApiBuilder.group(
15 ControlPlaneApi,15 ControlPlaneApi,
@@ -17,21 +17,21 @@ export const ControlPlanePoliciesLive = HttpApiBuilder.group( · 1 unmodified line
17 (handlers) =>17 (handlers) =>
18 handlers18 handlers
19 .handle("list", ({ path }) =>19 .handle("list", ({ path }) =>
20 requireLocalWorkspaceAccess("policies.list", path.workspaceId).pipe(20 resolveRequestedLocalWorkspace("policies.list", path.workspaceId).pipe(
21 Effect.zipRight(21 Effect.zipRight(
22 listPolicies(path.workspaceId),22 listPolicies(path.workspaceId),
23 ),23 ),
24 ),24 ),
25 )25 )
26 .handle("create", ({ path, payload }) =>26 .handle("create", ({ path, payload }) =>
27 requireLocalWorkspaceAccess("policies.create", path.workspaceId).pipe(27 resolveRequestedLocalWorkspace("policies.create", path.workspaceId).pipe(
28 Effect.zipRight(28 Effect.zipRight(
29 createPolicy({ workspaceId: path.workspaceId, payload }),29 createPolicy({ workspaceId: path.workspaceId, payload }),
30 ),30 ),
31 ),31 ),
32 )32 )
33 .handle("get", ({ path }) =>33 .handle("get", ({ path }) =>
34 requireLocalWorkspaceAccess("policies.get", path.workspaceId).pipe(34 resolveRequestedLocalWorkspace("policies.get", path.workspaceId).pipe(
35 Effect.zipRight(35 Effect.zipRight(
36 getPolicy({36 getPolicy({
37 workspaceId: path.workspaceId,37 workspaceId: path.workspaceId,
@@ -41,7 +41,7 @@ export const ControlPlanePoliciesLive = HttpApiBuilder.group( · 3 unmodified lines
41 ),41 ),
42 )42 )
43 .handle("update", ({ path, payload }) =>43 .handle("update", ({ path, payload }) =>
44 requireLocalWorkspaceAccess("policies.update", path.workspaceId).pipe(44 resolveRequestedLocalWorkspace("policies.update", path.workspaceId).pipe(
45 Effect.zipRight(45 Effect.zipRight(
46 updatePolicy({46 updatePolicy({
47 workspaceId: path.workspaceId,47 workspaceId: path.workspaceId,
@@ -52,7 +52,7 @@ export const ControlPlanePoliciesLive = HttpApiBuilder.group( · 4 unmodified lines
52 ),52 ),
53 )53 )
54 .handle("remove", ({ path }) =>54 .handle("remove", ({ path }) =>
55 requireLocalWorkspaceAccess("policies.remove", path.workspaceId).pipe(55 resolveRequestedLocalWorkspace("policies.remove", path.workspaceId).pipe(
56 Effect.zipRight(56 Effect.zipRight(
57 removePolicy({57 removePolicy({
58 workspaceId: path.workspaceId,58 workspaceId: path.workspaceId,
packages/control-plane/src/api/sources/http.ts+11−11
@@ -34,7 +34,7 @@ import { · 33 unmodified lines
34 ControlPlaneStorageError,34 ControlPlaneStorageError,
35} from "../errors";35} from "../errors";
36import { ControlPlaneApi } from "../api";36import { ControlPlaneApi } from "../api";
37import { requireLocalWorkspaceAccess } from "../local-context";37import { resolveRequestedLocalWorkspace } from "../local-context";
38 38
39const readHeader = (headers: unknown, name: string): string | null => {39const readHeader = (headers: unknown, name: string): string | null => {
40 if (headers == null || typeof headers !== "object") {40 if (headers == null || typeof headers !== "object") {
@@ -658,7 +658,7 @@ export const ControlPlaneSourcesLive = HttpApiBuilder.group( · 617 unmodified lines
658 ),658 ),
659 )659 )
660 .handle("connect", ({ path, payload }) =>660 .handle("connect", ({ path, payload }) =>
661 requireLocalWorkspaceAccess("sources.connect", path.workspaceId).pipe(661 resolveRequestedLocalWorkspace("sources.connect", path.workspaceId).pipe(
662 Effect.flatMap((runtimeLocalWorkspace) =>662 Effect.flatMap((runtimeLocalWorkspace) =>
663 Effect.gen(function* () {663 Effect.gen(function* () {
664 const request = yield* HttpServerRequest.HttpServerRequest;664 const request = yield* HttpServerRequest.HttpServerRequest;
@@ -698,7 +698,7 @@ export const ControlPlaneSourcesLive = HttpApiBuilder.group( · 33 unmodified lines
698 ),698 ),
699 )699 )
700 .handle("list", ({ path }) =>700 .handle("list", ({ path }) =>
701 requireLocalWorkspaceAccess("sources.list", path.workspaceId).pipe(701 resolveRequestedLocalWorkspace("sources.list", path.workspaceId).pipe(
702 Effect.flatMap((runtimeLocalWorkspace) =>702 Effect.flatMap((runtimeLocalWorkspace) =>
703 listSources({703 listSources({
704 workspaceId: path.workspaceId,704 workspaceId: path.workspaceId,
@@ -708,7 +708,7 @@ export const ControlPlaneSourcesLive = HttpApiBuilder.group( · 3 unmodified lines
708 ),708 ),
709 )709 )
710 .handle("create", ({ path, payload }) =>710 .handle("create", ({ path, payload }) =>
711 requireLocalWorkspaceAccess("sources.create", path.workspaceId).pipe(711 resolveRequestedLocalWorkspace("sources.create", path.workspaceId).pipe(
712 Effect.flatMap((runtimeLocalWorkspace) =>712 Effect.flatMap((runtimeLocalWorkspace) =>
713 createSource({713 createSource({
714 workspaceId: path.workspaceId,714 workspaceId: path.workspaceId,
@@ -719,7 +719,7 @@ export const ControlPlaneSourcesLive = HttpApiBuilder.group( · 4 unmodified lines
719 ),719 ),
720 )720 )
721 .handle("get", ({ path }) =>721 .handle("get", ({ path }) =>
722 requireLocalWorkspaceAccess("sources.get", path.workspaceId).pipe(722 resolveRequestedLocalWorkspace("sources.get", path.workspaceId).pipe(
723 Effect.flatMap((runtimeLocalWorkspace) =>723 Effect.flatMap((runtimeLocalWorkspace) =>
724 getSource({724 getSource({
725 workspaceId: path.workspaceId,725 workspaceId: path.workspaceId,
@@ -730,7 +730,7 @@ export const ControlPlaneSourcesLive = HttpApiBuilder.group( · 4 unmodified lines
730 ),730 ),
731 )731 )
732 .handle("inspection", ({ path }) =>732 .handle("inspection", ({ path }) =>
733 requireLocalWorkspaceAccess("sources.inspection", path.workspaceId).pipe(733 resolveRequestedLocalWorkspace("sources.inspection", path.workspaceId).pipe(
734 Effect.zipRight(734 Effect.zipRight(
735 getSourceInspection({735 getSourceInspection({
736 workspaceId: path.workspaceId,736 workspaceId: path.workspaceId,
@@ -740,7 +740,7 @@ export const ControlPlaneSourcesLive = HttpApiBuilder.group( · 3 unmodified lines
740 ),740 ),
741 )741 )
742 .handle("inspectionTool", ({ path }) =>742 .handle("inspectionTool", ({ path }) =>
743 requireLocalWorkspaceAccess("sources.inspection_tool", path.workspaceId).pipe(743 resolveRequestedLocalWorkspace("sources.inspection_tool", path.workspaceId).pipe(
744 Effect.zipRight(744 Effect.zipRight(
745 getSourceInspectionToolDetail({745 getSourceInspectionToolDetail({
746 workspaceId: path.workspaceId,746 workspaceId: path.workspaceId,
@@ -751,7 +751,7 @@ export const ControlPlaneSourcesLive = HttpApiBuilder.group( · 4 unmodified lines
751 ),751 ),
752 )752 )
753 .handle("inspectionSchemaBundle", ({ path }) =>753 .handle("inspectionSchemaBundle", ({ path }) =>
754 requireLocalWorkspaceAccess("sources.inspection_schema_bundle", path.workspaceId).pipe(754 resolveRequestedLocalWorkspace("sources.inspection_schema_bundle", path.workspaceId).pipe(
755 Effect.zipRight(755 Effect.zipRight(
756 getSourceInspectionSchemaBundle({756 getSourceInspectionSchemaBundle({
757 workspaceId: path.workspaceId,757 workspaceId: path.workspaceId,
@@ -762,7 +762,7 @@ export const ControlPlaneSourcesLive = HttpApiBuilder.group( · 4 unmodified lines
762 ),762 ),
763 )763 )
764 .handle("inspectionDiscover", ({ path, payload }) =>764 .handle("inspectionDiscover", ({ path, payload }) =>
765 requireLocalWorkspaceAccess("sources.inspection_discover", path.workspaceId).pipe(765 resolveRequestedLocalWorkspace("sources.inspection_discover", path.workspaceId).pipe(
766 Effect.zipRight(766 Effect.zipRight(
767 discoverSourceInspectionTools({767 discoverSourceInspectionTools({
768 workspaceId: path.workspaceId,768 workspaceId: path.workspaceId,
@@ -773,7 +773,7 @@ export const ControlPlaneSourcesLive = HttpApiBuilder.group( · 4 unmodified lines
773 ),773 ),
774 )774 )
775 .handle("update", ({ path, payload }) =>775 .handle("update", ({ path, payload }) =>
776 requireLocalWorkspaceAccess("sources.update", path.workspaceId).pipe(776 resolveRequestedLocalWorkspace("sources.update", path.workspaceId).pipe(
777 Effect.flatMap((runtimeLocalWorkspace) =>777 Effect.flatMap((runtimeLocalWorkspace) =>
778 updateSource({778 updateSource({
779 workspaceId: path.workspaceId,779 workspaceId: path.workspaceId,
@@ -785,7 +785,7 @@ export const ControlPlaneSourcesLive = HttpApiBuilder.group( · 5 unmodified lines
785 ),785 ),
786 )786 )
787 .handle("remove", ({ path }) =>787 .handle("remove", ({ path }) =>
788 requireLocalWorkspaceAccess("sources.remove", path.workspaceId).pipe(788 resolveRequestedLocalWorkspace("sources.remove", path.workspaceId).pipe(
789 Effect.zipRight(789 Effect.zipRight(
790 removeSource({790 removeSource({
791 workspaceId: path.workspaceId,791 workspaceId: path.workspaceId,