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: replace address and port with URL for RPC CLI #81

Closed
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/bins/wafl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ wasmflow-oci = { path = "../../wasmflow/wasmflow-oci" }
anyhow = "1.0"
markup-converter = "0.2"
jaq-core = "0.7"
url = "2.3.0"

[dev-dependencies]
trycmd = "0.13"
Expand Down
21 changes: 14 additions & 7 deletions crates/bins/wafl/src/commands/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::PathBuf;

use clap::{Args, Subcommand};
use url::Url;

pub(crate) mod invoke;
pub(crate) mod list;
Expand All @@ -23,13 +24,9 @@ pub(crate) enum SubCommands {

#[derive(Debug, Clone, Args)]
pub(crate) struct ConnectOptions {
/// RPC port.
#[clap(short, long, env = wasmflow_collection_cli::options::env::WAFL_RPC_PORT,action)]
pub(crate) port: u16,

/// RPC address.
#[clap(short, long, default_value = "127.0.0.1", env = wasmflow_collection_cli::options::env::WAFL_RPC_ADDRESS,action)]
pub(crate) address: String,
/// RPC Url
#[clap(short, long)]
pub(crate) url: Url,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I'm missing some validation so Im able to unwrap with confidence on L50 and L54.


/// Path to pem file for TLS connections.
#[clap(long, action)]
Expand All @@ -47,3 +44,13 @@ pub(crate) struct ConnectOptions {
#[clap(long, action)]
pub(crate) domain: Option<String>,
}

impl ConnectOptions {
pub(crate) fn host(&self) -> String {
self.url.host().unwrap().to_string()
}

pub(crate) fn port(&self) -> u16 {
self.url.port().unwrap()
}
}
2 changes: 1 addition & 1 deletion crates/bins/wafl/src/commands/rpc/invoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub(crate) async fn handle(opts: Options) -> Result<()> {
let _guard = crate::utils::init_logger(&opts.logging)?;

let mut client = wasmflow_rpc::make_rpc_client(
format!("http://{}:{}", opts.connection.address, opts.connection.port),
format!("http://{}:{}", opts.connection.host(), opts.connection.port()),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My quick solution to allow URLs was to expose previously used address and port fields as methods.

opts.connection.pem,
opts.connection.key,
opts.connection.ca,
Expand Down
2 changes: 1 addition & 1 deletion crates/bins/wafl/src/commands/rpc/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub(crate) struct Options {
pub(crate) async fn handle(opts: Options) -> Result<()> {
let _guard = crate::utils::init_logger(&opts.logging)?;
let mut client = wasmflow_rpc::make_rpc_client(
format!("http://{}:{}", opts.connection.address, opts.connection.port),
format!("http://{}:{}", opts.connection.host(), opts.connection.port()),
opts.connection.pem,
opts.connection.key,
opts.connection.ca,
Expand Down
2 changes: 1 addition & 1 deletion crates/bins/wafl/src/commands/rpc/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub(crate) struct Options {
pub(crate) async fn handle(opts: Options) -> Result<()> {
let _guard = crate::utils::init_logger(&opts.logging)?;
let mut client = wasmflow_rpc::make_rpc_client(
format!("http://{}:{}", opts.connection.address, opts.connection.port),
format!("http://{}:{}", opts.connection.host(), opts.connection.port()),
opts.connection.pem,
opts.connection.key,
opts.connection.ca,
Expand Down