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])
| 139 | /// subdomain. Split from the config-loading wrapper so it can be unit-tested |
| 140 | /// without a config file on disk. |
| 141 | fn resolve_identity_from_url(remote_url: &str, servers: &[ServerBinding]) -> Option<String> { |
| 142 | let url = Url::parse(remote_url).ok()?; |
| 143 | |
| 144 | // 1. Explicit in the URL: http://bob@host/... |
| 145 | let username = url.username(); |
| 146 | if !username.is_empty() { |
| 147 | return Some(username.to_string()); |
| 148 | } |
| 149 | |
| 150 | let host = url.host_str()?; |
| 151 | |
| 152 | // 2. Configured server binding: identity follows the server (apex), so any |
| 153 | // tenant under it resolves to the same identity. |
| 154 | if let Some(identity) = match_server_identity(host, servers) { |
| 155 | return Some(identity); |
| 156 | } |
| 157 | |
| 158 | // 3. Legacy: treat the first DNS label as the identity name. |
| 159 | extract_subdomain(host) |
| 160 | } |
| 161 | |
| 162 | /// Pick the identity bound to the configured server whose host is the longest |
| 163 | /// dot-boundary suffix of `remote_host`. When several profiles' hosts match |