-
Notifications
You must be signed in to change notification settings - Fork 21
refactor: prepare for ContainerAuthenticator impl #139
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
Conversation
This commit introduces the IamRequestBasedAuthenticator class which will serve as a common base class for any authenticator impl that interacts with the IAM token service to obtain an access token. Common code was moved from the IamAuthenticator class to the new IamRequestBasedAuthenticator base class.
private static final String DEFAULT_IAM_URL = "https://iam.cloud.ibm.com"; | ||
private static final String OPERATION_PATH = "/identity/token"; | ||
private static final String GRANT_TYPE = "grant_type"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed these constants because they are used only in the requestToken() function and I actually think the code is more readable and understandable WITHOUT using these contants.
|
||
// Properties specific to an IAM authenticator. | ||
private String url; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most of the rest of the code deletions you see in this class are due to this code being moved to the new base class.
// Canonicalize the URL by removing the operation path from it if present. | ||
this.url = this.url.substring(0, this.url.length() - OPERATION_PATH.length()); | ||
this.setURL(StringUtils.removeEnd(this.getURL(), OPERATION_PATH)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: StringUtils.removeEnd() will only remove OPERATION_PATH from the end of the string if the string in fact ends with OPERATION_PATH :)
@@ -361,13 +348,14 @@ protected void init(String apikey, String url, String clientId, String clientSec | |||
|
|||
@Override | |||
public void validate() { | |||
super.validate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new base class has a validate function that validates the common fields contained in that class.
@@ -0,0 +1,127 @@ | |||
/** | |||
* (C) Copyright IBM Corp. 2015, 2021. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the new base class. I'll leave the initial copyright year (2015) here since this code was copied from the other file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 👍
I also tested these changes in my local sandbox environment with the platform services Java SDK with a handful of integration tests and they all passed. |
🎉 This PR is included in version 9.12.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This commit introduces the IamRequestBasedAuthenticator class
which will serve as a common base class for any authenticator
impl that interacts with the IAM token service to obtain an
access token.
Common code was moved from the IamAuthenticator class to
the new IamRequestBasedAuthenticator base class.