Pure identity resolution from a URL plus the configured server bindings. userinfo → server-host match (longest suffix, active wins ties) → first-label subdomain. Split from the config-loading wrapper so it can be unit-tested without a config file on disk.
(remote_url: &str, servers: &[ServerBinding])
| 183 | /// subdomain. Split from the config-loading wrapper so it can be unit-tested |
| 184 | /// without a config file on disk. |
| 185 | fn resolve_identity_from_url(remote_url: &str, servers: &[ServerBinding]) -> Option<String> { |
| 186 | let url = Url::parse(remote_url).ok()?; |
| 187 | |
| 188 | // 1. Explicit in the URL: http://bob@host/... |
| 189 | let username = url.username(); |
| 190 | if !username.is_empty() { |
| 191 | return Some(username.to_string()); |
| 192 | } |
| 193 | |
| 194 | let host = url.host_str()?; |
| 195 | |
| 196 | // 2. Configured server binding: identity follows the server (apex), so any |
| 197 | // tenant under it resolves to the same identity. |
| 198 | if let Some(identity) = match_server_identity(host, servers) { |
| 199 | return Some(identity); |
| 200 | } |
| 201 | |
| 202 | // 3. Legacy: treat the first DNS label as the identity name. |
| 203 | extract_subdomain(host) |
| 204 | } |
| 205 | |
| 206 | /// Pick the identity bound to the configured server whose host is the longest |
| 207 | /// dot-boundary suffix of `remote_host`. When several profiles' hosts match |