Sync public tree for logout alias
This commit is contained in:
parent
22fa4fc675
commit
1c3fdfc38a
4 changed files with 55 additions and 3 deletions
|
|
@ -36,6 +36,7 @@ struct Cli {
|
|||
enum Commands {
|
||||
Doctor(DoctorArgs),
|
||||
Login(LoginArgs),
|
||||
Logout(AuthLogoutArgs),
|
||||
Auth {
|
||||
#[command(subcommand)]
|
||||
command: AuthCommands,
|
||||
|
|
@ -819,6 +820,10 @@ fn auth_status_report(args: AuthStatusArgs, cwd: PathBuf) -> Result<Value> {
|
|||
}
|
||||
|
||||
fn auth_logout_report(args: AuthLogoutArgs, cwd: PathBuf) -> Result<Value> {
|
||||
logout_report(args, cwd, "auth logout")
|
||||
}
|
||||
|
||||
fn logout_report(args: AuthLogoutArgs, cwd: PathBuf, command: &str) -> Result<Value> {
|
||||
let session_file = session_config_file(&cwd);
|
||||
let existed = session_file.exists();
|
||||
if existed {
|
||||
|
|
@ -826,7 +831,7 @@ fn auth_logout_report(args: AuthLogoutArgs, cwd: PathBuf) -> Result<Value> {
|
|||
.with_context(|| format!("failed to remove {}", session_file.display()))?;
|
||||
}
|
||||
Ok(json!({
|
||||
"command": "auth logout",
|
||||
"command": command,
|
||||
"requires_confirmation": !args.yes,
|
||||
"removed_cli_session_file": existed,
|
||||
"node_credentials_untouched": true,
|
||||
|
|
@ -2589,6 +2594,11 @@ fn run_cli() -> Result<()> {
|
|||
emit_report(&plan, json_output)?;
|
||||
}
|
||||
}
|
||||
Commands::Logout(args) => {
|
||||
let json_output = args.scope.json;
|
||||
let report = logout_report(args, std::env::current_dir()?, "logout")?;
|
||||
emit_report(&report, json_output)?;
|
||||
}
|
||||
Commands::Auth { command } => {
|
||||
let (report, json_output) = match command {
|
||||
AuthCommands::Status(args) => {
|
||||
|
|
@ -5823,6 +5833,7 @@ mod tests {
|
|||
for args in [
|
||||
&["disasmer", "doctor"][..],
|
||||
&["disasmer", "auth", "status"],
|
||||
&["disasmer", "logout", "--yes"],
|
||||
&["disasmer", "auth", "logout", "--yes"],
|
||||
&[
|
||||
"disasmer",
|
||||
|
|
@ -5876,11 +5887,42 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn top_level_logout_alias_removes_only_cli_session_state() {
|
||||
let temp = tempfile::tempdir().unwrap();
|
||||
let session_file = session_config_file(temp.path());
|
||||
fs::create_dir_all(session_file.parent().unwrap()).unwrap();
|
||||
fs::write(&session_file, br#"{"kind":"human","token":"local"}"#).unwrap();
|
||||
|
||||
let report = logout_report(
|
||||
AuthLogoutArgs {
|
||||
yes: true,
|
||||
scope: CliScopeArgs {
|
||||
coordinator: None,
|
||||
tenant: "tenant".to_owned(),
|
||||
project: "project".to_owned(),
|
||||
user: "user".to_owned(),
|
||||
json: false,
|
||||
},
|
||||
},
|
||||
temp.path().to_path_buf(),
|
||||
"logout",
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
assert_eq!(report["command"], "logout");
|
||||
assert_eq!(report["requires_confirmation"], false);
|
||||
assert_eq!(report["removed_cli_session_file"], true);
|
||||
assert_eq!(report["node_credentials_untouched"], true);
|
||||
assert!(!session_file.exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cli_first_json_mode_parses_for_primary_commands() {
|
||||
for args in [
|
||||
&["disasmer", "doctor", "--json"][..],
|
||||
&["disasmer", "login", "--json"],
|
||||
&["disasmer", "logout", "--yes", "--json"],
|
||||
&["disasmer", "auth", "status", "--json"],
|
||||
&[
|
||||
"disasmer",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue