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

Feature/add account number verification #14

Closed
wants to merge 5 commits into from
Closed

Feature/add account number verification #14

wants to merge 5 commits into from

Conversation

macdude357
Copy link

What Changed

Added AWS Account verification

Why

Solves issue #8
Todo:

  • Add tests
  • Add docs
  • [Not sure what this is ] Add yourself to contributors (run yarn contributors:add)

@macdude357
Copy link
Author

@pandian912 Looks like the build failed installing the JDK. I don't think that's related to my PR though.

@pandian912
Copy link
Collaborator

@pandian912 Looks like the build failed installing the JDK. I don't think that's related to my PR though.

take a pull from master plz

@macdude357
Copy link
Author

I pulled from master but this PR is for develop so it pulled in other changes from master. Did you mean for me to rebase with develop?

@macdude357
Copy link
Author

I fixed it by cherry picking the travis.yml change from master.

@@ -150,14 +167,24 @@ public BasicCredentials() {
//ignore to use amazon default provider
}
}

public BasicCredentials(AWSAccountValidator validator) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is a new constructor which will not be invoked by default... would recommend adding this logic in the default constructor so that all existing usages get this feature

Copy link
Author

Choose a reason for hiding this comment

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

I added this so that I could inject a mock instance in order to test with. The logic in getCredentials will create an instance of AWSAccountValidator if one does not exist so existing usages will get this feature


public BasicCredentials(AWSAccountValidator validator) {
this.validator = validator;
}

/**
* Returns AWSCredentials for the given user/account. Reverts to default credentials provider if no credentials exist.
* @return AWSCredentials
*/
public AWSCredentials getAwsCredentials() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • This function is a failsafe and the actual logic of fetching the credentials(via various methods) is done in the default constructor.... I would leave this function alone and make the validator call from the default constructor...
  • Also i would pass the validator function the AWSCredentials object or pass the account number fetched from the account as validator function does not have access to credentials

Copy link
Author

Choose a reason for hiding this comment

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

Ideally, there should be one method that creates the credentials. So I'd like to consolidate that code into one method and then put the validation logic there. Does that make sense?

public void validateAccount(String targetAccount) {

if (targetAccount != null) {
GetCallerIdentityRequest getCallerIdentityRequest = new GetCallerIdentityRequest();
Copy link
Collaborator

Choose a reason for hiding this comment

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

                    .withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
                    .withRegion(region)
                    .build()
                    .getCallerIdentity(new GetCallerIdentityRequest())
                    .getAccount();

Copy link
Author

Choose a reason for hiding this comment

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

If the code builds the AWSCredentialsProvider on the fly, there's no real way to unit test the code without having valid credentials (ie, no way to inject a mock provider).

@macdude357 macdude357 closed this Nov 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants