Skip to content

Commit

Permalink
Addressing Jenkins issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jrichard committed Jun 1, 2018
1 parent 42cf561 commit 0da415d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl;
import com.cloudbees.plugins.credentials.matchers.IdMatcher;

import hudson.model.AbstractProject;
import hudson.security.ACL;
import jenkins.model.Jenkins;

public class HubServerInfoSingleton {
private final static HubServerInfoSingleton HUB_SERVER_INFO_SINGLETON;
Expand Down Expand Up @@ -139,8 +139,7 @@ public String getHubApiToken() {
public BaseStandardCredentials getCredential() {
BaseStandardCredentials credential = null;
if (StringUtils.isNotBlank(hubCredentialsId)) {
final AbstractProject<?, ?> project = null;
final List<BaseStandardCredentials> credentials = CredentialsProvider.lookupCredentials(BaseStandardCredentials.class, project, ACL.SYSTEM, Collections.<DomainRequirement> emptyList());
final List<BaseStandardCredentials> credentials = CredentialsProvider.lookupCredentials(BaseStandardCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList());
final IdMatcher matcher = new IdMatcher(hubCredentialsId);
for (final BaseStandardCredentials c : credentials) {
if (matcher.matches(c)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.WebMethod;
import org.kohsuke.stapler.verb.POST;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
Expand Down Expand Up @@ -195,10 +196,25 @@ public ListBoxModel doFillDetectDownloadUrlItems() {
return boxModel;
}

@POST
public FormValidation doCheckDetectDownloadUrl(@QueryParameter("detectDownloadUrl") final String detectDownloadUrl) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
if (StringUtils.isBlank(detectDownloadUrl)) {
return FormValidation.ok();
}
try {
final DetectVersionRequestService detectVersionRequestService = getDetectVersionRequestService();
detectVersionRequestService.getDetectVersionModels();
final List<DetectVersionModel> detectVersionModels = detectVersionRequestService.getDetectVersionModels();
boolean foundMatch = false;
for (final DetectVersionModel detectVersionModel : detectVersionModels) {
if (detectDownloadUrl.equals(detectVersionModel.getVersionURL())) {
foundMatch = true;
break;
}
}
if (!foundMatch) {
return FormValidation.error(detectDownloadUrl + ", does not appear to be a valid URL for Detect.");
}
} catch (final IntegrationException e) {
return FormValidation.error(couldNotGetVersionsMessage);
} catch (final IOException e) {
Expand All @@ -213,7 +229,9 @@ private DetectVersionRequestService getDetectVersionRequestService() {
return new DetectVersionRequestService(new PrintStreamIntLogger(System.out, LogLevel.DEBUG), isTrustSSLCertificates(), getHubTimeout());
}

@POST
public FormValidation doCheckHubTimeout(@QueryParameter("hubTimeout") final String hubTimeout) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
if (StringUtils.isBlank(hubTimeout)) {
return FormValidation.error(Messages.DetectPostBuildStep_getPleaseSetTimeout());
}
Expand All @@ -232,7 +250,9 @@ public FormValidation doCheckHubTimeout(@QueryParameter("hubTimeout") final Stri
/**
* Performs on-the-fly validation of the form field 'serverUrl'.
*/
@POST
public FormValidation doCheckHubUrl(@QueryParameter("hubUrl") final String hubUrl, @QueryParameter("trustSSLCertificates") final boolean trustSSLCertificates) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
if (StringUtils.isBlank(hubUrl)) {
return FormValidation.ok();
}
Expand Down Expand Up @@ -264,6 +284,7 @@ public FormValidation doCheckHubUrl(@QueryParameter("hubUrl") final String hubUr
}

public ListBoxModel doFillHubCredentialsIdItems() {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
ListBoxModel boxModel = null;
final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
boolean changed = false;
Expand All @@ -274,8 +295,8 @@ public ListBoxModel doFillHubCredentialsIdItems() {
}
final CredentialsMatcher credentialsMatcher = CredentialsMatchers.anyOf(CredentialsMatchers.instanceOf(StandardUsernamePasswordCredentials.class), CredentialsMatchers.instanceOf(StringCredentials.class));
// Dont want to limit the search to a particular project for the drop down menu
final AbstractProject<?, ?> project = null;
boxModel = new StandardListBoxModel().withEmptySelection().withMatching(credentialsMatcher, CredentialsProvider.lookupCredentials(BaseStandardCredentials.class, project, ACL.SYSTEM, Collections.<DomainRequirement>emptyList()));
boxModel = new StandardListBoxModel().withEmptySelection()
.withMatching(credentialsMatcher, CredentialsProvider.lookupCredentials(BaseStandardCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()));
} finally {
if (changed) {
Thread.currentThread().setContextClassLoader(originalClassLoader);
Expand All @@ -284,8 +305,10 @@ public ListBoxModel doFillHubCredentialsIdItems() {
return boxModel;
}

@POST
public FormValidation doTestConnection(@QueryParameter("hubUrl") final String hubUrl, @QueryParameter("hubCredentialsId") final String hubCredentialsId, @QueryParameter("hubTimeout") final String hubTimeout,
@QueryParameter("trustSSLCertificates") final boolean trustSSLCertificates) {
Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER);
final ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
boolean changed = false;
try {
Expand All @@ -299,15 +322,13 @@ public FormValidation doTestConnection(@QueryParameter("hubUrl") final String hu
if (StringUtils.isBlank(hubCredentialsId)) {
return FormValidation.error(Messages.DetectPostBuildStep_getPleaseSetHubCredentials());
}

String credentialUserName = null;
String credentialPassword = null;
String hubApiToken = null;
if (StringUtils.isNotBlank(hubCredentialsId)) {
BaseStandardCredentials credential = null;
if (StringUtils.isNotBlank(hubCredentialsId)) {
final AbstractProject<?, ?> project = null;
final List<BaseStandardCredentials> credentials = CredentialsProvider.lookupCredentials(BaseStandardCredentials.class, project, ACL.SYSTEM, Collections.<DomainRequirement>emptyList());
final List<BaseStandardCredentials> credentials = CredentialsProvider.lookupCredentials(BaseStandardCredentials.class, Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList());
final IdMatcher matcher = new IdMatcher(hubCredentialsId);
for (final BaseStandardCredentials c : credentials) {
if (matcher.matches(c)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
<f:section title="${%GlobalSectionTitle}">
<f:entry title="${%HubURL}" field="hubUrl"
description="${%HubURLDescription}">
<f:textbox field="hubUrl" value="${instance.getHubServerUrl()}"/>
<f:textbox field="hubUrl" value="${instance.getHubServerUrl()}" checkMethod="post" />
</f:entry>
<f:entry title="${%HubCredentials}" field="hubCredentialsId" >
<c:select/>
</f:entry>
<f:entry title="${%HubDetectVersion}" field="detectDownloadUrl" >
<f:select/>
<f:entry title="${%HubDetectVersion}" field="detectDownloadUrl">
<f:select checkMethod="post" />
</f:entry>

<f:advanced>
<f:entry title="${%DetectArtifactUrl}" field="detectArtifactUrl" >
<f:textbox value="${instance.getDetectArtifactUrl()}" />
</f:entry>
<f:entry title="${%HubConnectionTimeout}" field="hubTimeout" description="${%HubConnectionTimeoutDescription}" >
<f:textbox clazz="required number" />
<f:textbox clazz="required number" checkMethod="post" />
</f:entry>
<f:entry title="${%TrustSSLCertificates}" field="trustSSLCertificates" >
<f:checkbox default="false" />
Expand Down

0 comments on commit 0da415d

Please sign in to comment.