-
Notifications
You must be signed in to change notification settings - Fork 206
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
Showing
2 changed files
with
63 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use clap::Parser; | ||
use rattler_networking::{Authentication, AuthenticationStorage}; | ||
|
||
// use crate::auth::{default_authentication_storage, listen_and_open_browser}; | ||
|
||
fn default_authentication_storage() -> AuthenticationStorage { | ||
AuthenticationStorage::new("rattler", &dirs::home_dir().unwrap().join(".rattler")) | ||
} | ||
|
||
/// Adds a dependency to the project | ||
#[derive(Parser, Debug)] | ||
pub struct Args { | ||
/// The host to authenticate with | ||
host: String, | ||
|
||
/// The token to use (for bearer authentication) | ||
#[clap(long)] | ||
token: Option<String>, | ||
|
||
/// The username to use (for basic authentication) | ||
#[clap(long)] | ||
username: Option<String>, | ||
|
||
/// The password to use (for basic authentication) | ||
#[clap(long)] | ||
password: Option<String>, | ||
|
||
/// The token to use on anaconda.org style authentication | ||
#[clap(long)] | ||
conda_token: Option<String>, | ||
} | ||
|
||
pub async fn execute(args: Args) -> anyhow::Result<()> { | ||
let storage = default_authentication_storage(); | ||
|
||
|
||
if let Some(conda_token) = args.conda_token { | ||
let auth = Authentication::CondaToken(conda_token); | ||
storage.store(&args.host, &auth)?; | ||
return Ok(()) | ||
} | ||
else if let Some(username) = args.username { | ||
if args.password.is_none() { | ||
anyhow::bail!("Password must be provided when using basic authentication"); | ||
} | ||
|
||
let password = args.password.unwrap(); | ||
let auth = Authentication::BasicHTTP{username, password}; | ||
storage.store(&args.host, &auth)?; | ||
return Ok(()) | ||
} | ||
else if let Some(token) = args.token { | ||
let auth = Authentication::BearerToken(token); | ||
storage.store(&args.host, &auth)?; | ||
return Ok(()) | ||
} | ||
else { | ||
anyhow::bail!("No authentication method provided"); | ||
} | ||
} |
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