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

Add option to set Basic credentials #292

Merged
merged 10 commits into from
Mar 2, 2021
Merged

Conversation

kwin
Copy link
Contributor

@kwin kwin commented Mar 1, 2021

This closes #245

@timja
Copy link
Member

timja commented Mar 1, 2021

can you resolve the conflicts, should be easy,

edit: thanks

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

looks good any thoughts on below

@@ -80,6 +80,9 @@
<directory>src/main/resources-filtered</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
Copy link
Member

Choose a reason for hiding this comment

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

why?

Copy link
Contributor Author

@kwin kwin Mar 1, 2021

Choose a reason for hiding this comment

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

Messages.properties doesn't need to be filtered. Can move it to src/main/resources-filtered but this has the overhead of unnecessary filtering...

FileUtils.copyURLToFile(location.toURL(), pluginFile);
} catch (URISyntaxException | IOException e) {
CredentialsProvider credentialsProvider = getCredentialsProvider();
if (credentialsProvider != null) {
Copy link
Member

Choose a reason for hiding this comment

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

isn't this always non null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 1be02a1. Now it can really be null in case no credentials have been set.

}
HttpGet httpGet = new HttpGet(urlString);
try {
httpclient.execute(httpGet, new FileDownloadResponseHandler(pluginFile), context);
Copy link
Member

Choose a reason for hiding this comment

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

this appears to revert #285 ?

(logging the actual download url after redirects)

Copy link
Contributor Author

@kwin kwin Mar 1, 2021

Choose a reason for hiding this comment

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

Yes, indeed, but the redirect are handled now within HttpClient, so if you are interested in this just enable the logging from HttpClient....

Update: Since this is easy to do, I am gonna restore the logging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 1be02a1.

// get final URI (after all redirects)
List<URI> locations = context.getRedirectLocations();
if (locations != null) {
logVerbose(String.format("Downloading %s from %s", plugin.getName(), locations.get(locations.size() - 1)));
Copy link
Member

Choose a reason for hiding this comment

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

isn't this done after the request has been made?

Suggested change
logVerbose(String.format("Downloading %s from %s", plugin.getName(), locations.get(locations.size() - 1)));
logVerbose(String.format("Downloaded %s from %s", plugin.getName(), locations.get(locations.size() - 1)));

and shouldn't it be added to the catch clause in that 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.

Good catch, now logged in finally (so that it covers both success and failure): 968d7c0

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

looks good, would appreciate a response on the logging bit but can't see any blockers

// get final URI (after all redirects)
List<URI> locations = context.getRedirectLocations();
if (locations != null) {
logVerbose(String.format("%s %s from %s", success ? "Downloaded" : "Tried downloading", plugin.getName(), locations.get(locations.size() - 1)));
Copy link
Member

Choose a reason for hiding this comment

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

nice, if you're feeling extra amazing it would be great to log the failure case always and verbose for the regular case, but not required to ship this

Thanks!

Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

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

Looks like a default value is missing,

➜  plugin-installation-manager-tool git:(feature/basic-auth) ✗ java -jar plugin-management-cli/target/jenkins-plugin-manager-2.6.2-SNAPSHOT.jar
Exception in thread "main" java.lang.NullPointerException
	at org.kohsuke.args4j.spi.DelimitedOptionHandler.printDefaultValue(DelimitedOptionHandler.java:62)
	at org.kohsuke.args4j.CmdLineParser.createDefaultValuePart(CmdLineParser.java:358)
	at org.kohsuke.args4j.CmdLineParser.printOption(CmdLineParser.java:335)
	at org.kohsuke.args4j.CmdLineParser.printUsage(CmdLineParser.java:303)
	at org.kohsuke.args4j.CmdLineParser.printUsage(CmdLineParser.java:273)
	at org.kohsuke.args4j.CmdLineParser.printUsage(CmdLineParser.java:263)
	at io.jenkins.tools.pluginmanager.cli.Main.main(Main.java:33)

…nmanager/impl/PluginManager.java

Co-authored-by: Tim Jacomb <[email protected]>
@kwin
Copy link
Contributor Author

kwin commented Mar 1, 2021

Looks like a default value is missing,

➜  plugin-installation-manager-tool git:(feature/basic-auth) ✗ java -jar plugin-management-cli/target/jenkins-plugin-manager-2.6.2-SNAPSHOT.jar
Exception in thread "main" java.lang.NullPointerException
	at org.kohsuke.args4j.spi.DelimitedOptionHandler.printDefaultValue(DelimitedOptionHandler.java:62)

Indeed, seem this is kohsuke/args4j#166. Will check for a workaround.

Update: Should be fixed by eac1477

@kwin kwin requested a review from timja March 1, 2021 21:59
@timja
Copy link
Member

timja commented Mar 2, 2021

there was a nullpointer when run without credentials, as the CLI was setting credentials to null when not used.

I added a safety net in the configuration

@timja timja added the enhancement New feature or request label Mar 2, 2021
@timja timja merged commit c45a558 into jenkinsci:master Mar 2, 2021
@timja
Copy link
Member

timja commented Mar 2, 2021

Thanks for the contribution! It's been asked for a couple of times

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

Successfully merging this pull request may close these issues.

Add support for Basic HTTP authentication
2 participants