Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Bump structopt and fix compilation. #2736

Merged
merged 1 commit into from
May 30, 2019
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
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.

8 changes: 4 additions & 4 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub use structopt::clap::App;
use params::{
RunCmd, PurgeChainCmd, RevertCmd, ImportBlocksCmd, ExportBlocksCmd, BuildSpecCmd,
NetworkConfigurationParams, MergeParameters, TransactionPoolParams,
NodeKeyParams, NodeKeyType
NodeKeyParams, NodeKeyType, Cors,
};
pub use params::{NoCustom, CoreParams, SharedParams};
pub use traits::{GetLogFilter, AugmentClap};
Expand Down Expand Up @@ -485,17 +485,17 @@ where
config.rpc_ws_max_connections = cli.ws_max_connections;
config.rpc_cors = cli.rpc_cors.unwrap_or_else(|| if is_dev {
log::warn!("Running in --dev mode, RPC CORS has been disabled.");
None
Cors::All
} else {
Some(vec![
Cors::List(vec![
"http://localhost:*".into(),
"http://127.0.0.1:*".into(),
"https://localhost:*".into(),
"https://127.0.0.1:*".into(),
"https://polkadot.js.org".into(),
"https://substrate-ui.parity.io".into(),
])
});
}).into();

// Override telemetry
if cli.no_telemetry {
Expand Down
27 changes: 24 additions & 3 deletions core/cli/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ pub struct RunCmd {
/// Default is to allow localhost, https://polkadot.js.org and https://substrate-ui.parity.io origins.
/// When running in --dev mode the default is to allow all origins.
#[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = "parse_cors"))]
pub rpc_cors: Option<Option<Vec<String>>>,
pub rpc_cors: Option<Cors>,

/// Specify the pruning mode, a number of blocks to keep or 'archive'. Default is 256.
#[structopt(long = "pruning", value_name = "PRUNING_MODE")]
Expand Down Expand Up @@ -490,8 +490,29 @@ fn parse_telemetry_endpoints(s: &str) -> Result<(String, u8), Box<std::error::Er
}
}

/// CORS setting
///
/// The type is introduced to overcome `Option<Option<T>>`
/// handling of `structopt`.
#[derive(Clone, Debug)]
pub enum Cors {
/// All hosts allowed
All,
/// Only hosts on the list are allowed.
List(Vec<String>),
}

impl From<Cors> for Option<Vec<String>> {
fn from(cors: Cors) -> Self {
match cors {
Cors::All => None,
Cors::List(list) => Some(list),
}
}
}

/// Parse cors origins
fn parse_cors(s: &str) -> Result<Option<Vec<String>>, Box<std::error::Error>> {
fn parse_cors(s: &str) -> Result<Cors, Box<std::error::Error>> {
let mut is_all = false;
let mut origins = Vec::new();
for part in s.split(',') {
Expand All @@ -504,7 +525,7 @@ fn parse_cors(s: &str) -> Result<Option<Vec<String>>, Box<std::error::Error>> {
}
}

Ok(if is_all { None } else { Some(origins) })
Ok(if is_all { Cors::All } else { Cors::List(origins) })
}

impl_augment_clap!(RunCmd);
Expand Down