fix(relay): keep managed endpoint zone prod-owned
Co-authored-by: codex <[email protected]>
This commit is contained in:
1 parent
14b5817472
commit
91d650353f
3 files changed
+37
-3
No files matched your search
@@ -4,6 +4,7 @@ import {
|
||||
managedEndpointDigestInput,
|
||||
managedEndpointHostname,
|
||||
managedEndpointTunnelName,
|
||||
relayOwnsManagedEndpointZone,
|
||||
relayPublicDomainForStage,
|
||||
relayResourceNameForStage,
|
||||
relayStageSlug,
|
||||
@@ -27,6 +28,13 @@ describe("relayPublicDomainForStage", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("relayOwnsManagedEndpointZone", () => {
|
||||
it("keeps the shared Cloudflare zone owned by production", () => {
|
||||
expect(relayOwnsManagedEndpointZone("prod")).toBe(true);
|
||||
expect(relayOwnsManagedEndpointZone("dev_julius")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("relayResourceNameForStage", () => {
|
||||
it("isolates production and personal stages", () => {
|
||||
expect(relayResourceNameForStage("t3-code-relay-traces", "prod")).toBe(
|
||||
|
||||
@@ -2,6 +2,7 @@ const DNS_LABEL_MAX_LENGTH = 63;
|
||||
const MANAGED_ENDPOINT_HASH_LENGTH = 16;
|
||||
const MANAGED_ENDPOINT_HOST_PREFIX = "tunnels";
|
||||
const MANAGED_ENDPOINT_TUNNEL_PREFIX = "t3coderelay-managedendpoint";
|
||||
export const MANAGED_ENDPOINT_ZONE_OWNER_STAGE = "prod";
|
||||
|
||||
function normalizeZoneName(zoneName: string): string {
|
||||
return zoneName
|
||||
@@ -37,6 +38,10 @@ export function relayResourceNameForStage(name: string, stage: string): string {
|
||||
return `${name}-${relayStageSlug(stage)}`;
|
||||
}
|
||||
|
||||
export function relayOwnsManagedEndpointZone(stage: string): boolean {
|
||||
return stage === MANAGED_ENDPOINT_ZONE_OWNER_STAGE;
|
||||
}
|
||||
|
||||
export function relayPublicDomainForStage(stage: string, zoneName: string): string {
|
||||
const stageSlug = relayStageSlug(stage);
|
||||
const relayLabel = stage === "prod" ? "relay" : `relay-${stageSlug}`;
|
||||
|
||||
+24
-3
@@ -5,7 +5,19 @@ import * as Config from "effect/Config";
|
||||
import * as Effect from "effect/Effect";
|
||||
import * as Option from "effect/Option";
|
||||
|
||||
import { relayPublicDomainForStage } from "./deploymentConfig.ts";
|
||||
import {
|
||||
MANAGED_ENDPOINT_ZONE_OWNER_STAGE,
|
||||
relayOwnsManagedEndpointZone,
|
||||
relayPublicDomainForStage,
|
||||
} from "./deploymentConfig.ts";
|
||||
|
||||
function withLogicalId<Resource extends object>(resource: Resource, logicalId: string): Resource {
|
||||
return new Proxy(resource, {
|
||||
has: (target, property) => property === "LogicalId" || property in target,
|
||||
get: (target, property, receiver) =>
|
||||
property === "LogicalId" ? logicalId : Reflect.get(target, property, receiver),
|
||||
});
|
||||
}
|
||||
|
||||
export const RelayDeploymentConfig = Effect.gen(function* () {
|
||||
const { stage } = yield* Alchemy.Stack;
|
||||
@@ -26,6 +38,15 @@ export const RelayDeploymentConfig = Effect.gen(function* () {
|
||||
});
|
||||
|
||||
export const ManagedEndpointZone = RelayDeploymentConfig.pipe(
|
||||
Effect.map(({ managedEndpointZoneName }) => managedEndpointZoneName),
|
||||
Effect.flatMap((name) => Cloudflare.Zone("ManagedEndpointZone", { name }).pipe(adopt(true))),
|
||||
Effect.flatMap(({ stage, managedEndpointZoneName }) =>
|
||||
relayOwnsManagedEndpointZone(stage)
|
||||
? Cloudflare.Zone("ManagedEndpointZone", { name: managedEndpointZoneName }).pipe(adopt(true))
|
||||
: Cloudflare.Zone.ref("ManagedEndpointZone", {
|
||||
stage: MANAGED_ENDPOINT_ZONE_OWNER_STAGE,
|
||||
}).pipe(
|
||||
// Alchemy beta's DNS binding policy uses LogicalId to derive a
|
||||
// stable SID, but Resource.ref returns a lazy output proxy.
|
||||
Effect.map((zone) => withLogicalId(zone, "ManagedEndpointZone")),
|
||||
),
|
||||
),
|
||||
);
|
||||
Reference in new issue
Block a user