-
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.
- Loading branch information
1 parent
acfaf3e
commit 5290199
Showing
20 changed files
with
565 additions
and
708 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
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,45 +1,24 @@ | ||
extern crate dkregistry; | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ use base64; | |
use http; | ||
use regex; | ||
use reqwest; | ||
use serde_json; | ||
use std::{io, string}; | ||
|
||
error_chain! { | ||
|
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.