Skip to content

Commit

Permalink
Allow UpdateSite to create the URLConnection
Browse files Browse the repository at this point in the history
Different UpdateSites may need to connect to URLs differently, this adds a method to UpdateSite which creates the URLConnection that will be used for connecting. This allows an implementation of a password protected UpdateSite which can add the authorization information to the connection prior to returning it.
  • Loading branch information
slide committed Jan 17, 2025
1 parent 4c552b6 commit 78b85dd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions core/src/main/java/hudson/model/UpdateCenter.java
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,9 @@ static URL toUpdateCenterCheckUrl(String updateCenterUrl) throws MalformedURLExc
* @throws IOException if the validation fails
*/
public void preValidate(DownloadJob job, URL src) throws IOException {
if(job.site != null) {

Check warning on line 1276 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1276 is only partially covered, one branch is missing
job.site.preValidate(src);
}
}

/**
Expand Down Expand Up @@ -1410,6 +1413,10 @@ private static String getSourceUrl(@NonNull URL src, @CheckForNull URLConnection
* how the connection gets established.
*/
protected URLConnection connect(DownloadJob job, URL src) throws IOException {
if(job.site != null) {

Check warning on line 1416 in core/src/main/java/hudson/model/UpdateCenter.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 1416 is only partially covered, one branch is missing
return job.site.connect(src);
}
// fall back to just using the normal ProxyConfiguration if the site is null
return ProxyConfiguration.open(src);
}

Expand Down
23 changes: 23 additions & 0 deletions core/src/main/java/hudson/model/UpdateSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import hudson.ExtensionList;
import hudson.PluginManager;
import hudson.PluginWrapper;
import hudson.ProxyConfiguration;
import hudson.Util;
import hudson.lifecycle.Lifecycle;
import hudson.model.UpdateCenter.UpdateCenterJob;
Expand All @@ -48,6 +49,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
Expand Down Expand Up @@ -202,6 +204,27 @@ public long getDataTimestamp() {
}
}

/**
* Opens a connection to the given URL
* @param src the url to connect to
* @return A {@code URLConnection} for the given src URL
* @since TODO
*/
public URLConnection connect(URL src) throws IOException {
return ProxyConfiguration.open(src);
}

/**
* Validate the URL of the resource before downloading it.
*
* @param src The location of the resource on the network
* @throws IOException if the validation fails
* @since TODO
*/
public void preValidate(URL src) throws IOException {
// no validation needed in the default setup
}

/**
* Forces an update of the data file from the configured URL, irrespective of the last time the data was retrieved.
* @return A {@code FormValidation} indicating the if the update metadata was successfully downloaded from the configured update site
Expand Down

0 comments on commit 78b85dd

Please sign in to comment.