Earnest-Labs / aws-sts

Generation of AWS STS tokens via SAML authentication.
67 stars 18 forks source link

fix/refactor get token to improve readability #21

Closed sortigoza closed 5 years ago

sortigoza commented 5 years ago

Before: lots of nesting and a big function, with mixed high and low level details:

sts.assumeRoleWithSAML({    
...
}, function (err, token) {      
    sts.assumeRole({    
        if...
        if...
        ...
    }, function (err, assumedToken) {   
        if...
        ...
    }); 
});

now is much clear what is happening there:

      this.spinner.start();
      const token = await this.getSTSToken();

       if (this.isDefaultAccount()) {
        this.spinner.stop();
        return token;
      }

       // need to switch roles to the other account
      const assumedToken = await this.getAssumeRoleToken(token);
      this.spinner.stop();
      return assumedToken;
krishicks commented 5 years ago

I prefer how it looked before. I don't agree with the explanations for why certain decisions were made.

sortigoza commented 5 years ago

can you explain why do you not agree? this is a previous step to introduce the additional logic to handle the new configuration.