generated from coulomb/repo-seed
feat: add deployment zone overlays
This commit is contained in:
@@ -15,6 +15,7 @@ import yaml
|
||||
|
||||
from .canon import edge_canon_mapping, evidence_state_for, node_canon_mapping, source_kind_from_anchor
|
||||
from .connectors import ConnectorConfig, apply_connectors
|
||||
from .deployment_overlay import normalize_deployment_overlay
|
||||
from .discovery import (
|
||||
attribute_stable_key,
|
||||
discovery_stable_key,
|
||||
@@ -1146,6 +1147,22 @@ def _add_runtime_endpoint(
|
||||
if not host or port_number is None:
|
||||
return ""
|
||||
|
||||
runtime_attributes = {
|
||||
"host": host,
|
||||
"runtime_target_type": server_type,
|
||||
**(attributes or {}),
|
||||
}
|
||||
overlay = _runtime_deployment_overlay(
|
||||
host=host,
|
||||
port=port_number,
|
||||
protocol=protocol_value,
|
||||
domain=domain,
|
||||
server_type=server_type,
|
||||
attributes=runtime_attributes,
|
||||
)
|
||||
if overlay:
|
||||
runtime_attributes["deployment_overlay"] = overlay
|
||||
|
||||
target_kind = _runtime_target_kind(host, server_type)
|
||||
target_key = discovery_stable_key(context.repo_slug, target_kind, host)
|
||||
context.accumulator.add_node(
|
||||
@@ -1156,11 +1173,7 @@ def _add_runtime_endpoint(
|
||||
provenance=provenance,
|
||||
source_anchor=anchor,
|
||||
aliases=[host],
|
||||
attributes={
|
||||
"host": host,
|
||||
"runtime_target_type": server_type,
|
||||
**(attributes or {}),
|
||||
},
|
||||
attributes=runtime_attributes,
|
||||
confidence=confidence,
|
||||
)
|
||||
|
||||
@@ -1175,10 +1188,9 @@ def _add_runtime_endpoint(
|
||||
source_anchor=anchor,
|
||||
aliases=[port_label],
|
||||
attributes={
|
||||
"host": host,
|
||||
"port": port_number,
|
||||
"protocol": protocol_value,
|
||||
**(attributes or {}),
|
||||
**runtime_attributes,
|
||||
},
|
||||
confidence=confidence,
|
||||
)
|
||||
@@ -1333,6 +1345,79 @@ def _add_domain_route(
|
||||
)
|
||||
|
||||
|
||||
def _runtime_deployment_overlay(
|
||||
*,
|
||||
host: str,
|
||||
port: int,
|
||||
protocol: str,
|
||||
domain: str,
|
||||
server_type: str,
|
||||
attributes: dict[str, object],
|
||||
) -> dict[str, Any]:
|
||||
source = str(attributes.get("source") or server_type or "").strip()
|
||||
overlay: dict[str, Any] = {
|
||||
"routing_authority": _routing_authority(source, server_type),
|
||||
"route_evidence": {
|
||||
"host": host,
|
||||
"hostname": _normalize_domain(domain) or host,
|
||||
"port": port,
|
||||
"protocol": protocol,
|
||||
"route": str(attributes.get("endpoint_url") or domain or host),
|
||||
"scheme": attributes.get("scheme", ""),
|
||||
},
|
||||
}
|
||||
if _is_loopback_host(host):
|
||||
overlay.update(
|
||||
{
|
||||
"deployment_environment": "dev",
|
||||
"deployment_scenario": "bernd-laptop",
|
||||
"access_zone": "private-dev",
|
||||
"policy_authority": "local-loopback-binding",
|
||||
"exposure_class": "local-only",
|
||||
}
|
||||
)
|
||||
elif _mentions_scenario(host, domain, "coulombcore"):
|
||||
overlay.update(
|
||||
{
|
||||
"deployment_environment": "test",
|
||||
"deployment_scenario": "coulombcore",
|
||||
"access_zone": "collaborator-test",
|
||||
"exposure_class": "collaborator-test",
|
||||
}
|
||||
)
|
||||
elif _mentions_scenario(host, domain, "railiance01"):
|
||||
overlay.update(
|
||||
{
|
||||
"deployment_environment": "prod",
|
||||
"deployment_scenario": "railiance01",
|
||||
"access_zone": "production-public" if _looks_like_domain(domain or host) else "production-admin",
|
||||
"exposure_class": "production-public" if _looks_like_domain(domain or host) else "production-admin",
|
||||
}
|
||||
)
|
||||
return normalize_deployment_overlay(overlay)
|
||||
|
||||
|
||||
def _routing_authority(source: str, server_type: str) -> str:
|
||||
source_value = source.strip().lower()
|
||||
if source_value == "docker-compose":
|
||||
return "docker-compose"
|
||||
if source_value.startswith("kubernetes-") or server_type == "kubernetes-service-dns":
|
||||
return "kubernetes"
|
||||
if server_type == "declared-endpoint":
|
||||
return "declared-endpoint"
|
||||
return source_value or server_type
|
||||
|
||||
|
||||
def _is_loopback_host(host: str) -> bool:
|
||||
value = _normalize_host(host)
|
||||
return value in {"localhost", "127.0.0.1", "::1"}
|
||||
|
||||
|
||||
def _mentions_scenario(host: str, domain: str, scenario: str) -> bool:
|
||||
needle = scenario.strip().lower()
|
||||
return needle in _normalize_host(host) or needle in _normalize_domain(domain)
|
||||
|
||||
|
||||
def _compose_port_bindings(service: dict[str, Any]) -> list[dict[str, object]]:
|
||||
ports = service.get("ports")
|
||||
if not isinstance(ports, list):
|
||||
|
||||
Reference in New Issue
Block a user