diff --git a/client/src/api/mod.rs b/client/src/api/mod.rs index 279e3e5..a8c17eb 100644 --- a/client/src/api/mod.rs +++ b/client/src/api/mod.rs @@ -62,6 +62,12 @@ impl ApiClient { }) } + /// Sets the API endpoint of this client. + pub fn set_endpoint(&mut self, endpoint: &str) -> Result<()> { + self.endpoint = Url::parse(endpoint)?; + Ok(()) + } + /// Returns the configuration of a cache. pub async fn get_cache_config(&self, cache: &CacheName) -> Result { let endpoint = self diff --git a/client/src/command/push.rs b/client/src/command/push.rs index 07e504c..a38482a 100644 --- a/client/src/command/push.rs +++ b/client/src/command/push.rs @@ -194,10 +194,10 @@ pub async fn run(opts: Opts) -> Result<()> { let (server_name, server, cache) = config.resolve_cache(&sub.cache)?; - let api = ApiClient::from_server_config(server.clone())?; + let mut api = ApiClient::from_server_config(server.clone())?; let plan = PushPlan::plan( store.clone(), - &api, + &mut api, cache, roots, sub.no_closure, @@ -261,7 +261,7 @@ impl PushPlan { /// Creates a plan. async fn plan( store: Arc, - api: &ApiClient, + api: &mut ApiClient, cache: &CacheName, roots: Vec, no_closure: bool, @@ -307,6 +307,11 @@ impl PushPlan { // Confirm remote cache validity, query cache config let cache_config = api.get_cache_config(cache).await?; + if let Some(api_endpoint) = &cache_config.api_endpoint { + // Use delegated API endpoint + api.set_endpoint(api_endpoint)?; + } + if !ignore_upstream_filter { // Filter out paths signed by upstream caches let upstream_cache_key_names =