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])
| 165 | /// subdomain. Split from the config-loading wrapper so it can be unit-tested |
| 166 | /// without a config file on disk. |
| 167 | fn resolve_identity_from_url(remote_url: &str, servers: &[ServerBinding]) -> Option<String> { |
| 168 | let url = Url::parse(remote_url).ok()?; |
| 169 | |
| 170 | // 1. Explicit in the URL: http://bob@host/... |
| 171 | let username = url.username(); |
| 172 | if !username.is_empty() { |
| 173 | return Some(username.to_string()); |
| 174 | } |
| 175 | |
| 176 | let host = url.host_str()?; |
| 177 | |
| 178 | // 2. Configured server binding: identity follows the server (apex), so any |
| 179 | // tenant under it resolves to the same identity. |
| 180 | if let Some(identity) = match_server_identity(host, servers) { |
| 181 | return Some(identity); |
| 182 | } |
| 183 | |
| 184 | // 3. Legacy: treat the first DNS label as the identity name. |
| 185 | extract_subdomain(host) |
| 186 | } |
| 187 | |
| 188 | /// Pick the identity bound to the configured server whose host is the longest |
| 189 | /// dot-boundary suffix of `remote_host`. When several profiles' hosts match |