|
13 | 13 | from ..const import ( |
14 | 14 | CONF_COLLECTOR_CLOUD_FAMILY, |
15 | 15 | CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT, |
| 16 | + CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT_OBSERVED_AT, |
16 | 17 | CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT_PROFILE_KEY, |
| 18 | + CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT_SOURCE, |
17 | 19 | CONF_DRIVER_HINT, |
18 | 20 | DRIVER_HINT_AUTO, |
19 | 21 | ) |
|
24 | 26 | resolve_collector_cloud_raw_passthrough_min_interval_ms, |
25 | 27 | resolve_collector_cloud_session_protocol, |
26 | 28 | ) |
27 | | -from .cloud_family import collector_cloud_family_observation_from_endpoint |
| 29 | +from .cloud_family import ( |
| 30 | + COLLECTOR_CLOUD_FAMILY_SOURCE_ENDPOINT_HOST, |
| 31 | + CollectorCloudFamilyObservation, |
| 32 | + collector_cloud_family_observation_from_endpoint, |
| 33 | + collector_cloud_family_observation_from_mapping, |
| 34 | + select_preferred_collector_cloud_family, |
| 35 | +) |
28 | 36 | from .capabilities import ( |
29 | 37 | COLLECTOR_KIND_ENTRY_KEY, |
30 | 38 | COLLECTOR_KIND_ESP_EYBOND_BRIDGE, |
@@ -118,34 +126,69 @@ def collector_cloud_family_from_entry_context( |
118 | 126 | options: Mapping[str, object], |
119 | 127 | *, |
120 | 128 | extra_endpoints: tuple[object, ...] = (), |
| 129 | + extra_observations: tuple[CollectorCloudFamilyObservation, ...] = (), |
121 | 130 | ) -> str: |
122 | 131 | """Resolve collector cloud family from durable and runtime entry context.""" |
123 | 132 |
|
124 | | - for source in (data, options): |
125 | | - family = known_collector_cloud_family(source.get(CONF_COLLECTOR_CLOUD_FAMILY, "")) |
126 | | - if family: |
127 | | - return family |
| 133 | + return known_collector_cloud_family( |
| 134 | + collector_cloud_family_observation_from_entry_context( |
| 135 | + data, options, |
| 136 | + extra_endpoints=extra_endpoints, |
| 137 | + extra_observations=extra_observations, |
| 138 | + ).family |
| 139 | + ) |
128 | 140 |
|
129 | | - for source in (options, data): |
130 | | - family = known_collector_cloud_family( |
131 | | - source.get(CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT_PROFILE_KEY, "") |
132 | | - ) |
133 | | - if family: |
134 | | - return family |
135 | 141 |
|
136 | | - for endpoint in extra_endpoints: |
137 | | - family = _known_family_from_endpoint(endpoint) |
138 | | - if family: |
139 | | - return family |
| 142 | +def collector_cloud_family_observation_from_entry_context( |
| 143 | + data: Mapping[str, object], |
| 144 | + options: Mapping[str, object], |
| 145 | + *, |
| 146 | + extra_endpoints: tuple[object, ...] = (), |
| 147 | + extra_observations: tuple[CollectorCloudFamilyObservation, ...] = (), |
| 148 | +) -> CollectorCloudFamilyObservation: |
| 149 | + """Resolve cloud identity without confusing a local route with a provider. |
| 150 | +
|
| 151 | + A current known cloud host wins over the remembered host. Local endpoints, |
| 152 | + shared ports and wire sniffing cannot replace either. Preserve the original |
| 153 | + endpoint as one record: data owns it, options is only a legacy fallback. |
| 154 | + This projection never chooses or confirms a session's wire protocol. |
| 155 | + """ |
140 | 156 |
|
141 | | - for source in (options, data): |
142 | | - family = _known_family_from_endpoint( |
143 | | - source.get(CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT, "") |
| 157 | + original_fields = ( |
| 158 | + CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT, |
| 159 | + CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT_PROFILE_KEY, |
| 160 | + CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT_SOURCE, |
| 161 | + CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT_OBSERVED_AT, |
| 162 | + ) |
| 163 | + original = data if any(key in data for key in original_fields) else options |
| 164 | + endpoint_observations = tuple( |
| 165 | + collector_cloud_family_observation_from_endpoint(endpoint) |
| 166 | + for endpoint in ( |
| 167 | + *extra_endpoints, |
| 168 | + original.get(CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT, ""), |
144 | 169 | ) |
145 | | - if family: |
146 | | - return family |
| 170 | + ) |
| 171 | + for observation in (*endpoint_observations, *extra_observations): |
| 172 | + if ( |
| 173 | + observation.source == COLLECTOR_CLOUD_FAMILY_SOURCE_ENDPOINT_HOST |
| 174 | + and known_collector_cloud_family(observation.family) |
| 175 | + ): |
| 176 | + return observation |
| 177 | + |
| 178 | + original_family = known_collector_cloud_family( |
| 179 | + original.get(CONF_COLLECTOR_ORIGINAL_SERVER_ENDPOINT_PROFILE_KEY, "") |
| 180 | + ) |
| 181 | + if original_family: |
| 182 | + return CollectorCloudFamilyObservation(family=original_family) |
147 | 183 |
|
148 | | - return "" |
| 184 | + durable_observations = tuple( |
| 185 | + collector_cloud_family_observation_from_mapping(source) |
| 186 | + for source in (data, options) |
| 187 | + ) |
| 188 | + for observation in (*extra_observations, *durable_observations): |
| 189 | + if known_collector_cloud_family(observation.family): |
| 190 | + return observation |
| 191 | + return select_preferred_collector_cloud_family(*endpoint_observations) |
149 | 192 |
|
150 | 193 |
|
151 | 194 | def resolve_collector_transport_profile( |
@@ -300,8 +343,3 @@ def resolve_collector_transport_profile_from_entry_context( |
300 | 343 | runtime_owner_key=runtime_owner_key, |
301 | 344 | virtual_bridge=entry_context_is_virtual_bridge(data, options), |
302 | 345 | ) |
303 | | - |
304 | | - |
305 | | -def _known_family_from_endpoint(endpoint: object) -> str: |
306 | | - observation = collector_cloud_family_observation_from_endpoint(endpoint) |
307 | | - return known_collector_cloud_family(observation.family) |
|
0 commit comments