hubcio commented on code in PR #3096: URL: https://github.com/apache/iggy/pull/3096#discussion_r3161316503
########## core/cli/src/commands/binary_system/session_status.rs: ########## @@ -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(()) + } +} Review Comment: same gap as `show_context.rs` - no unit tests for `explain` / `login_required` / `connection_required`. mirror `delete_context.rs:67-83`. ########## core/cli/src/commands/binary_context/show_context.rs: ########## @@ -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(()) + } +} Review Comment: missing tests covering `explain` / `login_required` / `connection_required`. sibling `delete_context.rs:67-83` has the pattern. ########## core/cli/src/commands/binary_context/show_context.rs: ########## @@ -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]); + } Review Comment: only displays the subset of `ArgsOptional` matching `ContextCreateArgs` flags. drops `config.extra` (BTreeMap of preserved unknown TOML keys, see `common.rs:54-55` and the round-trip test `common.rs:734-756`), `tcp_tls_domain`, `tcp_reconnection_*`, `http_retries`, `websocket_server_address`, all `quic_*` tuning fields, `encryption_key`, `credentials_username` / `credentials_password`. doc at `args/context.rs:67` claims "full configuration" - promise not kept. either iterate `extra` and append the remaining `iggy.*` fields, or trim the doc to match implementation. ########## core/cli/src/commands/binary_context/show_context.rs: ########## @@ -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) Review Comment: quotes the name: `format!("show context \"{}\"", ...)`. siblings `delete_context.rs:41`, `use_context.rs`, `create_context.rs` use unquoted form (`"delete context {context_name}"`). pick one. ########## core/cli/src/commands/binary_system/session_status.rs: ########## @@ -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(); Review Comment: `is_active()` (`session.rs:45-51`) only checks whether the keyring entry exists. a stale or expired token still reports Active=Yes. either note this in the command output (e.g. "Session Active: Yes (token freshness not verified)") or document the limitation in the command's doc comment. ########## core/integration/tests/cli/context/test_context_show_command.rs: ########## @@ -0,0 +1,274 @@ +/* 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 std::collections::BTreeMap; + +use crate::cli::common::{ + CLAP_INDENT, IggyCmdCommand, IggyCmdTest, IggyCmdTestCase, TestHelpCmd, USAGE_PREFIX, +}; +use assert_cmd::assert::Assert; +use async_trait::async_trait; +use iggy::prelude::Client; +use iggy_cli::commands::binary_context::common::ContextConfig; +use iggy_common::ArgsOptional; +use predicates::str::contains; +use serial_test::parallel; + +use super::common::TestIggyContext; + +struct TestContextShowCmd { + test_iggy_context: TestIggyContext, + context_to_show: String, + expected_fields: Vec<(String, String)>, +} + +impl TestContextShowCmd { + fn new( + test_iggy_context: TestIggyContext, + context_to_show: String, + expected_fields: Vec<(String, String)>, + ) -> Self { + Self { + test_iggy_context, + context_to_show, + expected_fields, + } + } +} + +#[async_trait] +impl IggyCmdTestCase for TestContextShowCmd { + async fn prepare_server_state(&mut self, _client: &dyn Client) { + self.test_iggy_context.prepare().await; + } + + fn get_command(&self) -> IggyCmdCommand { + IggyCmdCommand::new() + .env( + "IGGY_HOME", + self.test_iggy_context.get_iggy_home().to_str().unwrap(), + ) + .arg("context") + .arg("show") + .arg(self.context_to_show.clone()) + .with_env_credentials() + } + + fn verify_command(&self, command_state: Assert) { + let mut command_state = command_state.success(); + + for (key, value) in &self.expected_fields { + command_state = command_state + .stdout(contains(key.as_str())) + .stdout(contains(value.as_str())); + } Review Comment: asserts `key` and `value` substrings independently. the test passes even if the table renders rows in mismatched order (e.g. "Username" appearing without its value, or vice versa). use a row-aware predicate or a single combined substring like `"Username | admin"`. ########## core/cli/src/commands/binary_system/session_status.rs: ########## @@ -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"]); + } Review Comment: duplicates the `add_row` call. collapse to: ```rust let active = if is_active { "Yes" } else { "No" }; table.add_row(vec!["Session Active", active]); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
