Skip to content

Commit

Permalink
refactor(rust): revert command features
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbenavides committed Jan 20, 2025
1 parent ae36b80 commit b80f016
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 257 deletions.
5 changes: 1 addition & 4 deletions implementations/rust/ockam/ockam_command/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ cfg_aliases = "0.2.1"
[dependencies]
arboard = "3.4.1"
async-trait = "0.1"
cfg-if = "1.0.0"
clap = { version = "4.5", features = ["derive", "cargo", "wrap_help"] }
clap_complete = "4.5.28"
clap_mangen = "0.2.23"
Expand Down Expand Up @@ -108,9 +107,7 @@ serial_test = "3.0.0"
tempfile = "3.10.1"

[features]
default = ["rust-crypto", "privileged_portals", "admin_commands", "advanced_commands"]
default = ["rust-crypto", "privileged_portals"]
privileged_portals = ["ockam_api/privileged_portals"]
aws-lc = ["ockam_vault/aws-lc", "ockam_api/aws-lc", "rustls/aws-lc-rs"]
rust-crypto = ["ockam_vault/rust-crypto", "ockam_api/rust-crypto", "rustls/ring"]
admin_commands = []
advanced_commands = []
28 changes: 11 additions & 17 deletions implementations/rust/ockam/ockam_command/src/kafka/mod.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
use cfg_if::cfg_if;
use ockam::transport::{HostnamePort, SchemeHostnamePort, StaticHostnamePort};
use ockam_api::nodes::service::default_address::DefaultAddress;
use ockam_api::port_range::PortRange;
use ockam_multiaddr::MultiAddr;
use std::cmp::min;
use std::str::FromStr;

pub(crate) mod consumer;
pub(crate) mod inlet;
pub(crate) mod outlet;
pub(crate) mod producer;
pub(crate) mod util;

cfg_if! {
if #[cfg(feature = "advanced_commands")] {
pub(crate) mod consumer;
pub(crate) mod producer;

const KAFKA_DEFAULT_CONSUMER_SERVER: StaticHostnamePort =
StaticHostnamePort::new("127.0.0.1", 4000);
const KAFKA_DEFAULT_PRODUCER_SERVER: StaticHostnamePort =
StaticHostnamePort::new("127.0.0.1", 5000);
const KAFKA_DEFAULT_CONSUMER_SERVER: StaticHostnamePort =
StaticHostnamePort::new("127.0.0.1", 4000);
const KAFKA_DEFAULT_PRODUCER_SERVER: StaticHostnamePort =
StaticHostnamePort::new("127.0.0.1", 5000);

fn kafka_default_consumer_server() -> SchemeHostnamePort {
KAFKA_DEFAULT_CONSUMER_SERVER.try_into().unwrap()
}
fn kafka_default_producer_server() -> SchemeHostnamePort {
KAFKA_DEFAULT_PRODUCER_SERVER.try_into().unwrap()
}
}
fn kafka_default_consumer_server() -> SchemeHostnamePort {
KAFKA_DEFAULT_CONSUMER_SERVER.try_into().unwrap()
}
fn kafka_default_producer_server() -> SchemeHostnamePort {
KAFKA_DEFAULT_PRODUCER_SERVER.try_into().unwrap()
}

const KAFKA_DEFAULT_BOOTSTRAP_ADDRESS: StaticHostnamePort =
Expand Down
39 changes: 14 additions & 25 deletions implementations/rust/ockam/ockam_command/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
//! ```
pub use arguments::*;
use cfg_if::cfg_if;
pub use command::*;
pub use command_events::*;
pub use command_global_opts::*;
Expand All @@ -28,7 +27,9 @@ pub use pager::*;
pub use subcommand::*;
pub use terminal::*;

mod admin;
mod arguments;
mod authority;
mod command;
mod command_events;
mod command_global_opts;
Expand All @@ -39,54 +40,42 @@ pub mod enroll;
pub mod entry_point;
mod environment;
pub mod error;
mod flow_control;
mod global_args;
pub mod identity;
mod influxdb;
mod kafka;
mod lease;
mod manpages;
mod markdown;
mod message;
pub mod node;
mod operation;
mod output;
pub mod pager;
mod policy;
mod project;
mod project_admin;
mod project_member;
mod relay;
mod rendezvous;
mod reset;
mod run;
mod secure_channel;
mod service;
mod share;
mod shared_args;
mod sidecar;
mod space;
mod space_admin;
mod status;
mod subcommand;
mod subscription;
pub mod tcp;
mod terminal;
mod upgrade;
pub mod util;
pub mod value_parsers;
mod vault;
mod version;

cfg_if! {
if #[cfg(feature = "admin_commands")] {
mod admin;
mod authority;
mod lease;
mod project_admin;
mod project_member;
mod markdown;
mod sidecar;
mod space_admin;
mod subscription;
}
}

cfg_if! {
if #[cfg(feature = "advanced_commands")] {
mod flow_control;
mod message;
mod secure_channel;
mod share;
mod worker;
}
}
mod worker;
Original file line number Diff line number Diff line change
@@ -1,35 +1,26 @@
use cfg_if::cfg_if;
use miette::IntoDiagnostic;
use std::sync::Arc;
use tracing::{debug, info, instrument};

use crate::node::show::is_node_up;
use crate::node::CreateCommand;
use crate::util::foreground_args::wait_for_exit_signal;
use crate::CommandGlobalOpts;
use miette::miette;
use miette::IntoDiagnostic;
use ockam::tcp::{TcpListenerOptions, TcpTransport};
use ockam::udp::{UdpBindArguments, UdpBindOptions, UdpTransport};
use ockam::Address;
use ockam::Context;
use ockam_api::fmt_log;
use ockam_api::nodes::service::NodeManagerTransport;
use ockam_api::nodes::BackgroundNodeClient;
use ockam_api::nodes::InMemoryNode;
use ockam_api::nodes::{
service::{NodeManagerGeneralOptions, NodeManagerTransportOptions},
NodeManagerWorker, NODEMANAGER_ADDR,
};
use ockam_api::terminal::notification::NotificationHandler;

cfg_if! {
if #[cfg(feature = "advanced_commands")] {
use miette::miette;
use tokio::time::{sleep, Duration};

use ockam::Address;
use ockam_api::fmt_log;
use ockam_api::nodes::BackgroundNodeClient;
use ockam_core::{route, LOCAL};

use crate::node::show::is_node_up;
}
}
use ockam_core::{route, LOCAL};
use std::sync::Arc;
use tokio::time::{sleep, Duration};
use tracing::{debug, info, instrument};

impl CreateCommand {
#[instrument(skip_all, fields(node_name = self.name))]
Expand Down Expand Up @@ -121,7 +112,6 @@ impl CreateCommand {
.into_diagnostic()?;
debug!("node manager worker started");

#[cfg(feature = "advanced_commands")]
if self.start_services(ctx, &opts).await.is_err() {
//TODO: Process should terminate on any error during its setup phase,
// not just during the start_services.
Expand Down Expand Up @@ -157,7 +147,6 @@ impl CreateCommand {
Ok(())
}

#[cfg(feature = "advanced_commands")]
async fn start_services(&self, ctx: &Context, opts: &CommandGlobalOpts) -> miette::Result<()> {
if let Some(config) = &self.launch_configuration {
if let Some(startup_services) = &config.startup_services {
Expand Down
36 changes: 8 additions & 28 deletions implementations/rust/ockam/ockam_command/src/project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,22 @@ pub use version::VersionCommand;

use crate::{docs, Command, CommandGlobalOpts};

mod addon;
mod create;
mod delete;
pub(crate) mod enroll;
mod import;
mod info;
mod list;
mod show;
mod ticket;
#[allow(unused)]
pub mod util;
mod version;

cfg_if::cfg_if! {
if #[cfg(feature = "admin_commands")] {
mod addon;
mod create;
mod delete;
mod ticket;
pub use addon::AddonCommand;
pub use create::CreateCommand;
pub use delete::DeleteCommand;
pub use ticket::TicketCommand;
}
}
pub use addon::AddonCommand;
pub use create::CreateCommand;
pub use delete::DeleteCommand;
pub use ticket::TicketCommand;

const LONG_ABOUT: &str = include_str!("./static/long_about.txt");

Expand All @@ -53,14 +48,9 @@ pub enum ProjectSubcommand {
Show(ShowCommand),
Version(VersionCommand),
Information(InfoCommand),

#[cfg(feature = "admin_commands")]
Ticket(TicketCommand),
#[cfg(feature = "admin_commands")]
Create(CreateCommand),
#[cfg(feature = "admin_commands")]
Delete(DeleteCommand),
#[cfg(feature = "admin_commands")]
Addon(AddonCommand),
}

Expand All @@ -73,14 +63,9 @@ impl ProjectCommand {
ProjectSubcommand::Show(c) => c.run(opts),
ProjectSubcommand::Version(c) => c.run(opts),
ProjectSubcommand::Information(c) => c.run(opts),

#[cfg(feature = "admin_commands")]
ProjectSubcommand::Ticket(c) => c.run(opts),
#[cfg(feature = "admin_commands")]
ProjectSubcommand::Create(c) => c.run(opts),
#[cfg(feature = "admin_commands")]
ProjectSubcommand::Delete(c) => c.run(opts),
#[cfg(feature = "admin_commands")]
ProjectSubcommand::Addon(c) => c.run(opts),
}
}
Expand All @@ -93,14 +78,9 @@ impl ProjectCommand {
ProjectSubcommand::Show(c) => c.name(),
ProjectSubcommand::Version(c) => c.name(),
ProjectSubcommand::Information(c) => c.name(),

#[cfg(feature = "admin_commands")]
ProjectSubcommand::Ticket(c) => c.name(),
#[cfg(feature = "admin_commands")]
ProjectSubcommand::Create(c) => c.name(),
#[cfg(feature = "admin_commands")]
ProjectSubcommand::Delete(c) => c.name(),
#[cfg(feature = "admin_commands")]
ProjectSubcommand::Addon(c) => c.name(),
}
}
Expand Down
64 changes: 30 additions & 34 deletions implementations/rust/ockam/ockam_command/src/service/mod.rs
Original file line number Diff line number Diff line change
@@ -1,44 +1,40 @@
pub(crate) mod config;

cfg_if::cfg_if! {
if #[cfg(feature = "advanced_commands")] {
pub(crate) mod list;
pub(crate) mod start;
pub(crate) mod list;
pub(crate) mod start;

use clap::{Args, Subcommand};
use list::ListCommand;
pub(crate) use start::StartCommand;
use crate::{docs, CommandGlobalOpts};
use crate::{docs, CommandGlobalOpts};
use clap::{Args, Subcommand};
use list::ListCommand;
pub(crate) use start::StartCommand;

#[derive(Clone, Debug, Args)]
#[command(hide = docs::hide())]
pub struct ServiceCommand {
#[command(subcommand)]
subcommand: ServiceSubcommand,
}
#[derive(Clone, Debug, Args)]
#[command(hide = docs::hide())]
pub struct ServiceCommand {
#[command(subcommand)]
subcommand: ServiceSubcommand,
}

#[derive(Clone, Debug, Subcommand)]
pub enum ServiceSubcommand {
#[command(display_order = 900)]
Start(StartCommand),
#[command(display_order = 901)]
List(ListCommand),
}
#[derive(Clone, Debug, Subcommand)]
pub enum ServiceSubcommand {
#[command(display_order = 900)]
Start(StartCommand),
#[command(display_order = 901)]
List(ListCommand),
}

impl ServiceCommand {
pub fn run(self, opts: CommandGlobalOpts) -> miette::Result<()> {
match self.subcommand {
ServiceSubcommand::Start(c) => c.run(opts),
ServiceSubcommand::List(c) => c.run(opts),
}
}
impl ServiceCommand {
pub fn run(self, opts: CommandGlobalOpts) -> miette::Result<()> {
match self.subcommand {
ServiceSubcommand::Start(c) => c.run(opts),
ServiceSubcommand::List(c) => c.run(opts),
}
}

pub fn name(&self) -> String {
match &self.subcommand {
ServiceSubcommand::Start(c) => c.name(),
ServiceSubcommand::List(c) => c.name(),
}
}
pub fn name(&self) -> String {
match &self.subcommand {
ServiceSubcommand::Start(c) => c.name(),
ServiceSubcommand::List(c) => c.name(),
}
}
}
Loading

0 comments on commit b80f016

Please sign in to comment.