Skip to content

Commit

Permalink
Fix Client::call
Browse files Browse the repository at this point in the history
  • Loading branch information
termoshtt committed Jun 3, 2024
1 parent e2f3014 commit 4574279
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions ocipkg/src/distribution/client.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::distribution::*;
use anyhow::Result;
use anyhow::{bail, ensure, Context, Result};

Check failure on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / clippy

unused imports: `Context`, `bail`

error: unused imports: `Context`, `bail` --> ocipkg/src/distribution/client.rs:2:14 | 2 | use anyhow::{bail, ensure, Context, Result}; | ^^^^ ^^^^^^^ | = note: `-D unused-imports` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(unused_imports)]`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / doc

unused imports: `Context`, `bail`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / test

unused imports: `Context`, `bail`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / with-registry

unused imports: `Context`, `bail`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / get

unused imports: `Context`, `bail`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / pack

unused imports: `Context`, `bail`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / rust-lib

unused imports: `Context`, `bail`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / push

unused imports: `Context`, `bail`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / cpp-lib

unused imports: `Context`, `bail`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / load

unused imports: `Context`, `bail`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / rust-exe

unused imports: `Context`, `bail`

Check warning on line 2 in ocipkg/src/distribution/client.rs

View workflow job for this annotation

GitHub Actions / rust-exe

unused imports: `Context`, `bail`
use oci_spec::{distribution::*, image::*};
use url::Url;

Expand Down Expand Up @@ -37,20 +37,22 @@ impl Client {
}

fn call(&mut self, req: ureq::Request) -> Result<ureq::Response> {
if let Some(token) = &self.token {
return Ok(req
.set("Authorization", &format!("Bearer {}", token))
.call()?);
if self.token.is_none() {
// Try get token
let try_req = req.clone();
let challenge = match try_req.call() {
Ok(res) => return Ok(res),
Err(e) => AuthChallenge::try_from(e)?,
};
self.token = Some(self.auth.challenge(&challenge)?);
}

// Try get token
let try_req = req.clone();
let challenge = match try_req.call() {
Ok(res) => return Ok(res),
Err(e) => AuthChallenge::try_from(e)?,
};
self.token = Some(self.auth.challenge(&challenge)?);
self.call(req)
ensure!(self.token.is_some());
Ok(req
.set(
"Authorization",
&format!("Bearer {}", self.token.as_ref().unwrap()),
)
.call()?)
}

fn get(&self, url: &Url) -> ureq::Request {
Expand Down

0 comments on commit 4574279

Please sign in to comment.