Throw dedicated error for attempting EC2 auth not on EC2 #983
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in #981:
Each link in the discover chain should throw an
AuthError
to triggermoving onto the next link in the chain. If all links fail, then a
CredentialChainExhausted
error is thrown.In the case of the final link, attempting an EC2 instance profile, the
code was throwing
CredentialChainExhausted
if run not on EC2. Throwingwhen not on EC2 is important (to avoid an unnecessary and slow network
request) but throwing this particular exception is surprising and only
functions because this is the last link in said chain. If any other
authentication mechanisms were added after it, they would never be
reached.
To address this, a new constructor was added to
AuthError
to useinstead. The name is very much up for debate. This is also the first
case of a nullary constructor besides
CredentialChainExhausted
, so Iwasn't sure what to do in
AsAuthError
-- please advise.The original discussion mentioned introduce two new errors:
I did think about this and found that the second case is already
throwing a specific error (
RetrievalError
), so I only changed thefirst case.