Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions core/cli/src/args/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ pub(crate) enum ContextAction {
/// iggy context delete production
#[clap(verbatim_doc_comment, visible_alias = "d")]
Delete(ContextDeleteArgs),

/// Show details of a specific context
///
/// Displays the full configuration of a named context including
/// transport, server addresses, TLS settings, and credentials.
///
/// Examples
/// iggy context show default
/// iggy context show production
#[clap(verbatim_doc_comment, visible_alias = "s")]
Show(ContextShowArgs),
}

#[derive(Debug, Clone, Args)]
Expand Down Expand Up @@ -148,6 +159,13 @@ pub(crate) struct ContextDeleteArgs {
pub(crate) context_name: String,
}

#[derive(Debug, Clone, Args)]
pub(crate) struct ContextShowArgs {
/// Name of the context to show
#[arg(value_parser = clap::value_parser!(String))]
pub(crate) context_name: String,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
10 changes: 10 additions & 0 deletions core/cli/src/args/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ use crate::args::{
#[cfg(feature = "login-session")]
use crate::args::system::LoginArgs;

#[cfg(feature = "login-session")]
use crate::args::session::SessionAction;

use self::user::UserAction;

pub(crate) mod client;
Expand All @@ -63,6 +66,9 @@ pub(crate) mod system;
pub(crate) mod topic;
pub(crate) mod user;

#[cfg(feature = "login-session")]
pub(crate) mod session;

static CARGO_BIN_NAME: &str = env!("CARGO_BIN_NAME");
static CARGO_PKG_HOMEPAGE: &str = env!("CARGO_PKG_HOMEPAGE");

Expand Down Expand Up @@ -206,6 +212,10 @@ pub(crate) enum Command {
/// execute any command that requires authentication.
#[clap(verbatim_doc_comment, visible_alias = "lo")]
Logout,
#[cfg(feature = "login-session")]
/// login session operations
#[command(subcommand, visible_alias = "sess")]
Session(SessionAction),
}

impl IggyConsoleArgs {
Expand Down
33 changes: 33 additions & 0 deletions core/cli/src/args/session.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use clap::Subcommand;

#[derive(Debug, Clone, Subcommand)]
pub(crate) enum SessionAction {
/// Show current login session status
///
/// Displays whether you have an active login session and which
/// server it is connected to. This checks the local credential
/// store without contacting the server.
///
/// Examples
/// iggy session status
#[clap(verbatim_doc_comment, visible_alias = "s")]
Status,
}
1 change: 1 addition & 0 deletions core/cli/src/commands/binary_context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ pub mod common;
pub mod create_context;
pub mod delete_context;
pub mod get_contexts;
pub mod show_context;
pub mod use_context;
114 changes: 114 additions & 0 deletions core/cli/src/commands/binary_context/show_context.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use anyhow::bail;
use async_trait::async_trait;
use comfy_table::Table;
use tracing::{Level, event};

use crate::commands::cli_command::{CliCommand, PRINT_TARGET};
use iggy_common::Client;

use super::common::{ContextConfig, ContextManager};

const MASKED_VALUE: &str = "********";

pub struct ShowContextCmd {
context_name: String,
}

impl ShowContextCmd {
pub fn new(context_name: String) -> Self {
Self { context_name }
}

fn build_table(name: &str, is_active: bool, config: &ContextConfig) -> Table {
let mut table = Table::new();
table.set_header(vec!["Property", "Value"]);

let display_name = if is_active {
format!("{name}*")
} else {
name.to_string()
};
table.add_row(vec!["Name", &display_name]);

if let Some(ref transport) = config.iggy.transport {
table.add_row(vec!["Transport", transport]);
}
if let Some(ref addr) = config.iggy.tcp_server_address {
table.add_row(vec!["TCP Server Address", addr]);
}
if let Some(ref url) = config.iggy.http_api_url {
table.add_row(vec!["HTTP API URL", url]);
}
if let Some(ref addr) = config.iggy.quic_server_address {
table.add_row(vec!["QUIC Server Address", addr]);
}
if let Some(tls) = config.iggy.tcp_tls_enabled {
table.add_row(vec!["TCP TLS Enabled", &tls.to_string()]);
}
if let Some(ref username) = config.username {
table.add_row(vec!["Username", username]);
}
if config.password.is_some() {
table.add_row(vec!["Password", MASKED_VALUE]);
}
if config.token.is_some() {
table.add_row(vec!["Token", MASKED_VALUE]);
}
if let Some(ref token_name) = config.token_name {
table.add_row(vec!["Token Name", token_name]);
}

table
}
}

#[async_trait]
impl CliCommand for ShowContextCmd {
fn explain(&self) -> String {
format!("show context \"{}\"", self.context_name)
}

fn login_required(&self) -> bool {
false
}

fn connection_required(&self) -> bool {
false
}

async fn execute_cmd(&mut self, _client: &dyn Client) -> anyhow::Result<(), anyhow::Error> {
let mut context_mgr = ContextManager::default();
let contexts_map = context_mgr.get_contexts().await?;
let active_context_key = context_mgr.get_active_context_key().await?;

let config = match contexts_map.get(&self.context_name) {
Some(config) => config,
None => bail!("context '{}' not found", self.context_name),
};

let is_active = self.context_name == active_context_key;
let table = Self::build_table(&self.context_name, is_active, config);

event!(target: PRINT_TARGET, Level::INFO, "{table}");

Ok(())
}
}
1 change: 1 addition & 0 deletions core/cli/src/commands/binary_system/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ pub mod logout;
pub mod me;
pub mod ping;
pub mod session;
pub mod session_status;
pub mod snapshot;
pub mod stats;
70 changes: 70 additions & 0 deletions core/cli/src/commands/binary_system/session_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

use crate::commands::binary_system::session::ServerSession;
use crate::commands::cli_command::{CliCommand, PRINT_TARGET};
use async_trait::async_trait;
use comfy_table::Table;
use iggy_common::Client;
use tracing::{Level, event};

pub struct SessionStatusCmd {
server_session: ServerSession,
}

impl SessionStatusCmd {
pub fn new(server_address: String) -> Self {
Self {
server_session: ServerSession::new(server_address),
}
}
}

#[async_trait]
impl CliCommand for SessionStatusCmd {
fn explain(&self) -> String {
"session status command".to_owned()
}

fn login_required(&self) -> bool {
false
}

fn connection_required(&self) -> bool {
false
}

async fn execute_cmd(&mut self, _client: &dyn Client) -> anyhow::Result<(), anyhow::Error> {
let is_active = self.server_session.is_active();
let server_address = self.server_session.get_server_address();

let mut table = Table::new();
table.set_header(vec!["Property", "Value"]);
table.add_row(vec!["Server Address", server_address]);

if is_active {
table.add_row(vec!["Session Active", "Yes"]);
} else {
table.add_row(vec!["Session Active", "No"]);
}

event!(target: PRINT_TARGET, Level::INFO, "{table}");

Ok(())
}
}
12 changes: 12 additions & 0 deletions core/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use iggy::prelude::{Aes256GcmEncryptor, Args, EncryptorKind, PersonalAccessToken
use iggy_cli::commands::binary_context::common::ContextManager;
use iggy_cli::commands::binary_context::create_context::CreateContextCmd;
use iggy_cli::commands::binary_context::delete_context::DeleteContextCmd;
use iggy_cli::commands::binary_context::show_context::ShowContextCmd;
use iggy_cli::commands::binary_context::use_context::UseContextCmd;
use iggy_cli::commands::binary_segments::delete_segments::DeleteSegmentsCmd;
use iggy_cli::commands::binary_system::snapshot::GetSnapshotCmd;
Expand Down Expand Up @@ -95,6 +96,8 @@ use tracing::{Level, event};

#[cfg(feature = "login-session")]
mod main_login_session {
pub(crate) use crate::args::session::SessionAction;
pub(crate) use iggy_cli::commands::binary_system::session_status::SessionStatusCmd;
pub(crate) use iggy_cli::commands::binary_system::{login::LoginCmd, logout::LogoutCmd};
pub(crate) use iggy_cli::commands::utils::login_session_expiry::LoginSessionExpiry;
}
Expand Down Expand Up @@ -337,6 +340,9 @@ fn get_command(
ContextAction::Delete(delete_args) => {
Box::new(DeleteContextCmd::new(delete_args.context_name.clone()))
}
ContextAction::Show(show_args) => {
Box::new(ShowContextCmd::new(show_args.context_name.clone()))
}
},
#[cfg(feature = "login-session")]
Command::Login(login_args) => Box::new(LoginCmd::new(
Expand All @@ -345,6 +351,12 @@ fn get_command(
)),
#[cfg(feature = "login-session")]
Command::Logout => Box::new(LogoutCmd::new(iggy_args.get_server_address().unwrap())),
#[cfg(feature = "login-session")]
Command::Session(command) => match command {
SessionAction::Status => Box::new(SessionStatusCmd::new(
iggy_args.get_server_address().unwrap(),
)),
},
}
}

Expand Down
1 change: 1 addition & 0 deletions core/integration/tests/cli/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ mod test_context_applied;
mod test_context_create_command;
mod test_context_delete_command;
mod test_context_list_command;
mod test_context_show_command;
mod test_context_use_command;
Loading
Loading