Skip to content

support gcp authentication refresh token#1810

Merged
k8s-ci-robot merged 6 commits intokubernetes-client:masterfrom
jhbae200:master
Aug 9, 2021
Merged

support gcp authentication refresh token#1810
k8s-ci-robot merged 6 commits intokubernetes-client:masterfrom
jhbae200:master

Conversation

@jhbae200
Copy link
Copy Markdown
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
Copy Markdown
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.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please sign in with your organization's credentials at https://identity.linuxfoundation.org/projects/cncf to be authorized.
  • If you have done the above and are still having issues with the CLA being reported as unsigned, please log a ticket with the Linux Foundation Helpdesk: https://support.linuxfoundation.org/
  • Should you encounter any issues with the Linux Foundation Helpdesk, send a message to the backup e-mail support address at: [email protected]
Details

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
Copy Markdown
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
Copy Markdown
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 ...

@jhbae200
Copy link
Copy Markdown
Contributor Author

jhbae200 commented Aug 2, 2021

/check-cla

@jhbae200
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@jhbae200
Copy link
Copy Markdown
Contributor Author

jhbae200 commented Aug 3, 2021

Updated the code. am i right?

@brendandburns
Copy link
Copy Markdown
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.

@jhbae200
Copy link
Copy Markdown
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 <[email protected]>
@brendandburns
Copy link
Copy Markdown
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;
}
....

@brendandburns
Copy link
Copy Markdown
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
Copy Markdown
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

Details 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
Copy Markdown

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
Copy Markdown

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