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

Move proxy configuration form out of pluginManager screens as it is not related #8693

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1803,13 +1803,7 @@
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();
}
ProxyConfigurationManager.saveProxyConfiguration(pc);

Check warning on line 1806 in core/src/main/java/hudson/PluginManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 1806 is not covered by tests
return new HttpRedirect("advanced");
}

Expand Down
72 changes: 72 additions & 0 deletions core/src/main/java/hudson/ProxyConfigurationManager.java
Copy link
Contributor

Choose a reason for hiding this comment

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

How about naming this ProxyGlobalConfiguration?

Copy link
Member Author

Choose a reason for hiding this comment

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

There is a class called ProxyConfiguration which already some contains some logic about this.
So the idea was to have a name similar.
Anywat naming it's like color or codestyle or wine. Everybody may have his own taste preferences.
why not another name but someone may not like it or prefer something different,
This will eventually turn into an endless loop and definitely a waste of time.

Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* The MIT License
*
* Copyright (c) 2023, CloudBees Inc, and other contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package hudson;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.model.Descriptor;
import java.io.IOException;
import jenkins.model.GlobalConfiguration;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.StaplerRequest;

@Extension @Restricted(NoExternalUse.class)
public class ProxyConfigurationManager extends GlobalConfiguration {

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

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);

Check warning on line 56 in core/src/main/java/hudson/ProxyConfigurationManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 55-56 are not covered by tests
}
return true;
}

public static void saveProxyConfiguration(ProxyConfiguration pc) throws IOException {
Copy link
Member Author

@olamy olamy Nov 16, 2023

Choose a reason for hiding this comment

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

I wonder if this method should be move this to the class ProxyConfiguration.
I'm tempted but so no strong opinion really

Jenkins jenkins = Jenkins.get();
if (pc.name == null) {

Check warning on line 63 in core/src/main/java/hudson/ProxyConfigurationManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 63 is only partially covered, one branch is missing
jenkins.proxy = null;
ProxyConfiguration.getXmlFile().delete();
} else {
jenkins.proxy = pc;
jenkins.proxy.save();

Check warning on line 68 in core/src/main/java/hudson/ProxyConfigurationManager.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 67-68 are not covered by tests
}
}

}
2 changes: 2 additions & 0 deletions core/src/main/resources/hudson/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ PluginWrapper.NoSuchPlugin=No such plugin found with the name ''{0}''
PluginWrapper.Error.Disabling=There was an error disabling the ''{0}'' plugin. Error: ''{1}''
TcpSlaveAgentListener.PingAgentProtocol.displayName=Ping protocol

ProxyConfigurationManager.DisplayName=Proxy Configuration
ProxyConfigurationManager.Description=Configure the http proxy used by Jenkins
19 changes: 4 additions & 15 deletions core/src/main/resources/hudson/PluginManager/advanced.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,11 @@ THE SOFTWARE.
<l:main-panel>
<l:app-bar title="${%Advanced settings}"/>

<div class="alert alert-info">
<strong>${%The Proxy configuration form has been moved to} <a href="${rootURL}/manage/configure">Configure System page</a></strong>
olamy marked this conversation as resolved.
Show resolved Hide resolved
</div>

<div class="jenkins-form">
<section class="jenkins-section jenkins-!-margin-bottom-5">
olamy marked this conversation as resolved.
Show resolved Hide resolved
<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>

<l:isAdmin>
<section class="jenkins-section jenkins-!-margin-bottom-5">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!--
The MIT License

Copyright (c) 2023, CloudBees Inc, and other contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
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">
<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>
Loading