Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rust): improve node info displayed by commands to add services #3176

Merged
merged 1 commit into from
Aug 9, 2022
Merged
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
40 changes: 19 additions & 21 deletions implementations/rust/ockam/ockam_command/src/node/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ use clap::Args;
use ockam::Route;
use ockam_api::nodes::{models::base::NodeStatus, NODEMANAGER_ADDR};
use ockam_api::Status;
use std::{
net::{IpAddr, SocketAddr},
str::FromStr,
};

#[derive(Clone, Debug, Args)]
pub struct ShowCommand {
Expand Down Expand Up @@ -45,12 +41,7 @@ pub async fn query_status(
.context("Failed to process request")?;

let NodeStatus {
node_name,
status,
workers,
pid,
transports,
..
node_name, status, ..
} = api::parse_status(&resp)?;

// Getting short id for the node
Expand All @@ -71,24 +62,31 @@ pub async fn query_status(
};

let node_cfg = cfg.get_node(&node_name).unwrap();
let api_address = SocketAddr::new(IpAddr::from_str("127.0.0.1").unwrap(), node_cfg.port);
let (mlog, _) = cfg.log_paths_for_node(&node_name.to_string()).unwrap();
let log_path = util::print_path(&mlog);

println!(
r#"
Node:
Name: {}
Status: {}
API Address: {}
Default Identity: {}
Secure Channel Listener Address: /service/api
Pid: {}
Worker count: {}
Transport count: {}
Log Path: {}
Services:
Service:
Type: TCP Listener
Address: /ip4/127.0.0.1/tcp/{}
Service:
Type: Secure Channel Listener
Address: /service/api
Route: /ip4/127.0.0.1/tcp/{}/service/api
Identity: {}
Authorized Identities:
- {}
Service:
Type: Uppercase
Address: /service/uppercase
Service:
Type: Echo
Address: /service/echo
"#,
node_name, status, api_address, default_id, pid, workers, transports, log_path
node_name, status, node_cfg.port, node_cfg.port, default_id, default_id,
);
util::stop_node(ctx).await
}
6 changes: 1 addition & 5 deletions implementations/rust/ockam/ockam_command/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ pub use config::*;

use anyhow::Context;
use ockam::{route, NodeBuilder, Route, TcpTransport, TCP};
use std::{env, net::TcpListener, path::Path};
use std::{env, net::TcpListener};
use tracing::error;
use tracing_subscriber::prelude::*;
use tracing_subscriber::{filter::LevelFilter, fmt, EnvFilter};
Expand Down Expand Up @@ -138,7 +138,3 @@ pub fn setup_logging(verbose: u8, no_color: bool) {
eprintln!("Failed to initialise tracing logging.");
}
}

pub fn print_path(p: &Path) -> String {
p.to_str().unwrap_or("<unprintable>").to_string()
}