client/push: Correctly delegate API requests based on cache config
This commit is contained in:
parent
05a5e9cca8
commit
d547c86f08
|
@ -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<CacheConfig> {
|
||||
let endpoint = self
|
||||
|
|
|
@ -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<NixStore>,
|
||||
api: &ApiClient,
|
||||
api: &mut ApiClient,
|
||||
cache: &CacheName,
|
||||
roots: Vec<StorePath>,
|
||||
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 =
|
||||
|
|
Loading…
Reference in a new issue