1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//! `offline login` / `logout` / `whoami`: device-flow auth (see docs/AUTH.md).
use anyhow::Result;
use clap::Args;
use crate::auth::login::{LoginOptions, LogoutOptions, WhoamiOptions};
#[derive(Args)]
pub struct LoginArgs {
/// Sign in with an application API key instead of a developer session. For CI only: it
/// can't run `offline setup`, `orgs`, `apps` or `keys`.
#[arg(long)]
pub api_key: Option<String>,
/// Sign in with an emailed code instead of the browser, for SSH and agents. Pass an address or
/// omit the value to be prompted. You get the same developer session as the browser login.
#[arg(long, conflicts_with = "no_browser", num_args = 0..=1, default_missing_value = "")]
pub email: Option<String>,
/// The code from the email, to finish `--email` without a prompt. Without a terminal,
/// `offline login --email you@example.com` sends the code and exits; rerun with `--code`.
#[arg(long, requires = "email")]
pub code: Option<String>,
/// Don't open a browser; print the developer portal URL to complete login (same session as the browser login)
#[arg(long, conflicts_with = "email")]
pub no_browser: bool,
}
#[derive(Args)]
pub struct LogoutArgs {
/// Only clear local credentials; skip server-side key revocation
#[arg(long)]
pub local_only: bool,
}
#[derive(Args)]
pub struct WhoamiArgs {
/// Output JSON
#[arg(long)]
pub json: bool,
/// Validate the stored API key and app id against the developer API
#[arg(long)]
pub verify: bool,
}
pub async fn login(args: LoginArgs) -> Result<()> {
crate::auth::login::run_login(LoginOptions {
api_key: args.api_key,
email: args.email,
code: args.code,
no_browser: args.no_browser,
})
.await
}
pub async fn logout(args: LogoutArgs) -> Result<()> {
crate::auth::login::run_logout(LogoutOptions {
local_only: args.local_only,
})
.await
}
pub async fn whoami(args: WhoamiArgs) -> Result<()> {
crate::auth::login::run_whoami(WhoamiOptions {
json: args.json,
verify: args.verify,
})
.await
}