Skip to content

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

Merged
merged 1 commit into from
Aug 5, 2021

Conversation

padamstx
Copy link
Member

@padamstx padamstx commented Aug 4, 2021

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.

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.
@padamstx padamstx self-assigned this Aug 4, 2021
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";
Copy link
Member Author

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;
Copy link
Member Author

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));
Copy link
Member Author

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();
Copy link
Member Author

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.
Copy link
Member Author

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.

Copy link
Member

@pyrooka pyrooka left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

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

Looks good! 👍

@padamstx
Copy link
Member Author

padamstx commented Aug 5, 2021

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.

@padamstx padamstx merged commit a44720b into main Aug 5, 2021
@padamstx padamstx deleted the refactor-iam-authenticator branch August 5, 2021 17:57
@ibm-devx-sdk
Copy link
Contributor

🎉 This PR is included in version 9.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants