Resolve all ambient configuration only at the trusted local boundary.
(
&self,
repository: &crate::atomic::RepositoryRef,
remote: &str,
identity: Option<String>,
push: bool,
)
| 426 | |
| 427 | /// Resolve all ambient configuration only at the trusted local boundary. |
| 428 | async fn sync_credentials( |
| 429 | &self, |
| 430 | repository: &crate::atomic::RepositoryRef, |
| 431 | remote: &str, |
| 432 | identity: Option<String>, |
| 433 | push: bool, |
| 434 | ) -> Result<(String, String, HttpRemoteConfig), Status> { |
| 435 | let handle = self.state.resolve(repository)?; |
| 436 | let remote = (!remote.is_empty()).then(|| remote.to_owned()); |
| 437 | let runtime = tokio::runtime::Handle::current(); |
| 438 | tokio::task::spawn_blocking(move || { |
| 439 | let repo = handle.repository_readonly()?; |
| 440 | let name = remote.unwrap_or_else(|| { |
| 441 | repo.get_default_remote() |
| 442 | .map(|(name, _)| name) |
| 443 | .unwrap_or_else(|_| "origin".to_owned()) |
| 444 | }); |
| 445 | let url = if name.contains("://") { |
| 446 | name.clone() |
| 447 | } else { |
| 448 | repo.get_remote(&name) |
| 449 | .map_err(|error| match error { |
| 450 | atomic_repository::RepositoryError::RemoteNotFound { .. } => { |
| 451 | crate::daemon::state::domain_status( |
| 452 | crate::atomic::ErrorCode::NotFound, |
| 453 | format!("remote '{name}' not found"), |
| 454 | ) |
| 455 | } |
| 456 | other => repository_error(other), |
| 457 | })? |
| 458 | .url |
| 459 | }; |
| 460 | if push { |
| 461 | auth::check_push_credentials(&url, identity.as_deref()).map_err(auth_status)?; |
| 462 | } |
| 463 | drop(repo); |
| 464 | let config = runtime.block_on(auth::attach_identity( |
| 465 | HttpRemoteConfig::new(), |
| 466 | &url, |
| 467 | identity.as_deref(), |
| 468 | )); |
| 469 | Ok::<_, Status>((name, url, config)) |
| 470 | }) |
| 471 | .await |
| 472 | .map_err(|e| Status::internal(format!("credentials task failed: {e}")))? |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | fn reject_transport_credentials( |
no test coverage detected