Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Fix signup command
Browse files Browse the repository at this point in the history
- Identity client must also use anonymous credentials
- Fix verify email loop never exits
  • Loading branch information
alexkehayias committed May 10, 2020
1 parent b665ce3 commit 1d647aa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
27 changes: 19 additions & 8 deletions cli/src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ use rusoto_cognito_identity::*;
use rusoto_cognito_idp::CognitoIdentityProvider;
use rusoto_cognito_idp::*;


use crate::cache::FileCache;
use crate::config::*;


// By default, CognitoIdentityProviderClient::new will attempt to use
// the aws credentials on the user's machine (e.g. ~/.aws/credentials
// or environment variables). If the user doesn't have any
// credentials, signup and setup will fail. The client returned by
// this function uses anonymous credentials which prevents this issue.
/// By default, CognitoIdentityProviderClient::new will attempt to use the aws
/// credentials on the user's machine (e.g. ~/.aws/credentials or
/// environment variables). If the user doesn't have any credentials,
/// any calls with this client will fail. The client returned by this
/// function uses anonymous credentials which prevents this issue.
pub fn anonymous_identity_provider_client() -> CognitoIdentityProviderClient {
CognitoIdentityProviderClient::new_with(
HttpClient::new().expect("Failed to create HTTP client"),
Expand All @@ -24,6 +23,19 @@ pub fn anonymous_identity_provider_client() -> CognitoIdentityProviderClient {
)
}

/// By default, CognitoIdentityClient::new will attempt to use the aws
/// credentials on the user's machine (e.g. ~/.aws/credentials or
/// environment variables). If the user doesn't have any credentials,
/// any calls with this client will fail. The client returned by this
/// function uses anonymous credentials which prevents this issue.
pub fn anonymous_identity_client() -> CognitoIdentityClient {
CognitoIdentityClient::new_with(
HttpClient::new().expect("Failed to create HTTP client"),
StaticProvider::from(AwsCredentials::default()),
Region::UsWest2
)
}

pub async fn signup(client: &CognitoIdentityProviderClient, email: String,
username: String, password: String)
-> Result<SignUpResponse, RusotoError<SignUpError>> {
Expand Down Expand Up @@ -111,11 +123,10 @@ pub async fn setup(id_provider_client: &CognitoIdentityProviderClient,
Err(error) => {
match error {
RusotoError::Service(e) => Err(e),
_ => panic!("Unknown error")
_ => panic!("Login failed: {}", error)
}
}
}
// future::ready(Ok(())).await
}

pub type AWSCredentialsResponse = Result<GetCredentialsForIdentityResponse,
Expand Down
11 changes: 5 additions & 6 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ async fn run() -> Result<(), Error> {
// TODO first check if there is an existing installation
let values = prompt::signup();
let id_provider_client = account::anonymous_identity_provider_client();
let id_client = CognitoIdentityClient::new(Region::UsWest2);
let id_client = account::anonymous_identity_client();

let user_id = account::signup(&id_provider_client,
values.email.clone(),
Expand All @@ -144,6 +144,7 @@ async fn run() -> Result<(), Error> {

// Prompt the user to confirm they clicked the verification link
let mut email_verified = false;

while !email_verified {
println!("Please check your inbox for an email to verify your account.");
if prompt::is_email_verified() {
Expand All @@ -166,19 +167,17 @@ async fn run() -> Result<(), Error> {
}
})
.context("Failed to set up account")?;

email_verified = true;
}
};

println!("Your account has been successfully set up! You can now deploy to your applications using 'woz deploy'");
},
Command::Setup => {
let values = prompt::login();
// TODO this must use anonymous credentials otherwise
// it will fail on machines that don't have any AWS
// credentials
let id_provider_client = account::anonymous_identity_provider_client();
// CognitoIdentityProviderClient::new_with(rusoto_credential::Anonymous ,Region::UsWest2)
let id_client = CognitoIdentityClient::new(Region::UsWest2);
let id_client = account::anonymous_identity_client();

account::setup(&id_provider_client,
&id_client,
Expand Down
2 changes: 1 addition & 1 deletion cli/src/upload_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async fn ensure_id_token(cache: &FileCache, id_provider_client: &CognitoIdentity

pub async fn authenticated_client(cache: &FileCache) -> Result<S3Client, Error> {
let id_provider_client = CognitoIdentityProviderClient::new(Region::UsWest2);
let id_client = CognitoIdentityClient::new(Region::UsWest2);
let id_client = account::anonymous_identity_client();

let refresh_token = ensure_refresh_token(&cache, &id_provider_client).await;
let identity_id = cache.get("identity").context("Unable to retrieve user ID")?;
Expand Down

0 comments on commit 1d647aa

Please sign in to comment.