Skip to content
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

support gcp authentication refresh token #1810

Merged
merged 6 commits into from
Aug 9, 2021

Conversation

jhbae200
Copy link
Contributor

@jhbae200 jhbae200 commented Aug 2, 2021

Related Issues:

I wrote a "refresh" function because it seems to be using "cmd-path", "cmd-args", "expiry-key", "token-key" to refresh the token.
Need to check that it works on various os platforms.

@k8s-ci-robot
Copy link
Contributor

Thanks for your pull request. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please follow instructions at https://git.k8s.io/community/CLA.md#the-contributor-license-agreement to sign the CLA.

It may take a couple minutes for the CLA signature to be fully registered; after that, please reply here with a new comment and we'll verify. Thanks.


Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Aug 2, 2021
@k8s-ci-robot
Copy link
Contributor

Welcome @jhbae200!

It looks like this is your first PR to kubernetes-client/java 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-client/java has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Aug 2, 2021
@yue9944882
Copy link
Member

@jhbae200 thank you for kicking this off! can you resign your commit by properly setting up your git workspace?

git config user.name ..
git config user.email ...

Signed-off-by: jhbae200 <jhbae200@gmail.com>
Signed-off-by: jhbae200 <jhbae200@gmail.com>
@jhbae200
Copy link
Contributor Author

jhbae200 commented Aug 2, 2021

/check-cla

@jhbae200
Copy link
Contributor Author

jhbae200 commented Aug 2, 2021

/assign @yue9944882

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Aug 2, 2021
Copy link
Member

@yue9944882 yue9944882 left a comment

Choose a reason for hiding this comment

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

@jhbae200 can you run mvn spotless:apply before submitting the changes? thanks!

import java.time.Instant;
import java.util.Date;
import java.util.Map;
import java.util.*;
Copy link
Member

Choose a reason for hiding this comment

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

wildcard import will fail the lint checker

Process process = new ProcessBuilder().command(commandList).start();
process.waitFor(10, TimeUnit.SECONDS);
if(process.exitValue() != 0) {
throw new IOException("Process exit code: "+process.exitValue());
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure that IOException is right here. IllegalStateException(...)?

Copy link
Contributor

@brendandburns brendandburns Aug 2, 2021

Choose a reason for hiding this comment

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

Also, please make the message more descriptive and include the stderr to make the exception more debuggable.

String stderr = IOUtils.toString(process.getErrorStream(), StandardCharsets.UTF_8)
throw new IllegalStateException("Failed to get token (" + process.exitValue() + ") " + stderr

@brendandburns
Copy link
Contributor

Some small comments. Generally looks good. Needs linter formatting to conform to the style guide.

Signed-off-by: jhbae200 <jhbae200@gmail.com>
@jhbae200
Copy link
Contributor Author

jhbae200 commented Aug 3, 2021

Updated the code. am i right?

@brendandburns
Copy link
Contributor

Code looks great.

Can you add a unit test for this new functionality (sorry, I should have mentioned that before).

Once it is tested (and passing) we can merge.

Signed-off-by: jhbae200 <jhbae200@gmail.com>
@jhbae200
Copy link
Contributor Author

jhbae200 commented Aug 5, 2021

I think need to mock the ProcessBuilder to test the refresh method.
I'm trying to mock that function by adding a getProcessBuilder method to this class. What do you think?

public class GCPAuthenticator implements Authenticator {
//somthing code
  public ProcessBuilder getPb() {
    return new ProcessBuilder();
  }

  @Override
  public Map<String, Object> refresh(Map<String, Object> config) {
    //somthing code
      Process process = this.getPb().command(Arrays.asList(fullCmd.split(" "))).start();
    //somthing code
  }
}

Signed-off-by: jhbae200 <jhbae200@gmail.com>
@brendandburns
Copy link
Contributor

Thanks for adding the test!

I think it is simpler if you just make the ProcessBuilder an optional constructor parameter, e.g.

public GCPAuthenticator() {
   this(new ProcessBuilder());
}

public GCPAuthenticator(ProcessBuilder pb) {
   this.pb = pb;
}
....

Signed-off-by: jhbae200 <jhbae200@gmail.com>
@brendandburns
Copy link
Contributor

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 9, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: brendandburns, jhbae200

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 9, 2021
@k8s-ci-robot k8s-ci-robot merged commit 4a8ab93 into kubernetes-client:master Aug 9, 2021
@piotom
Copy link

piotom commented Nov 9, 2021

Great to have it implemented!

Are there any plans to release it in the near future?

@keith-miller
Copy link

It took me a while to discover that this existed and was released. Any chance this can be added to the documentation for those coming after me?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants