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

CODENVY-739: pass proxy credentials to jgit #1707

Merged
merged 3 commits into from
Jul 13, 2016
Merged

CODENVY-739: pass proxy credentials to jgit #1707

merged 3 commits into from
Jul 13, 2016

Conversation

dmytro-ndp
Copy link
Contributor

@vinokurig, @evoevodin: please, review this request.

Signed-off-by: Dmytro Nochevnov dnochevnov@codenvy.com

private static Authenticator httpsProxyAuth;
private static Authenticator httpProxyAuth;
static {
if (nonNull(System.getProperty("http.proxyUser")) && nonNull(System.getProperty("http.proxyPassword"))) {
Copy link
Contributor

@voievodin voievodin Jul 11, 2016

Choose a reason for hiding this comment

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

  1. I don't see any reason to use nonNull(...) against != null.
  2. I don't think that camel cased properties are good choice, i would preferable change them to http.proxy_user and http.proxy_password
  3. Authenticator looks not good as anonymous class to me, i think you should extract it to the private static NAMED inner class, and it seems that findbugs will suggest you to do the same.

Copy link
Contributor Author

@dmytro-ndp dmytro-ndp Jul 11, 2016

Choose a reason for hiding this comment

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

(1). I don't see any reason to use nonNull(...) against != null.

Agree.

(2). I don't think that camel cased properties are good choice, i would preferable change them to http.proxy_user and http.proxy_password

I don't think so. Camel case is good enough here, moreover - there is a convention of Java proxy settings naming which we can't change: http://rolandtapken.de/blog/2012-04/java-process-httpproxyuser-and-httpproxypassword

(3). Authenticator looks not good as anonymous class to me, i think you should extract it to the private static NAMED inner class, and it seems that findbugs will suggest you to do the same.

Agree.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you use java.util.Objects#nonNull instead of com.google.common.base.Strings#isNullOrEmpty?
Empty property value may means that this property is not configured, isn't it?

Copy link
Contributor Author

@dmytro-ndp dmytro-ndp Jul 11, 2016

Choose a reason for hiding this comment

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

Empty property shouldn't affect the code. But usage of Strings#isNullOrEmpty is definitely great suggestion. Thank you!

@voievodin
Copy link
Contributor

reviewed, check the comment

@dmytro-ndp
Copy link
Contributor Author

dmytro-ndp commented Jul 11, 2016

Thank you! Please, see my answers.

@voievodin
Copy link
Contributor

Well, then there is nothing to add. LGTM Good Job 👍

@codenvy-ci
Copy link

@@ -1590,13 +1616,22 @@ public void configure(Transport transport) {
sshTransport.setSshSessionFactory(sshSessionFactory);
}
});

if (nonNull(httpProxyAuth)) {
Authenticator.setDefault(httpProxyAuth);
Copy link
Member

@sleshchenko sleshchenko Jul 12, 2016

Choose a reason for hiding this comment

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

  1. Please, can you explain why we should use httpProxyAuth for ssh connections and httpsProxyAuth for http/https ?
  2. I guess there can be some problem with concurrency. I mean you can send two requests with ssh and http links. Then there can be situation when before invoking of command.call() will be invoked Authenticator.setDefault(httpsProxyAuth); for ssh link. Am I wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

(1) Please, can you explain why we should use httpProxyAuth for ssh connections and httpsProxyAuth for http/https ?

You found an error, and we even don't need setup proxy for ssh.

(2) I guess there can be some problem with concurrency. I mean you can send two requests with ssh and http links. Then there can be situation when before invoking of command.call() will be invoked Authenticator.setDefault(httpsProxyAuth); for ssh link. Am I wrong?

You are right, but I would prefer don't work around synchronization of invoking authenticator so as it will lead to redundant delays.

@dmytro-ndp dmytro-ndp force-pushed the CODENVY-739 branch 2 times, most recently from 29d9086 to f19dc32 Compare July 13, 2016 10:58
@codenvy-ci
Copy link

@dmytro-ndp
Copy link
Contributor Author

@evoevodin, @sleshchenko: please, review my fixup on your notices.

@Inject
JGitConnection(Repository repository, CredentialsLoader credentialsLoader, SshKeyProvider sshKeyProvider,
GitUserResolver userResolver) {
this.repository = repository;
this.credentialsLoader = credentialsLoader;
this.sshKeyProvider = sshKeyProvider;
this.userResolver = userResolver;
this.proxyAuthenticator = new ProxyAuthenticator();
Copy link
Member

Choose a reason for hiding this comment

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

Seems that this instance is unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right.

@codenvy-ci
Copy link

Dmytro Nochevnov added 2 commits July 13, 2016 17:16
Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
@@ -137,4 +137,29 @@ public void testWhenThereAreNoAnyRemotes(GitConnectionFactory connectionFactory)
PullRequest request = newDto(PullRequest.class);
connection.pull(request);
}

@Test(dataProvider = "GitConnectionFactory", dataProviderClass = GitConnectionFactoryProvider.class,
expectedExceptions = GitException.class, expectedExceptionsMessageRegExp = "No remote repository specified. " +
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure that this test check your use case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I am.

@sleshchenko
Copy link
Member

OK for me

@Inject
JGitConnection(Repository repository, CredentialsLoader credentialsLoader, SshKeyProvider sshKeyProvider,
GitUserResolver userResolver) {
@Inject JGitConnection(Repository repository, CredentialsLoader credentialsLoader, SshKeyProvider sshKeyProvider,
Copy link
Member

Choose a reason for hiding this comment

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

revert formatting

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will fix

private PasswordAuthentication passwordAuthentication = createPasswordAuthentication();

private PasswordAuthentication createPasswordAuthentication() {
if (! (Strings.isNullOrEmpty(getProxyUserSystemProperty())
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use static import of isNullOrEmpty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for advice.

Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
@dmytro-ndp
Copy link
Contributor Author

@evoevodin: please, review new fixup.

@voievodin
Copy link
Contributor

LGTM

@dmytro-ndp
Copy link
Contributor Author

Thank @evoevodin, @sleshchenko, @vinokurig for your helpful notices!

@dmytro-ndp dmytro-ndp merged commit 8b2cd2e into master Jul 13, 2016
@dmytro-ndp dmytro-ndp deleted the CODENVY-739 branch July 13, 2016 16:19
@codenvy-ci
Copy link

Build # 1207 - FAILED

Please check console output at http://ci.codenvy-dev.com/jenkins/job/che-pullrequests-build/1207/ to view the results.

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

Successfully merging this pull request may close these issues.

6 participants