-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Refactor decoding Base64 to byte[] #9912
Conversation
…64 to byte[] Signed-off-by: MichaelMorris <[email protected]>
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.
Thanks for the PR ... I left one comment that might apply to more places.
@@ -127,10 +128,10 @@ private static KeycloakInstance createKeycloakInstance(String namespaceName) { | |||
Secret keycloakSecret = kubeClient().getSecret(namespaceName, KEYCLOAK_SECRET_NAME); | |||
|
|||
String usernameEncoded = keycloakSecret.getData().get("username"); | |||
String username = new String(Base64.getDecoder().decode(usernameEncoded.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); | |||
String username = new String(Util.decodeBytesFromBase64(usernameEncoded.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); |
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.
Here, but also in the other cases of this ... should these go directly to String instead using the already existing Utils.decodeFromBase64(String data, Charset charset)
method? I think when the byte[]
is actually used, Util.decodeBytesFromBase64
makes sense. but where we just create a String from it right away, we should use the method to decode it directly to String, or?
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.
Yes, thats a good point, I've updated the implementation
Signed-off-by: MichaelMorris <[email protected]>
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.
Few more nits. But LGTM overall, thanks.
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
|
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.
Not needed I guess.
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.
Done
String username = Util.decodeFromBase64(usernameEncoded); | ||
|
||
String passwordEncoded = keycloakSecret.getData().get("password"); | ||
String password = new String(Base64.getDecoder().decode(passwordEncoded.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); | ||
String password = Util.decodeFromBase64(passwordEncoded); |
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.
Should these keep the UTF_8 charset?
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.
Done
Signed-off-by: MichaelMorris <[email protected]>
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.
Thanks. LGTM. I will run the system tests, but I do not expect anything to break there.
/azp run regression |
Azure Pipelines successfully started running 1 pipeline(s). |
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.
LGTM. Thanks for the PR!
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.
Thanks.
Type of change
Refactoring
Description
Introduce new methods in operator-common Util class for decoding Base64 to byte[] and refactor code to use the new methods
Closes #9911
Checklist
Please go through this checklist and make sure all applicable tasks have been done