From f12c604bb2d31482104be97cdf02324fe2822509 Mon Sep 17 00:00:00 2001 From: Mrinal Wadhwa Date: Sun, 14 Aug 2022 10:13:52 -0700 Subject: [PATCH] feat(rust): change portal sub command to tcp-inlet and tcp-outlet * move portal/* commands to tcp-inlet/* and tcp-outlet/* * change options for create commands to --at, --from, --to * move api helper code into the command --- .../rust/ockam/ockam_command/src/lib.rs | 22 +- .../ockam/ockam_command/src/portal/create.rs | 214 ------------------ .../ockam/ockam_command/src/portal/mod.rs | 28 --- .../ockam_command/src/tcp/inlet/create.rs | 140 ++++++++++++ .../ockam/ockam_command/src/tcp/inlet/mod.rs | 25 ++ .../rust/ockam/ockam_command/src/tcp/mod.rs | 2 + .../ockam_command/src/tcp/outlet/create.rs | 131 +++++++++++ .../ockam/ockam_command/src/tcp/outlet/mod.rs | 25 ++ .../rust/ockam/ockam_command/src/util/api.rs | 56 ----- 9 files changed, 337 insertions(+), 306 deletions(-) delete mode 100644 implementations/rust/ockam/ockam_command/src/portal/create.rs delete mode 100644 implementations/rust/ockam/ockam_command/src/portal/mod.rs create mode 100644 implementations/rust/ockam/ockam_command/src/tcp/inlet/create.rs create mode 100644 implementations/rust/ockam/ockam_command/src/tcp/inlet/mod.rs create mode 100644 implementations/rust/ockam/ockam_command/src/tcp/outlet/create.rs create mode 100644 implementations/rust/ockam/ockam_command/src/tcp/outlet/mod.rs diff --git a/implementations/rust/ockam/ockam_command/src/lib.rs b/implementations/rust/ockam/ockam_command/src/lib.rs index 4b165439906..e35d6cc0601 100644 --- a/implementations/rust/ockam/ockam_command/src/lib.rs +++ b/implementations/rust/ockam/ockam_command/src/lib.rs @@ -7,7 +7,6 @@ mod forwarder; mod identity; mod message; mod node; -mod portal; mod project; mod secure_channel; mod secure_channel_listener; @@ -23,12 +22,14 @@ use enroll::EnrollCommand; use forwarder::ForwarderCommand; use message::MessageCommand; use node::NodeCommand; -use portal::PortalCommand; use project::ProjectCommand; use secure_channel::SecureChannelCommand; use secure_channel_listener::SecureChannelListenerCommand; use space::SpaceCommand; -use tcp::{connection::TcpConnectionCommand, listener::TcpListenerCommand}; +use tcp::connection::TcpConnectionCommand; +use tcp::inlet::TcpInletCommand; +use tcp::listener::TcpListenerCommand; +use tcp::outlet::TcpOutletCommand; // to be removed mod old; @@ -158,10 +159,18 @@ pub enum OckamSubcommand { #[clap(display_order = 900, help_template = HELP_TEMPLATE)] TcpConnection(TcpConnectionCommand), + /// Manage TCP Inlets + #[clap(display_order = 900, help_template = HELP_TEMPLATE)] + TcpInlet(TcpInletCommand), + /// Create, update, or delete tcp listeners #[clap(display_order = 900, help_template = HELP_TEMPLATE)] TcpListener(TcpListenerCommand), + /// Manage TCP Outlets + #[clap(display_order = 900, help_template = HELP_TEMPLATE)] + TcpOutlet(TcpOutletCommand), + /// Manage Identities #[clap(display_order = 900, help_template = HELP_TEMPLATE)] Identity(IdentityCommand), @@ -197,10 +206,6 @@ pub enum OckamSubcommand { #[clap(display_order = 900, help_template = HELP_TEMPLATE, name = "token", hide = hide())] GenerateEnrollmentToken(GenerateEnrollmentTokenCommand), - /// Create, update, or delete portal endpoints - #[clap(display_order = 900, help_template = HELP_TEMPLATE, hide = hide())] - Portal(PortalCommand), - /// Create, update or delete projects #[clap(display_order = 900, help_template = HELP_TEMPLATE, hide = hide())] Project(ProjectCommand), @@ -327,8 +332,9 @@ pub fn run() { OckamSubcommand::Project(command) => ProjectCommand::run(opts, command), OckamSubcommand::Space(command) => SpaceCommand::run(opts, command), OckamSubcommand::TcpConnection(command) => TcpConnectionCommand::run(opts, command), + OckamSubcommand::TcpInlet(command) => TcpInletCommand::run(opts, command), OckamSubcommand::TcpListener(command) => TcpListenerCommand::run(opts, command), - OckamSubcommand::Portal(command) => PortalCommand::run(opts, command), + OckamSubcommand::TcpOutlet(command) => TcpOutletCommand::run(opts, command), OckamSubcommand::Vault(command) => VaultCommand::run(opts, command), OckamSubcommand::Identity(command) => IdentityCommand::run(opts, command), OckamSubcommand::SecureChannel(command) => SecureChannelCommand::run(opts, command), diff --git a/implementations/rust/ockam/ockam_command/src/portal/create.rs b/implementations/rust/ockam/ockam_command/src/portal/create.rs deleted file mode 100644 index cff74a4a040..00000000000 --- a/implementations/rust/ockam/ockam_command/src/portal/create.rs +++ /dev/null @@ -1,214 +0,0 @@ -use crate::node::NodeOpts; -use crate::util::{api, connect_to, exitcode, stop_node}; -use crate::util::{ComposableSnippet, Operation, PortalMode, Protocol}; -use crate::CommandGlobalOpts; -use clap::{Args, Subcommand}; -use ockam::{Context, Route}; -use ockam_api::error::ApiError; -use ockam_api::{ - nodes::models::portal::{InletStatus, OutletStatus}, - nodes::NODEMANAGER_ADDR, - Status, -}; -use ockam_core::Address; -use ockam_multiaddr::MultiAddr; - -#[derive(Clone, Debug, Args)] -pub struct CreateCommand { - #[clap(flatten)] - node_opts: NodeOpts, - - /// Select a creation variant - #[clap(subcommand)] - pub create_subcommand: CreateTypeCommand, - - /// Give this portal endpoint a name. If none is provided a - /// random one will be generated. - pub alias: Option, -} - -impl From<&'_ CreateCommand> for ComposableSnippet { - fn from(cc: &'_ CreateCommand) -> Self { - let bind = cc.create_subcommand.bind(); - let peer = cc.create_subcommand.peer(); - let mode = cc.create_subcommand.mode(); - - Self { - id: format!("_portal_{}_{}_{}_{}", mode, "tcp", bind, peer,), - op: Operation::Portal { - mode, - protocol: Protocol::Tcp, - bind, - peer, - }, - params: vec![], - } - } -} - -#[derive(Clone, Debug, Subcommand)] -pub enum CreateTypeCommand { - /// Create a TCP portal inlet - TcpInlet { - /// Portal inlet bind address - bind: String, - /// Forwarding point for the portal (ockam routing address) - outlet_addr: MultiAddr, - }, - /// Create a TCP portal outlet - TcpOutlet { - /// Portal outlet connection address - tcp_address: String, - /// Portal outlet worker address - worker_address: Address, - }, -} - -impl CreateTypeCommand { - fn mode(&self) -> PortalMode { - match self { - Self::TcpInlet { .. } => PortalMode::Inlet, - Self::TcpOutlet { .. } => PortalMode::Outlet, - } - } - - fn bind(&self) -> String { - match self { - Self::TcpInlet { bind, .. } => bind.clone(), - Self::TcpOutlet { worker_address, .. } => worker_address.to_string(), - } - } - - fn peer(&self) -> String { - match self { - Self::TcpInlet { outlet_addr, .. } => outlet_addr.to_string(), - Self::TcpOutlet { tcp_address, .. } => tcp_address.clone(), - } - } -} - -impl CreateCommand { - pub fn run(opts: CommandGlobalOpts, command: CreateCommand) { - let cfg = &opts.config; - let port = match cfg.select_node(&command.node_opts.api_node) { - Some(cfg) => cfg.port, - None => { - eprintln!("No such node available. Run `ockam node list` to list available nodes"); - std::process::exit(exitcode::IOERR); - } - }; - - let composite = (&command).into(); - let node = command.node_opts.api_node.clone(); - - match command.create_subcommand { - CreateTypeCommand::TcpInlet { .. } => connect_to(port, command, create_inlet), - CreateTypeCommand::TcpOutlet { .. } => connect_to(port, command, create_outlet), - } - - // Update the startup config - let startup_cfg = match cfg.get_startup_cfg(&node) { - Ok(cfg) => cfg, - Err(e) => { - eprintln!("failed to load startup configuration: {}", e); - std::process::exit(exitcode::IOERR); - } - }; - - startup_cfg.add_composite(composite); - if let Err(e) = startup_cfg.atomic_update().run() { - eprintln!("failed to update configuration: {}", e); - std::process::exit(exitcode::IOERR); - } - } -} - -pub async fn create_inlet( - ctx: Context, - cmd: CreateCommand, - mut base_route: Route, -) -> anyhow::Result<()> { - let (bind, outlet_addr) = match cmd.create_subcommand { - CreateTypeCommand::TcpInlet { bind, outlet_addr } => (bind, outlet_addr), - CreateTypeCommand::TcpOutlet { .. } => { - return Err(ApiError::generic("Internal logic error").into()) - } - }; - - let resp: Vec = ctx - .send_and_receive( - base_route.modify().append(NODEMANAGER_ADDR), - api::create_inlet(&bind, &outlet_addr, &cmd.alias)?, - ) - .await?; - - let ( - response, - InletStatus { - bind_addr, alias, .. - }, - ) = api::parse_inlet_status(&resp)?; - - match response.status() { - Some(Status::Ok) => { - println!( - "Portal inlet '{}' created! You can send messages to it on this tcp address: \n{}`", - alias, bind_addr - ) - } - - _ => { - eprintln!("An unknown error occurred while creating an inlet..."); - std::process::exit(exitcode::UNAVAILABLE) - } - } - - stop_node(ctx).await -} - -pub async fn create_outlet( - ctx: Context, - cmd: CreateCommand, - mut base_route: Route, -) -> anyhow::Result<()> { - let (tcp_address, worker_address) = match cmd.create_subcommand { - CreateTypeCommand::TcpInlet { .. } => { - return Err(ApiError::generic("Internal logic error").into()) - } - CreateTypeCommand::TcpOutlet { - tcp_address, - worker_address, - } => (tcp_address, worker_address), - }; - - let resp: Vec = ctx - .send_and_receive( - base_route.modify().append(NODEMANAGER_ADDR), - api::create_outlet(&tcp_address, worker_address.to_string(), &cmd.alias)?, - ) - .await?; - - let ( - response, - OutletStatus { - worker_addr, alias, .. - }, - ) = api::parse_outlet_status(&resp)?; - - match response.status() { - Some(Status::Ok) => { - println!( - "Portal outlet '{}' created! You can send messages through it via this address:\n{}", - alias, - worker_addr - ); - } - - _ => { - eprintln!("An unknown error occurred while creating an outlet..."); - std::process::exit(exitcode::UNAVAILABLE); - } - } - - stop_node(ctx).await -} diff --git a/implementations/rust/ockam/ockam_command/src/portal/mod.rs b/implementations/rust/ockam/ockam_command/src/portal/mod.rs deleted file mode 100644 index 15303c8bd08..00000000000 --- a/implementations/rust/ockam/ockam_command/src/portal/mod.rs +++ /dev/null @@ -1,28 +0,0 @@ -mod create; -pub(crate) use create::CreateCommand; - -// TODO: add delete, list, show subcommands - -use crate::{CommandGlobalOpts, HELP_TEMPLATE}; -use clap::{Args, Subcommand}; - -#[derive(Clone, Debug, Args)] -pub struct PortalCommand { - #[clap(subcommand)] - subcommand: PortalSubCommand, -} - -#[derive(Clone, Debug, Subcommand)] -pub enum PortalSubCommand { - /// Create portals on the selected node - #[clap(display_order = 900, help_template = HELP_TEMPLATE)] - Create(CreateCommand), -} - -impl PortalCommand { - pub fn run(opts: CommandGlobalOpts, cmd: PortalCommand) { - match cmd.subcommand { - PortalSubCommand::Create(cmd) => CreateCommand::run(opts, cmd), - } - } -} diff --git a/implementations/rust/ockam/ockam_command/src/tcp/inlet/create.rs b/implementations/rust/ockam/ockam_command/src/tcp/inlet/create.rs new file mode 100644 index 00000000000..173e5be87b2 --- /dev/null +++ b/implementations/rust/ockam/ockam_command/src/tcp/inlet/create.rs @@ -0,0 +1,140 @@ +use crate::util::{connect_to, exitcode, stop_node}; +use crate::util::{ComposableSnippet, Operation, PortalMode, Protocol}; +use crate::CommandGlobalOpts; +use clap::Args; +use minicbor::Decoder; +use ockam::{Context, Route}; +use ockam_api::{ + nodes::models, nodes::models::portal::InletStatus, nodes::NODEMANAGER_ADDR, Method, Request, + Response, Status, +}; +use ockam_multiaddr::MultiAddr; +use std::net::SocketAddr; + +/// Create TCP Inlets +#[derive(Clone, Debug, Args)] +pub struct CreateCommand { + /// Node on which to start the tcp inlet. + #[clap(long, display_order = 900, name = "NODE")] + at: String, + + /// Address on which to accept tcp connections. + #[clap(long, display_order = 900, name = "SOCKET_ADDRESS")] + from: SocketAddr, + + /// Route to a tcp outlet. + #[clap(long, display_order = 900, name = "ROUTE")] + to: MultiAddr, +} + +impl From<&'_ CreateCommand> for ComposableSnippet { + fn from(cc: &'_ CreateCommand) -> Self { + let bind = cc.from.to_string(); + let peer = cc.to.to_string(); + let mode = PortalMode::Inlet; + + Self { + id: format!("_portal_{}_{}_{}_{}", mode, "tcp", bind, peer,), + op: Operation::Portal { + mode, + protocol: Protocol::Tcp, + bind, + peer, + }, + params: vec![], + } + } +} + +impl CreateCommand { + pub fn run(options: CommandGlobalOpts, command: Self) -> anyhow::Result<()> { + let cfg = &options.config; + let port = match cfg.select_node(&command.at) { + Some(cfg) => cfg.port, + None => { + eprintln!("No such node available. Run `ockam node list` to list available nodes"); + std::process::exit(-1); + } + }; + + let composite = (&command).into(); + let node = command.at.clone(); + connect_to(port, command, create_inlet); + + // Update the startup config + let startup_cfg = match cfg.get_startup_cfg(&node) { + Ok(cfg) => cfg, + Err(e) => { + eprintln!("failed to load startup configuration: {}", e); + std::process::exit(-1); + } + }; + + startup_cfg.add_composite(composite); + if let Err(e) = startup_cfg.atomic_update().run() { + eprintln!("failed to update configuration: {}", e); + std::process::exit(exitcode::IOERR); + } else { + std::process::exit(exitcode::OK); + } + } +} + +pub async fn create_inlet( + ctx: Context, + cmd: CreateCommand, + mut base_route: Route, +) -> anyhow::Result<()> { + let route = base_route.modify().append(NODEMANAGER_ADDR); + let message = make_api_request(&cmd.from.to_string(), &cmd.to, &None::)?; + let response: Vec = ctx.send_and_receive(route, message).await?; + + let ( + response, + InletStatus { + bind_addr, alias, .. + }, + ) = parse_inlet_status(&response)?; + + match response.status() { + Some(Status::Ok) => { + println!( + "TCP inlet '{}' created! You can send messages to it on this tcp address: \n{}`", + alias, bind_addr + ) + } + + _ => { + eprintln!("An unknown error occurred while creating an inlet..."); + std::process::exit(exitcode::UNAVAILABLE) + } + } + + stop_node(ctx).await +} + +/// Construct a request to create a tcp inlet +fn make_api_request( + bind_addr: &str, + outlet_route: &MultiAddr, + alias: &Option, +) -> ockam::Result> { + let payload = models::portal::CreateInlet::new( + bind_addr, + outlet_route.to_string(), + alias.as_ref().map(|x| x.as_str().into()), + ); + + let mut buf = vec![]; + Request::builder(Method::Post, "/node/inlet") + .body(payload) + .encode(&mut buf)?; + Ok(buf) +} + +/// Parse the returned status response +fn parse_inlet_status(resp: &[u8]) -> ockam::Result<(Response, models::portal::InletStatus<'_>)> { + let mut dec = Decoder::new(resp); + let response = dec.decode::()?; + Ok((response, dec.decode::()?)) +} diff --git a/implementations/rust/ockam/ockam_command/src/tcp/inlet/mod.rs b/implementations/rust/ockam/ockam_command/src/tcp/inlet/mod.rs new file mode 100644 index 00000000000..c839e397da3 --- /dev/null +++ b/implementations/rust/ockam/ockam_command/src/tcp/inlet/mod.rs @@ -0,0 +1,25 @@ +mod create; + +use crate::{CommandGlobalOpts, HELP_TEMPLATE}; +use clap::{Args, Subcommand}; +use create::CreateCommand; + +#[derive(Clone, Debug, Args)] +pub struct TcpInletCommand { + #[clap(subcommand)] + subcommand: TcpInletSubCommand, +} + +#[derive(Clone, Debug, Subcommand)] +pub enum TcpInletSubCommand { + #[clap(display_order = 900, help_template = HELP_TEMPLATE)] + Create(CreateCommand), +} + +impl TcpInletCommand { + pub fn run(options: CommandGlobalOpts, command: TcpInletCommand) { + match command.subcommand { + TcpInletSubCommand::Create(command) => CreateCommand::run(options, command).unwrap(), + } + } +} diff --git a/implementations/rust/ockam/ockam_command/src/tcp/mod.rs b/implementations/rust/ockam/ockam_command/src/tcp/mod.rs index e0a1cdd9bf9..f553dcf8202 100644 --- a/implementations/rust/ockam/ockam_command/src/tcp/mod.rs +++ b/implementations/rust/ockam/ockam_command/src/tcp/mod.rs @@ -1,2 +1,4 @@ pub(crate) mod connection; +pub(crate) mod inlet; pub(crate) mod listener; +pub(crate) mod outlet; diff --git a/implementations/rust/ockam/ockam_command/src/tcp/outlet/create.rs b/implementations/rust/ockam/ockam_command/src/tcp/outlet/create.rs new file mode 100644 index 00000000000..b0b74293351 --- /dev/null +++ b/implementations/rust/ockam/ockam_command/src/tcp/outlet/create.rs @@ -0,0 +1,131 @@ +use crate::util::{connect_to, exitcode, stop_node}; +use crate::util::{ComposableSnippet, Operation, PortalMode, Protocol}; +use crate::CommandGlobalOpts; +use clap::Args; +use minicbor::Decoder; +use ockam::{Context, Route}; +use ockam_api::{ + error::ApiError, + nodes::models::portal::{CreateOutlet, OutletStatus}, + nodes::NODEMANAGER_ADDR, + route_to_multiaddr, Method, Request, Response, Status, +}; +use ockam_core::{route, Address}; +use std::net::SocketAddr; + +/// Create TCP Outlets +#[derive(Clone, Debug, Args)] +pub struct CreateCommand { + /// Node on which to start the tcp outlet. + #[clap(long, display_order = 900, name = "NODE")] + at: String, + + /// Address of the tcp outlet. + #[clap(long, display_order = 901, name = "OUTLET_ADDRESS")] + from: Address, + + /// TCP address to send raw tcp traffic. + #[clap(long, display_order = 902, name = "SOCKET_ADDRESS")] + to: SocketAddr, +} + +impl From<&'_ CreateCommand> for ComposableSnippet { + fn from(cc: &'_ CreateCommand) -> Self { + let bind = cc.from.to_string(); + let peer = cc.to.to_string(); + let mode = PortalMode::Outlet; + + Self { + id: format!("_portal_{}_{}_{}_{}", mode, "tcp", bind, peer,), + op: Operation::Portal { + mode, + protocol: Protocol::Tcp, + bind, + peer, + }, + params: vec![], + } + } +} + +impl CreateCommand { + pub fn run(options: CommandGlobalOpts, command: Self) -> anyhow::Result<()> { + let cfg = &options.config; + let port = match cfg.select_node(&command.at) { + Some(cfg) => cfg.port, + None => { + eprintln!("No such node available. Run `ockam node list` to list available nodes"); + std::process::exit(exitcode::IOERR); + } + }; + + let composite = (&command).into(); + let node = command.at.clone(); + connect_to(port, command, create_outlet); + + // Update the startup config + let startup_cfg = match cfg.get_startup_cfg(&node) { + Ok(cfg) => cfg, + Err(e) => { + eprintln!("failed to load startup configuration: {}", e); + std::process::exit(exitcode::IOERR); + } + }; + + startup_cfg.add_composite(composite); + if let Err(e) = startup_cfg.atomic_update().run() { + eprintln!("failed to update configuration: {}", e); + std::process::exit(exitcode::IOERR); + } else { + std::process::exit(exitcode::OK); + } + } +} + +pub async fn create_outlet( + ctx: Context, + cmd: CreateCommand, + mut base_route: Route, +) -> anyhow::Result<()> { + let route = base_route.modify().append(NODEMANAGER_ADDR); + let message = make_api_request(cmd)?; + let response: Vec = ctx.send_and_receive(route, message).await?; + + let (response, OutletStatus { worker_addr, .. }) = parse_outlet_status(&response)?; + let addr = route_to_multiaddr(&route![worker_addr.to_string()]) + .ok_or_else(|| ApiError::generic("Invalid Outlet Address"))?; + + match response.status() { + Some(Status::Ok) => { + println!("{}", addr); + } + + _ => { + eprintln!("An unknown error occurred while creating an outlet..."); + std::process::exit(exitcode::UNAVAILABLE); + } + } + + stop_node(ctx).await +} + +/// Construct a request to create a tcp outlet +fn make_api_request(cmd: CreateCommand) -> ockam::Result> { + let tcp_addr = &cmd.to.to_string(); + let worker_addr = cmd.from.to_string(); + let alias = (&None::).as_ref().map(|x| x.as_str().into()); + let payload = CreateOutlet::new(tcp_addr, worker_addr, alias); + + let mut buf = vec![]; + Request::builder(Method::Post, "/node/outlet") + .body(payload) + .encode(&mut buf)?; + Ok(buf) +} + +/// Parse the returned status response +fn parse_outlet_status(response: &[u8]) -> ockam::Result<(Response, OutletStatus<'_>)> { + let mut decoder = Decoder::new(response); + let response = decoder.decode::()?; + Ok((response, decoder.decode::()?)) +} diff --git a/implementations/rust/ockam/ockam_command/src/tcp/outlet/mod.rs b/implementations/rust/ockam/ockam_command/src/tcp/outlet/mod.rs new file mode 100644 index 00000000000..3a61568dcc6 --- /dev/null +++ b/implementations/rust/ockam/ockam_command/src/tcp/outlet/mod.rs @@ -0,0 +1,25 @@ +mod create; + +use crate::{CommandGlobalOpts, HELP_TEMPLATE}; +use clap::{Args, Subcommand}; +use create::CreateCommand; + +#[derive(Clone, Debug, Args)] +pub struct TcpOutletCommand { + #[clap(subcommand)] + subcommand: TcpOutletSubCommand, +} + +#[derive(Clone, Debug, Subcommand)] +pub enum TcpOutletSubCommand { + #[clap(display_order = 900, help_template = HELP_TEMPLATE)] + Create(CreateCommand), +} + +impl TcpOutletCommand { + pub fn run(options: CommandGlobalOpts, command: TcpOutletCommand) { + match command.subcommand { + TcpOutletSubCommand::Create(command) => CreateCommand::run(options, command).unwrap(), + } + } +} diff --git a/implementations/rust/ockam/ockam_command/src/util/api.rs b/implementations/rust/ockam/ockam_command/src/util/api.rs index 987470ffac5..a3c8c3a6938 100644 --- a/implementations/rust/ockam/ockam_command/src/util/api.rs +++ b/implementations/rust/ockam/ockam_command/src/util/api.rs @@ -200,44 +200,6 @@ pub(crate) fn start_authenticated_service(addr: &str) -> Result> { Ok(buf) } -/// Construct a request to create a tcp inlet -pub(crate) fn create_inlet( - bind_addr: &str, - outlet_route: &MultiAddr, - alias: &Option, -) -> Result> { - let payload = models::portal::CreateInlet::new( - bind_addr, - outlet_route.to_string(), - alias.as_ref().map(|x| x.as_str().into()), - ); - - let mut buf = vec![]; - Request::builder(Method::Post, "/node/inlet") - .body(payload) - .encode(&mut buf)?; - Ok(buf) -} - -/// Construct a request to create a tcp outlet -pub(crate) fn create_outlet( - tcp_addr: &str, - worker_addr: String, - alias: &Option, -) -> Result> { - let payload = models::portal::CreateOutlet::new( - tcp_addr, - worker_addr, - alias.as_ref().map(|x| x.as_str().into()), - ); - - let mut buf = vec![]; - Request::builder(Method::Post, "/node/outlet") - .body(payload) - .encode(&mut buf)?; - Ok(buf) -} - /// Helpers to create enroll API requests pub(crate) mod enroll { use crate::enroll::*; @@ -465,24 +427,6 @@ pub(crate) fn parse_create_secure_channel_listener_response(resp: &[u8]) -> Resu Ok(response) } -/// Parse the returned status response -pub(crate) fn parse_inlet_status( - resp: &[u8], -) -> Result<(Response, models::portal::InletStatus<'_>)> { - let mut dec = Decoder::new(resp); - let response = dec.decode::()?; - Ok((response, dec.decode::()?)) -} - -/// Parse the returned status response -pub(crate) fn parse_outlet_status( - resp: &[u8], -) -> Result<(Response, models::portal::OutletStatus<'_>)> { - let mut dec = Decoder::new(resp); - let response = dec.decode::()?; - Ok((response, dec.decode::()?)) -} - ////////////// !== share CLI args #[derive(Clone, Debug, Args)]