From 881e431738aac3a8d9c324e85332bce6f5d15d0c Mon Sep 17 00:00:00 2001 From: Alex Kehayias Date: Sun, 10 May 2020 15:37:48 -0700 Subject: [PATCH] Fix conflicting async runtimes. Re-prompt for login on failure. --- cli/src/builder.rs | 13 ++++--------- cli/src/main.rs | 3 ++- cli/src/upload_client.rs | 11 +++++------ 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/cli/src/builder.rs b/cli/src/builder.rs index ea12f15..a0c750b 100644 --- a/cli/src/builder.rs +++ b/cli/src/builder.rs @@ -84,7 +84,7 @@ impl<'a> AppBuilder<'a> { /// Upload the app file bundle to S3. It will be immediately /// available on the public internet. - pub fn upload(&self, client: S3Client) -> Result<(), Error> { + pub async fn upload(&self, client: S3Client) -> Result<(), Error> { // In order to get errors out of tokio they need to be share // the data in a thread safe way let failures = Arc::new(Mutex::new(0)); @@ -92,7 +92,7 @@ impl<'a> AppBuilder<'a> { // loop runs let fail_count = Arc::clone(&failures); - let work = stream::iter(self.files.clone()) + stream::iter(self.files.clone()) .for_each(|f| { // References the outer failures. This will get moved into // the scope of the async task closure @@ -131,13 +131,8 @@ impl<'a> AppBuilder<'a> { } } } - }); - - // Actually execute the async tasks, blocking the main thread - // until idle (completed all spawned tasks) - let mut runtime = tokio::runtime::Runtime::new() - .expect("Failed to initialize runtime"); - runtime.block_on(async { work.await }); + }) + .await; if *fail_count.lock().unwrap() > 0 { Err(format_err!("Failed to upload app to S3")) diff --git a/cli/src/main.rs b/cli/src/main.rs index 9c1cf2a..7f652f5 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -410,7 +410,7 @@ wasm_path=\"target/wasm32-unknown-unknown/release/{}.wasm\" ) ) } - app.upload(s3_client).context("Failed to upload app")?; + app.upload(s3_client).await.context("Failed to upload app")?; println!("{}", format!("Your app is available at {}", url)); } // Sub command parsing will print the error and exit @@ -420,6 +420,7 @@ wasm_path=\"target/wasm32-unknown-unknown/release/{}.wasm\" _ => unimplemented!() }; }; + Ok(()) } diff --git a/cli/src/upload_client.rs b/cli/src/upload_client.rs index 8f06bc4..9fadaff 100644 --- a/cli/src/upload_client.rs +++ b/cli/src/upload_client.rs @@ -55,14 +55,13 @@ async fn ensure_id_token(cache: &FileCache, id_provider_client: &CognitoIdentity .id_token.expect("No ID token"), Err(error) => { println!("Getting refresh token failed: {}", error); - - let creds = prompt::login(); - let username = creds.username; - let password = creds.password; - let mut id_token = None; while let None = id_token { + let creds = prompt::login(); + let username = creds.username; + let password = creds.password; + let result = account::login(&id_provider_client, &username, &password).await; if result.is_err() { @@ -93,7 +92,7 @@ async fn ensure_id_token(cache: &FileCache, id_provider_client: &CognitoIdentity } pub async fn authenticated_client(cache: &FileCache) -> Result { - let id_provider_client = CognitoIdentityProviderClient::new(Region::UsWest2); + let id_provider_client = account::anonymous_identity_provider_client(); let id_client = account::anonymous_identity_client(); let refresh_token = ensure_refresh_token(&cache, &id_provider_client).await;