-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt to bumped dependencies and use async/await
* async/await * Apply cargo fmt
- Loading branch information
1 parent
b5404d8
commit 2d6b579
Showing
24 changed files
with
554 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,23 @@ | ||
extern crate futures; | ||
|
||
use futures::prelude::*; | ||
|
||
pub fn authenticate_client( | ||
pub async fn authenticate_client( | ||
mut client: dkregistry::v2::Client, | ||
login_scope: String, | ||
) -> impl Future<Item = dkregistry::v2::Client, Error = dkregistry::errors::Error> { | ||
futures::future::ok::<_, dkregistry::errors::Error>(client.clone()) | ||
.and_then(|dclient| { | ||
dclient.is_v2_supported().and_then(|v2_supported| { | ||
if !v2_supported { | ||
Err("API v2 not supported".into()) | ||
} else { | ||
Ok(dclient) | ||
} | ||
}) | ||
}) | ||
.and_then(|dclient| { | ||
dclient.is_auth(None).and_then(move |is_auth| { | ||
if is_auth { | ||
Ok(dclient) | ||
} else { | ||
Err("login required".into()) | ||
} | ||
}) | ||
}) | ||
.or_else(move |_| { | ||
client | ||
.login(&[login_scope.as_str()]) | ||
.and_then(move |token| { | ||
client | ||
.is_auth(Some(token.token())) | ||
.and_then(move |is_auth| { | ||
if !is_auth { | ||
Err("login failed".into()) | ||
} else { | ||
println!("logged in!"); | ||
Ok(client.set_token(Some(token.token())).clone()) | ||
} | ||
}) | ||
}) | ||
}) | ||
) -> Result<dkregistry::v2::Client, dkregistry::errors::Error> { | ||
if !client.is_v2_supported().await? { | ||
return Err("API v2 not supported".into()); | ||
} | ||
|
||
if client.is_auth(None).await? { | ||
return Ok(client); | ||
} | ||
|
||
let token = client.login(&[login_scope.as_str()]).await?; | ||
|
||
if !client.is_auth(Some(token.token())).await? { | ||
Err("login failed".into()) | ||
} else { | ||
println!("logged in!"); | ||
Ok(client.set_token(Some(token.token())).clone()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.