From 8cd875fd24b7958cf8da95c61dd7b36149430e45 Mon Sep 17 00:00:00 2001 From: jspspike Date: Thu, 30 Jul 2020 12:38:18 -0500 Subject: [PATCH 01/10] Openssl tests --- .github/workflows/release.yml | 10 ++++++++++ Cargo.toml | 2 +- src/commands/login.rs | 3 +++ src/commands/mod.rs | 1 + src/lib.rs | 1 + src/login/mod.rs | 22 ++++++++++++++++++++++ src/preview/mod.rs | 19 +------------------ src/terminal/browser.rs | 17 +++++++++++++++++ src/terminal/mod.rs | 2 ++ 9 files changed, 58 insertions(+), 19 deletions(-) create mode 100644 src/commands/login.rs create mode 100644 src/login/mod.rs create mode 100644 src/terminal/browser.rs diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f1e2e70c5..b51aad5df 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -89,6 +89,15 @@ jobs: if: matrix.build == 'macos' run: brew install p7zip + - name: Install vcpkg OpenSSL (Windows) + if: matrix.build == 'windows' + run: | + git clone https://github.com/microsoft/vcpkg + .\vcpkg\bootstrap-vcpkg.bat + .\vcpkg\vcpkg install openssl:x64-windows + env: + VCPKGRS_DYNAMIC: 1 + - name: Build (Linux) if: matrix.build == 'linux' run: | @@ -104,6 +113,7 @@ jobs: run: cargo build --release env: RUSTFLAGS: -Ctarget-feature=+crt-static + VCPKGRS_DYNAMIC: 1 - name: Create artifact directory run: | diff --git a/Cargo.toml b/Cargo.toml index df3327e10..9a25d8936 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,7 @@ lazy_static = "1.4.0" log = "0.4.11" notify = "4.0.15" number_prefix = "0.4.0" -openssl = { version = '0.10.29', optional = true } +openssl = { version = "0.10.29"} percent-encoding = "2.1.0" predicates = "1.0.5" prettytable-rs = "0.8.0" diff --git a/src/commands/login.rs b/src/commands/login.rs new file mode 100644 index 000000000..48e0a3027 --- /dev/null +++ b/src/commands/login.rs @@ -0,0 +1,3 @@ +//use crate::login; + +pub fn run() {} diff --git a/src/commands/mod.rs b/src/commands/mod.rs index b76bb3c3f..04f455593 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -6,6 +6,7 @@ pub mod dev; pub mod generate; pub mod init; pub mod kv; +pub mod login; mod preview; pub mod publish; pub mod route; diff --git a/src/lib.rs b/src/lib.rs index d7e7c1af8..95f219bf8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,6 +12,7 @@ pub mod http; pub mod install; pub mod installer; pub mod kv; +pub mod login; pub mod settings; pub mod sites; pub mod tail; diff --git a/src/login/mod.rs b/src/login/mod.rs new file mode 100644 index 000000000..5a4b8eb97 --- /dev/null +++ b/src/login/mod.rs @@ -0,0 +1,22 @@ +//use crate::terminal::{interactive::confirm, open_browser}; + +//use openssl::base64; +use openssl::rsa::Rsa; + +pub fn run() -> Result<(), failure::Error> { + let rsa = Rsa::generate(1024)?; + let _ = rsa.public_key_to_pem_pkcs1()?; + + Ok(()) +} + +#[cfg(test)] +mod tests { + use openssl::rsa::Rsa; + + #[test] + fn test_rsa() { + let rsa = Rsa::generate(1024).unwrap(); + rsa.public_key_to_pem_pkcs1().unwrap(); + } +} diff --git a/src/preview/mod.rs b/src/preview/mod.rs index 8597c383c..afe8ab278 100644 --- a/src/preview/mod.rs +++ b/src/preview/mod.rs @@ -10,7 +10,6 @@ pub use request_payload::RequestPayload; mod upload; pub use upload::upload; -use std::process::Command; use std::sync::mpsc::channel; use std::thread; @@ -22,7 +21,7 @@ use crate::build; use crate::http; use crate::settings::global_user::GlobalUser; use crate::settings::toml::Target; -use crate::terminal::message; +use crate::terminal::{message, open_browser}; use crate::watch::watch_and_build; pub fn preview( @@ -93,22 +92,6 @@ pub struct PreviewOpt { pub headless: bool, } -fn open_browser(url: &str) -> Result<(), failure::Error> { - let _output = if cfg!(target_os = "windows") { - let url_escaped = url.replace("&", "^&"); - let windows_cmd = format!("start {}", url_escaped); - Command::new("cmd").args(&["/C", &windows_cmd]).output()? - } else if cfg!(target_os = "linux") { - let linux_cmd = format!(r#"xdg-open "{}""#, url); - Command::new("sh").arg("-c").arg(&linux_cmd).output()? - } else { - let mac_cmd = format!(r#"open "{}""#, url); - Command::new("sh").arg("-c").arg(&mac_cmd).output()? - }; - - Ok(()) -} - fn client_request(payload: &RequestPayload, script_id: &str, sites_preview: bool) { let client = http::client(); diff --git a/src/terminal/browser.rs b/src/terminal/browser.rs new file mode 100644 index 000000000..a8ce5bbba --- /dev/null +++ b/src/terminal/browser.rs @@ -0,0 +1,17 @@ +use std::process::Command; + +pub fn open_browser(url: &str) -> Result<(), failure::Error> { + let _output = if cfg!(target_os = "windows") { + let url_escaped = url.replace("&", "^&"); + let windows_cmd = format!("start {}", url_escaped); + Command::new("cmd").args(&["/C", &windows_cmd]).output()? + } else if cfg!(target_os = "linux") { + let linux_cmd = format!(r#"xdg-open "{}""#, url); + Command::new("sh").arg("-c").arg(&linux_cmd).output()? + } else { + let mac_cmd = format!(r#"open "{}""#, url); + Command::new("sh").arg("-c").arg(&mac_cmd).output()? + }; + + Ok(()) +} diff --git a/src/terminal/mod.rs b/src/terminal/mod.rs index 73dff93cc..a4187af9e 100644 --- a/src/terminal/mod.rs +++ b/src/terminal/mod.rs @@ -1,4 +1,6 @@ +mod browser; pub mod emoji; pub mod interactive; pub mod message; pub mod styles; +pub use browser::open_browser; From d1084a85ecd174eafa8ada13cff055a144643735 Mon Sep 17 00:00:00 2001 From: jspspike Date: Thu, 30 Jul 2020 12:39:59 -0500 Subject: [PATCH 02/10] Changed name --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b51aad5df..8267e9f70 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -89,7 +89,7 @@ jobs: if: matrix.build == 'macos' run: brew install p7zip - - name: Install vcpkg OpenSSL (Windows) + - name: Install OpenSSL via vcpkg (Windows) if: matrix.build == 'windows' run: | git clone https://github.com/microsoft/vcpkg From 8e0db1ea31908eb208ba28e84e554f1317e77b22 Mon Sep 17 00:00:00 2001 From: jspspike Date: Thu, 30 Jul 2020 18:19:18 -0500 Subject: [PATCH 03/10] Added login --- .github/workflows/release.yml | 12 +---- Cargo.lock | 22 +++++++++ Cargo.toml | 1 + src/commands/login.rs | 6 ++- src/login/mod.rs | 85 +++++++++++++++++++++++++++++++++-- src/main.rs | 5 +++ src/terminal/emoji.rs | 1 + 7 files changed, 115 insertions(+), 17 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8267e9f70..abd8fb723 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -89,15 +89,6 @@ jobs: if: matrix.build == 'macos' run: brew install p7zip - - name: Install OpenSSL via vcpkg (Windows) - if: matrix.build == 'windows' - run: | - git clone https://github.com/microsoft/vcpkg - .\vcpkg\bootstrap-vcpkg.bat - .\vcpkg\vcpkg install openssl:x64-windows - env: - VCPKGRS_DYNAMIC: 1 - - name: Build (Linux) if: matrix.build == 'linux' run: | @@ -110,10 +101,9 @@ jobs: - name: Build (Windows) if: matrix.build == 'windows' - run: cargo build --release + run: cargo build --release --features vendored-openssl env: RUSTFLAGS: -Ctarget-feature=+crt-static - VCPKGRS_DYNAMIC: 1 - name: Create artifact directory run: | diff --git a/Cargo.lock b/Cargo.lock index 11da0a8cd..668c340a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -618,6 +618,17 @@ dependencies = [ "version_check", ] +[[package]] +name = "eventual" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9bda6d089b434ca50f3d6feb5fca421309b8bac97b8be9af51cff879fa3f54b" +dependencies = [ + "log 0.3.9", + "syncbox", + "time", +] + [[package]] name = "exitfailure" version = "0.5.1" @@ -2183,6 +2194,16 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "syncbox" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05bc2b72659ac27a2d0e7c4166c8596578197c4c41f767deab12c81f523b85c7" +dependencies = [ + "log 0.3.9", + "time", +] + [[package]] name = "synstructure" version = "0.12.4" @@ -2803,6 +2824,7 @@ dependencies = [ "console 0.11.3", "dirs 3.0.1", "env_logger", + "eventual", "exitfailure", "failure", "flate2", diff --git a/Cargo.toml b/Cargo.toml index 9a25d8936..b00bd94d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ config = "0.10.1" console = "0.11.3" dirs = "3.0.1" env_logger = "0.7.1" +eventual = "0.1.7" exitfailure = "0.5.1" failure = "0.1.8" flate2 = "1.0.16" diff --git a/src/commands/login.rs b/src/commands/login.rs index 48e0a3027..92a44e8f0 100644 --- a/src/commands/login.rs +++ b/src/commands/login.rs @@ -1,3 +1,5 @@ -//use crate::login; +use crate::login; -pub fn run() {} +pub fn run() -> Result<(), failure::Error> { + login::run() +} diff --git a/src/login/mod.rs b/src/login/mod.rs index 5a4b8eb97..bb9b98923 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -1,15 +1,92 @@ -//use crate::terminal::{interactive::confirm, open_browser}; +use eventual::Timer; +use indicatif::{ProgressBar, ProgressStyle}; +use openssl::base64; +use openssl::rsa::{Padding, Rsa}; +use percent_encoding::{percent_encode, NON_ALPHANUMERIC}; +use std::collections::HashMap; +use std::str; -//use openssl::base64; -use openssl::rsa::Rsa; +use crate::commands::config::global_config; +use crate::settings::global_user::GlobalUser; +use crate::terminal::{interactive, message, open_browser}; pub fn run() -> Result<(), failure::Error> { let rsa = Rsa::generate(1024)?; - let _ = rsa.public_key_to_pem_pkcs1()?; + let pubkey = rsa.public_key_to_pem_pkcs1()?; + + // Convert key to string and remove header and footer + let pubkey_str = str::from_utf8(&pubkey)?; + let pubkey_filtered = pubkey_str + .lines() + .filter(|line| !line.starts_with("-")) + .fold(String::new(), |mut data, line| { + data.push_str(&line); + data + }); + let pubkey_encoded = percent_encode(pubkey_filtered.as_bytes(), NON_ALPHANUMERIC).to_string(); + + let browser_permission = + interactive::confirm("Allow Wrangler to a open page in your browser?")?; + if !browser_permission { + failure::bail!("In order to use login you must allow Wrangler to open pages in your browser. If you don't want to do this consder using `wrangler config`"); + } + + open_browser(&format!( + "https://dash.staging.cloudflare.com/wrangler?key={0}", + pubkey_encoded + ))?; + + let encrypted_token_str = poll_token(pubkey_filtered)?; + let encrypted_token = base64::decode_block(encrypted_token_str.as_str())?; + let mut token_bytes: [u8; 128] = [0; 128]; + + rsa.private_decrypt(&encrypted_token, &mut token_bytes, Padding::PKCS1)?; + let token = str::from_utf8(&token_bytes)?; + + let user = GlobalUser::TokenAuth { + api_token: token.to_string(), + }; + global_config(&user, true)?; Ok(()) } +/// Poll for token, bail after 500 seconds. +fn poll_token(token_id: String) -> Result { + let mut request_params = HashMap::new(); + request_params.insert("token-id", token_id); + + let client = reqwest::blocking::Client::new(); + let timer = Timer::new().interval_ms(1000).iter(); + + let style = ProgressStyle::default_spinner().template("{spinner} {msg}"); + let spinner = ProgressBar::new_spinner().with_style(style); + spinner.set_message("Waiting to be sent api token..."); + spinner.enable_steady_tick(20); + + let mut seconds = 0; + + for _ in timer { + let res = client + .get("https://api.staging.cloudflare.com/client/v4/workers/token") + .json(&request_params) + .send()?; + + if res.status().is_success() { + return Ok(res.text_with_charset("utf-8")?); + } + + if seconds >= 500 { + break; + } + seconds += 1; + } + + failure::bail!( + "Timed out when waiting for api token. Try using `wrangler config` if login fails to work." + ); +} + #[cfg(test)] mod tests { use openssl::rsa::Rsa; diff --git a/src/main.rs b/src/main.rs index ada707707..189c3f5d5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -615,6 +615,9 @@ fn run() -> Result<(), failure::Error> { ) .arg(verbose_arg.clone()) ) + .subcommand( + SubCommand::with_name("login") + .about(&*format!("{} Give Wrangler permission for your Workers with your Cloudflare login", emoji::UNLOCKED))) .get_matches(); let mut is_preview = false; @@ -1069,6 +1072,8 @@ fn run() -> Result<(), failure::Error> { let verbose = matches.is_present("verbose"); commands::tail::start(&target, &user, tunnel_port, metrics_port, verbose)?; + } else if matches.subcommand_matches("login").is_some() { + commands::login::run()?; } Ok(()) } diff --git a/src/terminal/emoji.rs b/src/terminal/emoji.rs index 95fbbf8f0..ed6bbe166 100644 --- a/src/terminal/emoji.rs +++ b/src/terminal/emoji.rs @@ -36,3 +36,4 @@ pub static UP: Emoji = Emoji("🆙 ", ""); pub static WARN: Emoji = Emoji("⚠️ ", ""); pub static WAVING: Emoji = Emoji("👋 ", ""); pub static WORKER: Emoji = Emoji("👷 ", ""); +pub static UNLOCKED: Emoji = Emoji("🔓", ""); From b90a48c2d04b53d0b834ec1a909b2af25a85733e Mon Sep 17 00:00:00 2001 From: jspspike Date: Thu, 30 Jul 2020 18:44:49 -0500 Subject: [PATCH 04/10] Added messaging --- README.md | 5 +++++ src/login/mod.rs | 11 ++++------- src/main.rs | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7a58e5fc6..e1cf2d605 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,11 @@ $ wrangler publish Additionally, you can configure different [environments](https://developers.cloudflare.com/workers/tooling/wrangler/configuration/environments). + +### 🔓 `login` + + Authenticate Wrangler with your Cloudflare login. This will configure Wrangler to have access to your Workers and is the alternative to `wrangler config`. + ### 🔧 `config` Configure your global Cloudflare user. This is an interactive command that will prompt you for your API token: diff --git a/src/login/mod.rs b/src/login/mod.rs index bb9b98923..72b9dd1cb 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -8,7 +8,7 @@ use std::str; use crate::commands::config::global_config; use crate::settings::global_user::GlobalUser; -use crate::terminal::{interactive, message, open_browser}; +use crate::terminal::{interactive, open_browser}; pub fn run() -> Result<(), failure::Error> { let rsa = Rsa::generate(1024)?; @@ -18,7 +18,7 @@ pub fn run() -> Result<(), failure::Error> { let pubkey_str = str::from_utf8(&pubkey)?; let pubkey_filtered = pubkey_str .lines() - .filter(|line| !line.starts_with("-")) + .filter(|line| !line.starts_with('-')) .fold(String::new(), |mut data, line| { data.push_str(&line); data @@ -64,9 +64,7 @@ fn poll_token(token_id: String) -> Result { spinner.set_message("Waiting to be sent api token..."); spinner.enable_steady_tick(20); - let mut seconds = 0; - - for _ in timer { + for (seconds, _) in timer.enumerate() { let res = client .get("https://api.staging.cloudflare.com/client/v4/workers/token") .json(&request_params) @@ -79,11 +77,10 @@ fn poll_token(token_id: String) -> Result { if seconds >= 500 { break; } - seconds += 1; } failure::bail!( - "Timed out when waiting for api token. Try using `wrangler config` if login fails to work." + "Timed out while waiting for api token. Try using `wrangler config` if login fails to work." ); } diff --git a/src/main.rs b/src/main.rs index 189c3f5d5..166fa65b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -617,7 +617,7 @@ fn run() -> Result<(), failure::Error> { ) .subcommand( SubCommand::with_name("login") - .about(&*format!("{} Give Wrangler permission for your Workers with your Cloudflare login", emoji::UNLOCKED))) + .about(&*format!("{} Authenticate Wrangler with your Cloudflare login", emoji::UNLOCKED))) .get_matches(); let mut is_preview = false; From fd2d1b43d9aee2c404bab72b777763e5c5d9b0e7 Mon Sep 17 00:00:00 2001 From: jjohnson Date: Fri, 31 Jul 2020 13:21:40 -0500 Subject: [PATCH 05/10] Read result out of response --- src/http/cf.rs | 7 ++++--- src/login/mod.rs | 11 +++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/http/cf.rs b/src/http/cf.rs index e8b9033a4..97203fd8d 100644 --- a/src/http/cf.rs +++ b/src/http/cf.rs @@ -5,6 +5,7 @@ use cloudflare::framework::auth::Credentials; use cloudflare::framework::response::ApiFailure; use cloudflare::framework::{Environment, HttpApiClient, HttpApiClientConfig}; use http::StatusCode; +use url::Url; use crate::http::{feature::headers, Feature, DEFAULT_HTTP_TIMEOUT_SECONDS}; use crate::settings::global_user::GlobalUser; @@ -19,7 +20,7 @@ pub fn cf_v4_client(user: &GlobalUser) -> Result HttpApiClient::new( Credentials::from(user.to_owned()), config, - Environment::Production, + Environment::Custom(Url::parse("https://api.staging.cloudflare.com/client/v4/")?), ) } @@ -35,7 +36,7 @@ pub fn featured_cf_v4_client( HttpApiClient::new( Credentials::from(user.to_owned()), config, - Environment::Production, + Environment::Custom(Url::parse("https://api.staging.cloudflare.com/client/v4/")?), ) } @@ -46,7 +47,7 @@ pub fn cf_v4_api_client_async( async_api::Client::new( Credentials::from(user.to_owned()), config, - Environment::Production, + Environment::Custom(Url::parse("https://api.staging.cloudflare.com/client/v4/")?), ) } diff --git a/src/login/mod.rs b/src/login/mod.rs index 72b9dd1cb..b2827925e 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -5,6 +5,7 @@ use openssl::rsa::{Padding, Rsa}; use percent_encoding::{percent_encode, NON_ALPHANUMERIC}; use std::collections::HashMap; use std::str; +use serde::Deserialize; use crate::commands::config::global_config; use crate::settings::global_user::GlobalUser; @@ -41,7 +42,7 @@ pub fn run() -> Result<(), failure::Error> { let mut token_bytes: [u8; 128] = [0; 128]; rsa.private_decrypt(&encrypted_token, &mut token_bytes, Padding::PKCS1)?; - let token = str::from_utf8(&token_bytes)?; + let token = str::from_utf8(&token_bytes)?.trim_matches(char::from(0)); let user = GlobalUser::TokenAuth { api_token: token.to_string(), @@ -51,6 +52,11 @@ pub fn run() -> Result<(), failure::Error> { Ok(()) } +#[derive(Deserialize)] +struct TokenResponse { + result: String +} + /// Poll for token, bail after 500 seconds. fn poll_token(token_id: String) -> Result { let mut request_params = HashMap::new(); @@ -71,7 +77,8 @@ fn poll_token(token_id: String) -> Result { .send()?; if res.status().is_success() { - return Ok(res.text_with_charset("utf-8")?); + let body: TokenResponse = res.json()?; + return Ok(body.result); } if seconds >= 500 { From 60e181200295261386b2637c64f3ea00add4f711 Mon Sep 17 00:00:00 2001 From: jspspike Date: Fri, 31 Jul 2020 13:42:13 -0500 Subject: [PATCH 06/10] Made openssl vendorded by default --- .github/workflows/release.yml | 4 ++-- Cargo.lock | 4 ++-- Cargo.toml | 7 +++---- src/login/mod.rs | 4 ++-- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index abd8fb723..9c30bc7be 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -93,7 +93,7 @@ jobs: if: matrix.build == 'linux' run: | rustup target add ${{ env.LINUX_TARGET }} - cargo build --release --target ${{ env.LINUX_TARGET }} --features vendored-openssl + cargo build --release --target ${{ env.LINUX_TARGET }} - name: Build (MacOS) if: matrix.build == 'macos' @@ -101,7 +101,7 @@ jobs: - name: Build (Windows) if: matrix.build == 'windows' - run: cargo build --release --features vendored-openssl + run: cargo build --release env: RUSTFLAGS: -Ctarget-feature=+crt-static diff --git a/Cargo.lock b/Cargo.lock index 668c340a0..c2eac0ce9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1529,9 +1529,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-src" -version = "111.10.0+1.1.1g" +version = "111.10.2+1.1.1g" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47cd4a96d49c3abf4cac8e8a80cba998a030c75608f158fb1c5f609772f265e6" +checksum = "a287fdb22e32b5b60624d4a5a7a02dbe82777f730ec0dbc42a0554326fef5a70" dependencies = [ "cc", ] diff --git a/Cargo.toml b/Cargo.toml index b00bd94d8..fe1828d74 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ lazy_static = "1.4.0" log = "0.4.11" notify = "4.0.15" number_prefix = "0.4.0" -openssl = { version = "0.10.29"} +openssl = { version = "0.10.29", optional = true} percent-encoding = "2.1.0" predicates = "1.0.5" prettytable-rs = "0.8.0" @@ -68,9 +68,8 @@ fs_extra = "1.1.0" predicates = "1.0.5" [features] -# We build Linux binaries with vendored openssl -# to avoid SSL issues -vendored-openssl = ['openssl/vendored'] +default = ['openssl/vendored'] +sys-openssl = ['openssl'] # Treat compiler warnings as a build error. # This only runs in CI by default diff --git a/src/login/mod.rs b/src/login/mod.rs index b2827925e..84fdbc14d 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -3,9 +3,9 @@ use indicatif::{ProgressBar, ProgressStyle}; use openssl::base64; use openssl::rsa::{Padding, Rsa}; use percent_encoding::{percent_encode, NON_ALPHANUMERIC}; +use serde::Deserialize; use std::collections::HashMap; use std::str; -use serde::Deserialize; use crate::commands::config::global_config; use crate::settings::global_user::GlobalUser; @@ -54,7 +54,7 @@ pub fn run() -> Result<(), failure::Error> { #[derive(Deserialize)] struct TokenResponse { - result: String + result: String, } /// Poll for token, bail after 500 seconds. From 494d2a1f1c3f235b0a2359dade98447e032832a5 Mon Sep 17 00:00:00 2001 From: jspspike Date: Fri, 31 Jul 2020 13:59:13 -0500 Subject: [PATCH 07/10] Config messaging changes --- Cargo.toml | 3 ++- README.md | 4 ++-- src/main.rs | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fe1828d74..6d2bc64f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,7 +38,7 @@ lazy_static = "1.4.0" log = "0.4.11" notify = "4.0.15" number_prefix = "0.4.0" -openssl = { version = "0.10.29", optional = true} +openssl = { version = "0.10.29", optional = true } percent-encoding = "2.1.0" predicates = "1.0.5" prettytable-rs = "0.8.0" @@ -68,6 +68,7 @@ fs_extra = "1.1.0" predicates = "1.0.5" [features] +# OpenSSL is vendored by default, can use system OpenSSL through feature flag. default = ['openssl/vendored'] sys-openssl = ['openssl'] diff --git a/README.md b/README.md index e1cf2d605..e09d1de8f 100644 --- a/README.md +++ b/README.md @@ -91,11 +91,11 @@ $ wrangler publish ### 🔓 `login` - Authenticate Wrangler with your Cloudflare login. This will configure Wrangler to have access to your Workers and is the alternative to `wrangler config`. + Authenticate Wrangler with your Cloudflare login. This will prompt you with a Cloudflare account login page and is the alternative to `wrangler config`. ### 🔧 `config` - Configure your global Cloudflare user. This is an interactive command that will prompt you for your API token: + Authenticate Wrangler with a Cloudflare API Token. This is an interactive command that will prompt you for your API token: ```bash wrangler config diff --git a/src/main.rs b/src/main.rs index 166fa65b9..97c32c1c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -550,7 +550,7 @@ fn run() -> Result<(), failure::Error> { .subcommand( SubCommand::with_name("config") .about(&*format!( - "{} Set up wrangler with your Cloudflare account", + "{} Authenticate Wrangler by copying in your Cloudflare API Token", emoji::SLEUTH )) .arg( @@ -617,7 +617,7 @@ fn run() -> Result<(), failure::Error> { ) .subcommand( SubCommand::with_name("login") - .about(&*format!("{} Authenticate Wrangler with your Cloudflare login", emoji::UNLOCKED))) + .about(&*format!("{} Authenticate Wrangler by logging in with your Cloudflare account", emoji::UNLOCKED))) .get_matches(); let mut is_preview = false; From ff5a268684b3c240c1b7581e56486a60c6cdd428 Mon Sep 17 00:00:00 2001 From: jspspike Date: Fri, 31 Jul 2020 14:31:44 -0500 Subject: [PATCH 08/10] Possible fix for CI failure --- Cargo.toml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 6d2bc64f6..e41127680 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,8 +70,10 @@ predicates = "1.0.5" [features] # OpenSSL is vendored by default, can use system OpenSSL through feature flag. default = ['openssl/vendored'] +# Keeping feature for users already using this feature flag +vendored-openssl = ['openssl/vendored'] sys-openssl = ['openssl'] # Treat compiler warnings as a build error. # This only runs in CI by default -strict = [] +strict = ['openssl/vendored'] From 0535533b731b9ea59e7cb8efe1d609374aec7f6f Mon Sep 17 00:00:00 2001 From: jspspike Date: Sat, 1 Aug 2020 15:27:23 -0500 Subject: [PATCH 09/10] Fixed wording for messages --- src/login/mod.rs | 10 +++++----- src/main.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/login/mod.rs b/src/login/mod.rs index 84fdbc14d..cdc701584 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -19,7 +19,7 @@ pub fn run() -> Result<(), failure::Error> { let pubkey_str = str::from_utf8(&pubkey)?; let pubkey_filtered = pubkey_str .lines() - .filter(|line| !line.starts_with('-')) + .filter(|line| !line.starts_with("---")) .fold(String::new(), |mut data, line| { data.push_str(&line); data @@ -27,9 +27,9 @@ pub fn run() -> Result<(), failure::Error> { let pubkey_encoded = percent_encode(pubkey_filtered.as_bytes(), NON_ALPHANUMERIC).to_string(); let browser_permission = - interactive::confirm("Allow Wrangler to a open page in your browser?")?; + interactive::confirm("Allow Wrangler to open a page in your browser?")?; if !browser_permission { - failure::bail!("In order to use login you must allow Wrangler to open pages in your browser. If you don't want to do this consder using `wrangler config`"); + failure::bail!("In order to log in you must allow Wrangler to open your browser. If you don't want to do this consider using `wrangler config`"); } open_browser(&format!( @@ -67,7 +67,7 @@ fn poll_token(token_id: String) -> Result { let style = ProgressStyle::default_spinner().template("{spinner} {msg}"); let spinner = ProgressBar::new_spinner().with_style(style); - spinner.set_message("Waiting to be sent api token..."); + spinner.set_message("Waiting for API token..."); spinner.enable_steady_tick(20); for (seconds, _) in timer.enumerate() { @@ -87,7 +87,7 @@ fn poll_token(token_id: String) -> Result { } failure::bail!( - "Timed out while waiting for api token. Try using `wrangler config` if login fails to work." + "Timed out while waiting for API token. Try using `wrangler config` if login fails to work." ); } diff --git a/src/main.rs b/src/main.rs index 97c32c1c3..8e97aafb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -550,7 +550,7 @@ fn run() -> Result<(), failure::Error> { .subcommand( SubCommand::with_name("config") .about(&*format!( - "{} Authenticate Wrangler by copying in your Cloudflare API Token", + "{} Authenticate Wrangler with a Cloudflare API Token or Global API Key", emoji::SLEUTH )) .arg( @@ -617,7 +617,7 @@ fn run() -> Result<(), failure::Error> { ) .subcommand( SubCommand::with_name("login") - .about(&*format!("{} Authenticate Wrangler by logging in with your Cloudflare account", emoji::UNLOCKED))) + .about(&*format!("{} Authenticate Wrangler with your Cloudflare username and password", emoji::UNLOCKED))) .get_matches(); let mut is_preview = false; From ca7f097efd3b49fabf896836ca9e4ec4af682d24 Mon Sep 17 00:00:00 2001 From: jspspike Date: Mon, 3 Aug 2020 14:15:52 -0500 Subject: [PATCH 10/10] Changed to prod --- src/http/cf.rs | 7 +++---- src/login/mod.rs | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/http/cf.rs b/src/http/cf.rs index 97203fd8d..e8b9033a4 100644 --- a/src/http/cf.rs +++ b/src/http/cf.rs @@ -5,7 +5,6 @@ use cloudflare::framework::auth::Credentials; use cloudflare::framework::response::ApiFailure; use cloudflare::framework::{Environment, HttpApiClient, HttpApiClientConfig}; use http::StatusCode; -use url::Url; use crate::http::{feature::headers, Feature, DEFAULT_HTTP_TIMEOUT_SECONDS}; use crate::settings::global_user::GlobalUser; @@ -20,7 +19,7 @@ pub fn cf_v4_client(user: &GlobalUser) -> Result HttpApiClient::new( Credentials::from(user.to_owned()), config, - Environment::Custom(Url::parse("https://api.staging.cloudflare.com/client/v4/")?), + Environment::Production, ) } @@ -36,7 +35,7 @@ pub fn featured_cf_v4_client( HttpApiClient::new( Credentials::from(user.to_owned()), config, - Environment::Custom(Url::parse("https://api.staging.cloudflare.com/client/v4/")?), + Environment::Production, ) } @@ -47,7 +46,7 @@ pub fn cf_v4_api_client_async( async_api::Client::new( Credentials::from(user.to_owned()), config, - Environment::Custom(Url::parse("https://api.staging.cloudflare.com/client/v4/")?), + Environment::Production, ) } diff --git a/src/login/mod.rs b/src/login/mod.rs index cdc701584..06e61485e 100644 --- a/src/login/mod.rs +++ b/src/login/mod.rs @@ -33,7 +33,7 @@ pub fn run() -> Result<(), failure::Error> { } open_browser(&format!( - "https://dash.staging.cloudflare.com/wrangler?key={0}", + "https://dash.cloudflare.com/wrangler?key={0}", pubkey_encoded ))?; @@ -72,7 +72,7 @@ fn poll_token(token_id: String) -> Result { for (seconds, _) in timer.enumerate() { let res = client - .get("https://api.staging.cloudflare.com/client/v4/workers/token") + .get("https://api.cloudflare.com/client/v4/workers/token") .json(&request_params) .send()?;