Skip to content

Commit

Permalink
move proxy configuration to Configure System
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Lamy <[email protected]>
  • Loading branch information
olamy committed Nov 16, 2023
1 parent 92aa498 commit 37918b9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 63 deletions.
16 changes: 16 additions & 0 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import hudson.model.AbstractModelObject;
import hudson.model.AdministrativeMonitor;
import hudson.model.Api;
import hudson.model.Descriptor;
import hudson.model.DownloadService;
import hudson.model.Failure;
import hudson.model.ItemGroupMixIn;
Expand Down Expand Up @@ -165,6 +166,7 @@
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;
import org.kohsuke.stapler.interceptor.RequirePOST;
import org.kohsuke.stapler.verb.POST;
import org.springframework.security.core.Authentication;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
Expand Down Expand Up @@ -1795,6 +1797,16 @@ public HttpResponse doSiteConfigure(@QueryParameter String site) throws IOExcept
return new HttpRedirect("advanced");
}

@POST
public HttpResponse doProxyConfigure(StaplerRequest req) throws IOException, ServletException {
Jenkins jenkins = Jenkins.get();
jenkins.checkPermission(Jenkins.ADMINISTER);

ProxyConfiguration pc = req.bindJSON(ProxyConfiguration.class, req.getSubmittedForm());
ProxyConfigurationManager.saveProxyConfiguration(pc);
return new HttpRedirect("advanced");
}

interface PluginCopier {
void copy(File target) throws Exception;

Expand Down Expand Up @@ -2112,6 +2124,10 @@ protected String identifyPluginShortName(File t) {
return FilenameUtils.getBaseName(t.getName()); // fall back to the base name of what's uploaded
}

public Descriptor<ProxyConfiguration> getProxyDescriptor() {
return Jenkins.get().getDescriptor(ProxyConfiguration.class);
}

/**
* Prepares plugins for some expected XML configuration.
* If the configuration (typically a job’s {@code config.xml})
Expand Down
55 changes: 15 additions & 40 deletions core/src/main/java/hudson/ProxyConfigurationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,70 +26,45 @@

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.Descriptor;
import hudson.model.ManagementLink;
import hudson.security.Permission;
import java.io.IOException;
import javax.servlet.ServletException;
import jenkins.model.GlobalConfiguration;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.HttpRedirect;
import org.kohsuke.stapler.HttpResponse;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.verb.POST;

@Extension
public class ProxyConfigurationManager extends ManagementLink {
public class ProxyConfigurationManager extends GlobalConfiguration {

@NonNull
@Override
public String getDisplayName() {
return Messages.ProxyConfigurationManager_DisplayName();
}

@Override
public String getIconFileName() {
return "symbol-proxy";
}

@Override
public String getUrlName() {
return "proxyConfigurationManager";
}

@NonNull
@Override
public Category getCategory() {
return Category.CONFIGURATION;
}

@NonNull
@Override
public Permission getRequiredPermission() {
return Jenkins.SYSTEM_READ;
}

@Override
public String getDescription() {
return Messages.ProxyConfigurationManager_Description();
}

public Descriptor<ProxyConfiguration> getProxyDescriptor() {
return Jenkins.get().getDescriptor(ProxyConfiguration.class);
}

@Override
public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
ProxyConfiguration pc = req.bindJSON(ProxyConfiguration.class, json);
try {
saveProxyConfiguration(pc);
} catch (IOException e) {
throw new FormException(e.getMessage(), e, null);
}
return true;
}

@POST
public HttpResponse doProxyConfigure(StaplerRequest req) throws IOException, ServletException {
public static void saveProxyConfiguration(ProxyConfiguration pc) throws IOException {
Jenkins jenkins = Jenkins.get();
jenkins.checkPermission(Jenkins.ADMINISTER);

ProxyConfiguration pc = req.bindJSON(ProxyConfiguration.class, req.getSubmittedForm());
if (pc.name == null) {
jenkins.proxy = null;
ProxyConfiguration.getXmlFile().delete();
} else {
jenkins.proxy = pc;
jenkins.proxy.save();
}
return new HttpRedirect("..");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,11 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout"
xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<l:layout title="${%Proxy Configuration}" permission="${app.SYSTEM_READ}">

<l:main-panel>
<div class="jenkins-form">
<section class="jenkins-section jenkins-!-margin-bottom-5">
<h2 class="jenkins-section__title">${%HTTP Proxy Configuration}</h2>
<f:form method="post" action="proxyConfigure" name="proxyConfigure">
<j:scope>
<j:set var="instance" value="${app.proxy}"/>
<j:set var="descriptor" value="${it.proxyDescriptor}"/>
<st:include from="${descriptor}" page="${descriptor.configPage}"/>
</j:scope>
<l:isAdmin>
<f:block>
<f:submit/>
</f:block>
</l:isAdmin>
</f:form>
</section>
</div>
</l:main-panel>
</l:layout>
<f:section title="${%HTTP Proxy Configuration}">
<j:scope>
<j:set var="descriptor" value="${instance.getProxyDescriptor()}"/>
<j:set var="instance" value="${app.proxy}"/>
<st:include from="${descriptor}" page="${descriptor.configPage}"/>
</j:scope>
</f:section>
</j:jelly>
1 change: 0 additions & 1 deletion war/src/main/resources/images/symbols/proxy.svg

This file was deleted.

0 comments on commit 37918b9

Please sign in to comment.