import * as networksecurity from "@distilled.cloud/gcp/networksecurity_v1";
import { Unowned } from "alchemy/AdoptPolicy";
import { isResolved } from "alchemy/Diff";
import * as Provider from "alchemy/Provider";
import { Resource } from "alchemy/Resource";
import * as Data from "effect/Data";
import * as Effect from "effect/Effect";
import * as Schedule from "effect/Schedule";
import * as Stream from "effect/Stream";
import { GcpEnvironment } from "../Environment.ts";
import type { Providers } from "../Providers.ts";
import {
normalizeLocation,
parentOf,
parseResourceName,
resourceName,
toId,
toResourcePath,
} from "./names.ts";
import { waitForOperation } from "./operations.ts";
import {
createInternalLabels,
encodeDescription,
hasAlchemyLabels,
hasOwnershipMarker,
parseDescription,
sameStringList,
} from "./ownership.ts";
const COLLECTION = "tlsInspectionPolicies";
export type TlsFeatureProfile =
| "PROFILE_COMPATIBLE"
| "PROFILE_MODERN"
| "PROFILE_RESTRICTED"
| "PROFILE_CUSTOM"
| (string & {});
export type MinTlsVersion = "TLS_1_0" | "TLS_1_1" | "TLS_1_2" | "TLS_1_3" | (string & {});
export type TlsInspectionPolicyProps = {
/**
* TlsInspectionPolicy id (the `{tlsInspectionPolicy}` segment of
* `projects/{project}/locations/{location}/tlsInspectionPolicies/{tlsInspectionPolicy}`).
* If omitted, a unique RFC1035 name is generated from the stack, stage,
* and logical id. Must match `^[a-z]([a-z0-9-]{0,61}[a-z0-9])?
.repos/alchemy-effect/packages/gcp/src/NetworkSecurity/TlsInspectionPolicy.ts at main · sailfork/t3code-github · Sailfork
.
* Immutable — changing it replaces the policy.
*/
tlsInspectionPolicyId?: string;
/**
* Location (`us-central1`, `us-east1`, …). Immutable — changing it
* replaces the policy. `US-CENTRAL1` is accepted and normalized to
* `us-central1`.
* @default the stack's GCP region (`GCP.Region`, profile region, `us-central1`)
*/
location?: string;
/**
* CA pool used to issue interception certificates, as
* `projects/{project}/locations/{location}/caPools/{caPool}` or a bare
* pool id (combined with `location`).
*/
caPool: string;
/**
* Human-readable description. TlsInspectionPolicy has no labels field,
* so Alchemy ownership is stored in a `[alchemy …]` prefix and stripped
* from attributes.
*/
description?: string;
/**
* TLS feature profile. Defaults to `PROFILE_COMPATIBLE` (broadest
* client/server set). Secure Web Proxy does not yet honor this field.
*/
tlsFeatureProfile?: TlsFeatureProfile;
/**
* Minimum TLS version negotiated with clients and servers. Secure Web
* Proxy does not yet honor this field.
*/
minTlsVersion?: MinTlsVersion;
/**
* Custom TLS cipher suites. Valid only when `tlsFeatureProfile` is
* `PROFILE_CUSTOM`. Secure Web Proxy does not yet honor this field.
*/
customTlsFeatures?: string[];
/**
* When true, do not trust the default public CA set — only CAs in
* `trustConfig` are accepted. Defaults to false. Secure Web Proxy does
* not yet honor this field.
* @default false
*/
excludePublicCaSet?: boolean;
/**
* Certificate Manager TrustConfig used when connecting to the TLS
* server (`projects/{project}/locations/{location}/trustConfigs/{trustConfig}`).
* Needed for private or self-signed server certificates. Secure Web
* Proxy does not yet honor this field.
*/
trustConfig?: string;
};
export type TlsInspectionPolicy = Resource<
"GCP.NetworkSecurity.TlsInspectionPolicy",
TlsInspectionPolicyProps,
{
/** Full resource name `projects/{project}/locations/{location}/tlsInspectionPolicies/{tlsInspectionPolicy}`. */
name: string;
/** TlsInspectionPolicy id (last path segment). */
tlsInspectionPolicyId: string;
/** Project id. */
project: string;
/** Location id (`us-central1`, …). */
location: string;
/** CA pool used to issue interception certificates. */
caPool: string | undefined;
/** User description with the Alchemy ownership prefix stripped. */
description: string | undefined;
/** TLS feature profile currently configured. */
tlsFeatureProfile: string | undefined;
/** Minimum TLS version currently configured. */
minTlsVersion: string | undefined;
/** Custom TLS cipher suites, if `tlsFeatureProfile` is `PROFILE_CUSTOM`. */
customTlsFeatures: string[];
/** Whether the default public CA set is excluded. */
excludePublicCaSet: boolean;
/** TrustConfig used when connecting to TLS servers, if set. */
trustConfig: string | undefined;
/** RFC3339 creation timestamp. */
createTime: string | undefined;
/** RFC3339 last-update timestamp. */
updateTime: string | undefined;
},
never,
Providers
>;
/**
* A Network Security TlsInspectionPolicy — CA pool and TLS settings used
* to intercept TLS for Secure Web Proxy and Cloud NGFW.
*
* TlsInspectionPolicy has no labels field, so Alchemy stamps ownership
* into the description for `list` / nuke. Changing `tlsInspectionPolicyId`
* or `location` replaces the policy. `caPool`, description, TLS feature
* profile, min version, custom features, `excludePublicCaSet`, and
* `trustConfig` update in place.
*
* ### Creating a TlsInspectionPolicy
* **Example:** Intercept with a CaPool
* ```typescript
* const pool = yield* GCP.PrivateCA.CaPool("Intercept", {
* location: "us-central1",
* tier: "DEVOPS",
* });
* const policy = yield* GCP.NetworkSecurity.TlsInspectionPolicy("Inspect", {
* caPool: pool.name,
* });
* ```
*
* **Example:** Named policy with TLS constraints
* ```typescript
* const policy = yield* GCP.NetworkSecurity.TlsInspectionPolicy("Inspect", {
* tlsInspectionPolicyId: "app-inspect",
* location: "us-central1",
* caPool: pool.name,
* description: "prod intercept",
* excludePublicCaSet: true,
* minTlsVersion: "TLS_1_2",
* tlsFeatureProfile: "PROFILE_MODERN",
* });
* ```
*
* ### Updating a TlsInspectionPolicy
* **Example:** Tighten TLS
* ```typescript
* const policy = yield* GCP.NetworkSecurity.TlsInspectionPolicy("Inspect", {
* tlsInspectionPolicyId: "app-inspect",
* location: "us-central1",
* caPool: pool.name,
* description: "prod intercept v2",
* excludePublicCaSet: true,
* minTlsVersion: "TLS_1_2",
* });
* ```
*
* @resource
* @category NetworkSecurity
*/
export const TlsInspectionPolicy = Resource<TlsInspectionPolicy>(
"GCP.NetworkSecurity.TlsInspectionPolicy",
);
export class TlsInspectionPolicyNotResolved extends Data.TaggedError(
"GCP.NetworkSecurity.TlsInspectionPolicyNotResolved",
)<{
resourceName: string;
}> {}
export class TlsInspectionPolicyStillExists extends Data.TaggedError(
"GCP.NetworkSecurity.TlsInspectionPolicyStillExists",
)<{
resourceName: string;
}> {}
const caPoolName = (project: string, location: string, caPool: string) => {
const trimmed = toResourcePath(caPool);
if (trimmed.includes("/")) return trimmed;
return `projects/${project}/locations/${location}/caPools/${trimmed}`;
};
const trustConfigName = (project: string, location: string, trustConfig: string | undefined) => {
if (trustConfig === undefined || trustConfig.length === 0) return undefined;
const trimmed = toResourcePath(trustConfig);
if (trimmed.includes("/")) return trimmed;
return `projects/${project}/locations/${location}/trustConfigs/${trimmed}`;
};
const toAttrs = (policy: networksecurity.TlsInspectionPolicy, project: string, region: string) => {
const name = policy.name ?? "";
const parsed = parseResourceName(name, COLLECTION);
const owned = parseDescription(policy.description);
return {
name,
tlsInspectionPolicyId: parsed.id,
project: parsed.project || project,
location: parsed.location || region,
caPool: policy.caPool,
description: owned.description,
tlsFeatureProfile: policy.tlsFeatureProfile,
minTlsVersion: policy.minTlsVersion,
customTlsFeatures: policy.customTlsFeatures ?? [],
excludePublicCaSet: policy.excludePublicCaSet === true,
trustConfig: policy.trustConfig,
createTime: policy.createTime,
updateTime: policy.updateTime,
};
};
const getByName = (name: string) =>
networksecurity
.getProjectsLocationsTlsInspectionPolicies({ name })
.pipe(Effect.catchTag("NotFound", () => Effect.undefined));
const waitUntilExists = (name: string) =>
getByName(name).pipe(
Effect.flatMap((policy) =>
policy
? Effect.succeed(policy)
: Effect.fail(new TlsInspectionPolicyNotResolved({ resourceName: name })),
),
Effect.retry({
while: (error) => error._tag === "GCP.NetworkSecurity.TlsInspectionPolicyNotResolved",
times: 8,
schedule: Schedule.spaced("1 second"),
}),
);
const waitUntilGone = (name: string) =>
getByName(name).pipe(
Effect.flatMap((policy) =>
policy === undefined
? Effect.void
: Effect.fail(new TlsInspectionPolicyStillExists({ resourceName: name })),
),
Effect.retry({
while: (error) => error._tag === "GCP.NetworkSecurity.TlsInspectionPolicyStillExists",
times: 10,
schedule: Schedule.spaced("2 seconds"),
}),
);
const listOwned = (project: string, region: string) =>
networksecurity.listProjectsLocationsTlsInspectionPolicies
.pages({
parent: parentOf(project, "-"),
pageSize: 1000,
})
.pipe(
Stream.flatMap((page) => Stream.fromIterable(page.tlsInspectionPolicies ?? [])),
Stream.filter((policy) => hasOwnershipMarker(policy.description)),
Stream.map((policy) => toAttrs(policy, project, region)),
Stream.runCollect,
Effect.map((chunk) => Array.from(chunk)),
Effect.catchTag("NotFound", () => Effect.succeed([])),
);
export const TlsInspectionPolicyProvider = () =>
Provider.succeed(TlsInspectionPolicy, {
stables: ["name", "tlsInspectionPolicyId", "project", "location", "createTime"],
diff: Effect.fn(function* ({ news, olds, output }) {
if (!isResolved(news)) return undefined;
const env = yield* GcpEnvironment.current;
const previousId = olds?.tlsInspectionPolicyId ?? output?.tlsInspectionPolicyId;
const nextId = news.tlsInspectionPolicyId ?? previousId;
const previousLocation = normalizeLocation(olds?.location ?? output?.location, env.region);
const nextLocation = normalizeLocation(
news.location ?? olds?.location ?? output?.location,
env.region,
);
if (
(previousId !== undefined && nextId !== undefined && nextId !== previousId) ||
previousLocation !== nextLocation
) {
return { action: "replace" as const };
}
return undefined;
}),
read: Effect.fn(function* ({ id, olds, output }) {
const env = yield* GcpEnvironment.current;
const tlsInspectionPolicyId = yield* toId(
id,
olds?.tlsInspectionPolicyId,
output?.tlsInspectionPolicyId,
"tlsinsp",
);
const location = normalizeLocation(olds?.location ?? output?.location, env.region);
const name =
output?.name ?? resourceName(env.project, location, COLLECTION, tlsInspectionPolicyId);
const existing = yield* getByName(name);
if (existing === undefined) return undefined;
const attrs = toAttrs(existing, env.project, env.region);
const { labels } = parseDescription(existing.description);
return (yield* hasAlchemyLabels(id, labels)) ? attrs : Unowned(attrs);
}),
list: () =>
Effect.gen(function* () {
const env = yield* GcpEnvironment.current;
return yield* listOwned(env.project, env.region);
}),
reconcile: Effect.fn(function* ({ id, news, output }) {
const env = yield* GcpEnvironment.current;
const tlsInspectionPolicyId = yield* toId(
id,
news.tlsInspectionPolicyId,
output?.tlsInspectionPolicyId,
"tlsinsp",
);
const location = normalizeLocation(news.location ?? output?.location, env.region);
const name = resourceName(env.project, location, COLLECTION, tlsInspectionPolicyId);
const ownership = yield* createInternalLabels(id);
const desiredDescription = encodeDescription(ownership, news.description);
const caPool = caPoolName(env.project, location, news.caPool);
const trustConfig = trustConfigName(env.project, location, news.trustConfig);
const excludePublicCaSet = news.excludePublicCaSet === true;
const customTlsFeatures = news.customTlsFeatures ?? [];
let current = yield* getByName(output?.name ?? name);
if (current === undefined) {
const created = yield* networksecurity
.createProjectsLocationsTlsInspectionPolicies({
parent: parentOf(env.project, location),
tlsInspectionPolicyId,
body: {
description: desiredDescription,
caPool,
trustConfig,
excludePublicCaSet,
tlsFeatureProfile: news.tlsFeatureProfile,
minTlsVersion: news.minTlsVersion,
customTlsFeatures: customTlsFeatures.length > 0 ? customTlsFeatures : undefined,
},
})
.pipe(
Effect.retry({
while: (error) => error._tag === "Conflict",
times: 5,
schedule: Schedule.spaced("2 seconds"),
}),
Effect.catchTag("Conflict", () => Effect.undefined),
);
if (created !== undefined) {
yield* waitForOperation(created);
}
current = yield* waitUntilExists(name);
}
if (current === undefined) {
return yield* new TlsInspectionPolicyNotResolved({ resourceName: name });
}
const descriptionChanged = (current.description ?? "") !== desiredDescription;
const caPoolChanged = (current.caPool ?? "") !== caPool;
const trustChanged = (current.trustConfig ?? "") !== (trustConfig ?? "");
const excludeChanged = (current.excludePublicCaSet === true) !== excludePublicCaSet;
const profileChanged = (current.tlsFeatureProfile ?? "") !== (news.tlsFeatureProfile ?? "");
const minTlsChanged = (current.minTlsVersion ?? "") !== (news.minTlsVersion ?? "");
const featuresChanged =
!sameStringList(
current.customTlsFeatures,
customTlsFeatures.length > 0 ? customTlsFeatures : current.customTlsFeatures,
) && news.customTlsFeatures !== undefined;
if (
descriptionChanged ||
caPoolChanged ||
trustChanged ||
excludeChanged ||
profileChanged ||
minTlsChanged ||
featuresChanged
) {
const updateMask = [
descriptionChanged ? "description" : undefined,
caPoolChanged ? "caPool" : undefined,
trustChanged ? "trustConfig" : undefined,
excludeChanged ? "excludePublicCaSet" : undefined,
profileChanged ? "tlsFeatureProfile" : undefined,
minTlsChanged ? "minTlsVersion" : undefined,
featuresChanged ? "customTlsFeatures" : undefined,
].filter((field): field is string => field !== undefined);
const operation = yield* networksecurity.patchProjectsLocationsTlsInspectionPolicies({
name: current.name ?? name,
updateMask: updateMask.join(","),
body: {
name: current.name ?? name,
description: desiredDescription,
caPool,
trustConfig,
excludePublicCaSet,
tlsFeatureProfile: news.tlsFeatureProfile,
minTlsVersion: news.minTlsVersion,
customTlsFeatures:
news.customTlsFeatures !== undefined ? customTlsFeatures : current.customTlsFeatures,
},
});
yield* waitForOperation(operation);
current = yield* waitUntilExists(current.name ?? name);
}
return toAttrs(current, env.project, env.region);
}),
delete: Effect.fn(function* ({ output }) {
const operation = yield* networksecurity
.deleteProjectsLocationsTlsInspectionPolicies({
name: output.name,
force: true,
})
.pipe(
Effect.retry({
while: (error) => error._tag === "Conflict",
times: 8,
schedule: Schedule.spaced("2 seconds"),
}),
Effect.catchTag("NotFound", () => Effect.undefined),
);
if (operation !== undefined) {
yield* waitForOperation(operation, { notFoundOk: true });
}
yield* waitUntilGone(output.name);
}),
});
.repos/alchemy-effect/packages/gcp/src/NetworkSecurity/TlsInspectionPolicy.ts at main · sailfork/t3code-github · Sailfork
.\n * Immutable — changing it replaces the policy.\n */\n tlsInspectionPolicyId?: string;\n /**\n * Location (`us-central1`, `us-east1`, …). Immutable — changing it\n * replaces the policy. `US-CENTRAL1` is accepted and normalized to\n * `us-central1`.\n * @default the stack's GCP region (`GCP.Region`, profile region, `us-central1`)\n */\n location?: string;\n /**\n * CA pool used to issue interception certificates, as\n * `projects/{project}/locations/{location}/caPools/{caPool}` or a bare\n * pool id (combined with `location`).\n */\n caPool: string;\n /**\n * Human-readable description. TlsInspectionPolicy has no labels field,\n * so Alchemy ownership is stored in a `[alchemy …]` prefix and stripped\n * from attributes.\n */\n description?: string;\n /**\n * TLS feature profile. Defaults to `PROFILE_COMPATIBLE` (broadest\n * client/server set). Secure Web Proxy does not yet honor this field.\n */\n tlsFeatureProfile?: TlsFeatureProfile;\n /**\n * Minimum TLS version negotiated with clients and servers. Secure Web\n * Proxy does not yet honor this field.\n */\n minTlsVersion?: MinTlsVersion;\n /**\n * Custom TLS cipher suites. Valid only when `tlsFeatureProfile` is\n * `PROFILE_CUSTOM`. Secure Web Proxy does not yet honor this field.\n */\n customTlsFeatures?: string[];\n /**\n * When true, do not trust the default public CA set — only CAs in\n * `trustConfig` are accepted. Defaults to false. Secure Web Proxy does\n * not yet honor this field.\n * @default false\n */\n excludePublicCaSet?: boolean;\n /**\n * Certificate Manager TrustConfig used when connecting to the TLS\n * server (`projects/{project}/locations/{location}/trustConfigs/{trustConfig}`).\n * Needed for private or self-signed server certificates. Secure Web\n * Proxy does not yet honor this field.\n */\n trustConfig?: string;\n};\n\nexport type TlsInspectionPolicy = Resource\u003c\n \"GCP.NetworkSecurity.TlsInspectionPolicy\",\n TlsInspectionPolicyProps,\n {\n /** Full resource name `projects/{project}/locations/{location}/tlsInspectionPolicies/{tlsInspectionPolicy}`. */\n name: string;\n /** TlsInspectionPolicy id (last path segment). */\n tlsInspectionPolicyId: string;\n /** Project id. */\n project: string;\n /** Location id (`us-central1`, …). */\n location: string;\n /** CA pool used to issue interception certificates. */\n caPool: string | undefined;\n /** User description with the Alchemy ownership prefix stripped. */\n description: string | undefined;\n /** TLS feature profile currently configured. */\n tlsFeatureProfile: string | undefined;\n /** Minimum TLS version currently configured. */\n minTlsVersion: string | undefined;\n /** Custom TLS cipher suites, if `tlsFeatureProfile` is `PROFILE_CUSTOM`. */\n customTlsFeatures: string[];\n /** Whether the default public CA set is excluded. */\n excludePublicCaSet: boolean;\n /** TrustConfig used when connecting to TLS servers, if set. */\n trustConfig: string | undefined;\n /** RFC3339 creation timestamp. */\n createTime: string | undefined;\n /** RFC3339 last-update timestamp. */\n updateTime: string | undefined;\n },\n never,\n Providers\n>;\n\n/**\n * A Network Security TlsInspectionPolicy — CA pool and TLS settings used\n * to intercept TLS for Secure Web Proxy and Cloud NGFW.\n *\n * TlsInspectionPolicy has no labels field, so Alchemy stamps ownership\n * into the description for `list` / nuke. Changing `tlsInspectionPolicyId`\n * or `location` replaces the policy. `caPool`, description, TLS feature\n * profile, min version, custom features, `excludePublicCaSet`, and\n * `trustConfig` update in place.\n *\n * ### Creating a TlsInspectionPolicy\n * **Example:** Intercept with a CaPool\n * ```typescript\n * const pool = yield* GCP.PrivateCA.CaPool(\"Intercept\", {\n * location: \"us-central1\",\n * tier: \"DEVOPS\",\n * });\n * const policy = yield* GCP.NetworkSecurity.TlsInspectionPolicy(\"Inspect\", {\n * caPool: pool.name,\n * });\n * ```\n *\n * **Example:** Named policy with TLS constraints\n * ```typescript\n * const policy = yield* GCP.NetworkSecurity.TlsInspectionPolicy(\"Inspect\", {\n * tlsInspectionPolicyId: \"app-inspect\",\n * location: \"us-central1\",\n * caPool: pool.name,\n * description: \"prod intercept\",\n * excludePublicCaSet: true,\n * minTlsVersion: \"TLS_1_2\",\n * tlsFeatureProfile: \"PROFILE_MODERN\",\n * });\n * ```\n *\n * ### Updating a TlsInspectionPolicy\n * **Example:** Tighten TLS\n * ```typescript\n * const policy = yield* GCP.NetworkSecurity.TlsInspectionPolicy(\"Inspect\", {\n * tlsInspectionPolicyId: \"app-inspect\",\n * location: \"us-central1\",\n * caPool: pool.name,\n * description: \"prod intercept v2\",\n * excludePublicCaSet: true,\n * minTlsVersion: \"TLS_1_2\",\n * });\n * ```\n *\n * @resource\n * @category NetworkSecurity\n */\nexport const TlsInspectionPolicy = Resource\u003cTlsInspectionPolicy>(\n \"GCP.NetworkSecurity.TlsInspectionPolicy\",\n);\n\nexport class TlsInspectionPolicyNotResolved extends Data.TaggedError(\n \"GCP.NetworkSecurity.TlsInspectionPolicyNotResolved\",\n)\u003c{\n resourceName: string;\n}> {}\n\nexport class TlsInspectionPolicyStillExists extends Data.TaggedError(\n \"GCP.NetworkSecurity.TlsInspectionPolicyStillExists\",\n)\u003c{\n resourceName: string;\n}> {}\n\nconst caPoolName = (project: string, location: string, caPool: string) => {\n const trimmed = toResourcePath(caPool);\n if (trimmed.includes(\"/\")) return trimmed;\n return `projects/${project}/locations/${location}/caPools/${trimmed}`;\n};\n\nconst trustConfigName = (project: string, location: string, trustConfig: string | undefined) => {\n if (trustConfig === undefined || trustConfig.length === 0) return undefined;\n const trimmed = toResourcePath(trustConfig);\n if (trimmed.includes(\"/\")) return trimmed;\n return `projects/${project}/locations/${location}/trustConfigs/${trimmed}`;\n};\n\nconst toAttrs = (policy: networksecurity.TlsInspectionPolicy, project: string, region: string) => {\n const name = policy.name ?? \"\";\n const parsed = parseResourceName(name, COLLECTION);\n const owned = parseDescription(policy.description);\n return {\n name,\n tlsInspectionPolicyId: parsed.id,\n project: parsed.project || project,\n location: parsed.location || region,\n caPool: policy.caPool,\n description: owned.description,\n tlsFeatureProfile: policy.tlsFeatureProfile,\n minTlsVersion: policy.minTlsVersion,\n customTlsFeatures: policy.customTlsFeatures ?? [],\n excludePublicCaSet: policy.excludePublicCaSet === true,\n trustConfig: policy.trustConfig,\n createTime: policy.createTime,\n updateTime: policy.updateTime,\n };\n};\n\nconst getByName = (name: string) =>\n networksecurity\n .getProjectsLocationsTlsInspectionPolicies({ name })\n .pipe(Effect.catchTag(\"NotFound\", () => Effect.undefined));\n\nconst waitUntilExists = (name: string) =>\n getByName(name).pipe(\n Effect.flatMap((policy) =>\n policy\n ? Effect.succeed(policy)\n : Effect.fail(new TlsInspectionPolicyNotResolved({ resourceName: name })),\n ),\n Effect.retry({\n while: (error) => error._tag === \"GCP.NetworkSecurity.TlsInspectionPolicyNotResolved\",\n times: 8,\n schedule: Schedule.spaced(\"1 second\"),\n }),\n );\n\nconst waitUntilGone = (name: string) =>\n getByName(name).pipe(\n Effect.flatMap((policy) =>\n policy === undefined\n ? Effect.void\n : Effect.fail(new TlsInspectionPolicyStillExists({ resourceName: name })),\n ),\n Effect.retry({\n while: (error) => error._tag === \"GCP.NetworkSecurity.TlsInspectionPolicyStillExists\",\n times: 10,\n schedule: Schedule.spaced(\"2 seconds\"),\n }),\n );\n\nconst listOwned = (project: string, region: string) =>\n networksecurity.listProjectsLocationsTlsInspectionPolicies\n .pages({\n parent: parentOf(project, \"-\"),\n pageSize: 1000,\n })\n .pipe(\n Stream.flatMap((page) => Stream.fromIterable(page.tlsInspectionPolicies ?? [])),\n Stream.filter((policy) => hasOwnershipMarker(policy.description)),\n Stream.map((policy) => toAttrs(policy, project, region)),\n Stream.runCollect,\n Effect.map((chunk) => Array.from(chunk)),\n Effect.catchTag(\"NotFound\", () => Effect.succeed([])),\n );\n\nexport const TlsInspectionPolicyProvider = () =>\n Provider.succeed(TlsInspectionPolicy, {\n stables: [\"name\", \"tlsInspectionPolicyId\", \"project\", \"location\", \"createTime\"],\n\n diff: Effect.fn(function* ({ news, olds, output }) {\n if (!isResolved(news)) return undefined;\n const env = yield* GcpEnvironment.current;\n const previousId = olds?.tlsInspectionPolicyId ?? output?.tlsInspectionPolicyId;\n const nextId = news.tlsInspectionPolicyId ?? previousId;\n const previousLocation = normalizeLocation(olds?.location ?? output?.location, env.region);\n const nextLocation = normalizeLocation(\n news.location ?? olds?.location ?? output?.location,\n env.region,\n );\n if (\n (previousId !== undefined && nextId !== undefined && nextId !== previousId) ||\n previousLocation !== nextLocation\n ) {\n return { action: \"replace\" as const };\n }\n return undefined;\n }),\n\n read: Effect.fn(function* ({ id, olds, output }) {\n const env = yield* GcpEnvironment.current;\n const tlsInspectionPolicyId = yield* toId(\n id,\n olds?.tlsInspectionPolicyId,\n output?.tlsInspectionPolicyId,\n \"tlsinsp\",\n );\n const location = normalizeLocation(olds?.location ?? output?.location, env.region);\n const name =\n output?.name ?? resourceName(env.project, location, COLLECTION, tlsInspectionPolicyId);\n const existing = yield* getByName(name);\n if (existing === undefined) return undefined;\n const attrs = toAttrs(existing, env.project, env.region);\n const { labels } = parseDescription(existing.description);\n return (yield* hasAlchemyLabels(id, labels)) ? attrs : Unowned(attrs);\n }),\n\n list: () =>\n Effect.gen(function* () {\n const env = yield* GcpEnvironment.current;\n return yield* listOwned(env.project, env.region);\n }),\n\n reconcile: Effect.fn(function* ({ id, news, output }) {\n const env = yield* GcpEnvironment.current;\n const tlsInspectionPolicyId = yield* toId(\n id,\n news.tlsInspectionPolicyId,\n output?.tlsInspectionPolicyId,\n \"tlsinsp\",\n );\n const location = normalizeLocation(news.location ?? output?.location, env.region);\n const name = resourceName(env.project, location, COLLECTION, tlsInspectionPolicyId);\n const ownership = yield* createInternalLabels(id);\n const desiredDescription = encodeDescription(ownership, news.description);\n const caPool = caPoolName(env.project, location, news.caPool);\n const trustConfig = trustConfigName(env.project, location, news.trustConfig);\n const excludePublicCaSet = news.excludePublicCaSet === true;\n const customTlsFeatures = news.customTlsFeatures ?? [];\n\n let current = yield* getByName(output?.name ?? name);\n\n if (current === undefined) {\n const created = yield* networksecurity\n .createProjectsLocationsTlsInspectionPolicies({\n parent: parentOf(env.project, location),\n tlsInspectionPolicyId,\n body: {\n description: desiredDescription,\n caPool,\n trustConfig,\n excludePublicCaSet,\n tlsFeatureProfile: news.tlsFeatureProfile,\n minTlsVersion: news.minTlsVersion,\n customTlsFeatures: customTlsFeatures.length > 0 ? customTlsFeatures : undefined,\n },\n })\n .pipe(\n Effect.retry({\n while: (error) => error._tag === \"Conflict\",\n times: 5,\n schedule: Schedule.spaced(\"2 seconds\"),\n }),\n Effect.catchTag(\"Conflict\", () => Effect.undefined),\n );\n if (created !== undefined) {\n yield* waitForOperation(created);\n }\n current = yield* waitUntilExists(name);\n }\n\n if (current === undefined) {\n return yield* new TlsInspectionPolicyNotResolved({ resourceName: name });\n }\n\n const descriptionChanged = (current.description ?? \"\") !== desiredDescription;\n const caPoolChanged = (current.caPool ?? \"\") !== caPool;\n const trustChanged = (current.trustConfig ?? \"\") !== (trustConfig ?? \"\");\n const excludeChanged = (current.excludePublicCaSet === true) !== excludePublicCaSet;\n const profileChanged = (current.tlsFeatureProfile ?? \"\") !== (news.tlsFeatureProfile ?? \"\");\n const minTlsChanged = (current.minTlsVersion ?? \"\") !== (news.minTlsVersion ?? \"\");\n const featuresChanged =\n !sameStringList(\n current.customTlsFeatures,\n customTlsFeatures.length > 0 ? customTlsFeatures : current.customTlsFeatures,\n ) && news.customTlsFeatures !== undefined;\n\n if (\n descriptionChanged ||\n caPoolChanged ||\n trustChanged ||\n excludeChanged ||\n profileChanged ||\n minTlsChanged ||\n featuresChanged\n ) {\n const updateMask = [\n descriptionChanged ? \"description\" : undefined,\n caPoolChanged ? \"caPool\" : undefined,\n trustChanged ? \"trustConfig\" : undefined,\n excludeChanged ? \"excludePublicCaSet\" : undefined,\n profileChanged ? \"tlsFeatureProfile\" : undefined,\n minTlsChanged ? \"minTlsVersion\" : undefined,\n featuresChanged ? \"customTlsFeatures\" : undefined,\n ].filter((field): field is string => field !== undefined);\n const operation = yield* networksecurity.patchProjectsLocationsTlsInspectionPolicies({\n name: current.name ?? name,\n updateMask: updateMask.join(\",\"),\n body: {\n name: current.name ?? name,\n description: desiredDescription,\n caPool,\n trustConfig,\n excludePublicCaSet,\n tlsFeatureProfile: news.tlsFeatureProfile,\n minTlsVersion: news.minTlsVersion,\n customTlsFeatures:\n news.customTlsFeatures !== undefined ? customTlsFeatures : current.customTlsFeatures,\n },\n });\n yield* waitForOperation(operation);\n current = yield* waitUntilExists(current.name ?? name);\n }\n\n return toAttrs(current, env.project, env.region);\n }),\n\n delete: Effect.fn(function* ({ output }) {\n const operation = yield* networksecurity\n .deleteProjectsLocationsTlsInspectionPolicies({\n name: output.name,\n force: true,\n })\n .pipe(\n Effect.retry({\n while: (error) => error._tag === \"Conflict\",\n times: 8,\n schedule: Schedule.spaced(\"2 seconds\"),\n }),\n Effect.catchTag(\"NotFound\", () => Effect.undefined),\n );\n if (operation !== undefined) {\n yield* waitForOperation(operation, { notFoundOk: true });\n }\n yield* waitUntilGone(output.name);\n }),\n });\n","preview":null,"history":null,"version":"f5dfda02a360cc2fdcfd898b709ac65bdfb9f41f"},"/_session?shell=1":null}