-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Conversation
private static Authenticator httpsProxyAuth; | ||
private static Authenticator httpProxyAuth; | ||
static { | ||
if (nonNull(System.getProperty("http.proxyUser")) && nonNull(System.getProperty("http.proxyPassword"))) { |
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.
- I don't see any reason to use
nonNull(...)
against!= null
. - I don't think that camel cased properties are good choice, i would preferable change them to
http.proxy_user
andhttp.proxy_password
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.
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.
(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.
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.
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?
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.
Empty property shouldn't affect the code. But usage of Strings#isNullOrEmpty is definitely great suggestion. Thank you!
reviewed, check the comment |
Thank you! Please, see my answers. |
Well, then there is nothing to add. LGTM Good Job 👍 |
@@ -1590,13 +1616,22 @@ public void configure(Transport transport) { | |||
sshTransport.setSshSessionFactory(sshSessionFactory); | |||
} | |||
}); | |||
|
|||
if (nonNull(httpProxyAuth)) { | |||
Authenticator.setDefault(httpProxyAuth); |
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.
- Please, can you explain why we should use httpProxyAuth for ssh connections and httpsProxyAuth for http/https ?
- 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 invokedAuthenticator.setDefault(httpsProxyAuth);
for ssh link. Am I wrong?
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.
(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.
29d9086
to
f19dc32
Compare
@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(); |
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.
Seems that this instance is unused
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.
You are right.
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. " + |
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.
Are you sure that this test check your use case?
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, I am.
OK for me |
@Inject | ||
JGitConnection(Repository repository, CredentialsLoader credentialsLoader, SshKeyProvider sshKeyProvider, | ||
GitUserResolver userResolver) { | ||
@Inject JGitConnection(Repository repository, CredentialsLoader credentialsLoader, SshKeyProvider sshKeyProvider, |
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.
revert formatting
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.
will fix
private PasswordAuthentication passwordAuthentication = createPasswordAuthentication(); | ||
|
||
private PasswordAuthentication createPasswordAuthentication() { | ||
if (! (Strings.isNullOrEmpty(getProxyUserSystemProperty()) |
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.
Please use static import of isNullOrEmpty
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.
Thank you for advice.
Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
@evoevodin: please, review new fixup. |
LGTM |
Thank @evoevodin, @sleshchenko, @vinokurig for your helpful notices! |
Build # 1207 - FAILED Please check console output at http://ci.codenvy-dev.com/jenkins/job/che-pullrequests-build/1207/ to view the results. |
@vinokurig, @evoevodin: please, review this request.
Signed-off-by: Dmytro Nochevnov dnochevnov@codenvy.com