Skip to content

Add warning while setting a GitLab Multipipeline project or organization folders without Credentials #406

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import edu.umd.cs.findbugs.annotations.CheckForNull;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;
Expand Down Expand Up @@ -526,6 +527,40 @@ public ListBoxModel doFillServerNameItems(
return GitLabServers.get().getServerItems();
}

public FormValidation doCheckCredentialsId(
@AncestorInPath SCMSourceOwner context, @QueryParameter String serverName, @QueryParameter String value)
throws IOException, InterruptedException {
if (context == null) {
if (Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return FormValidation.ok();
}
} else {
if (!context.hasPermission(Item.EXTENDED_READ)
&& !context.hasPermission(CredentialsProvider.USE_ITEM)) {
return FormValidation.ok();
}
}
GitLabServer server = GitLabServers.get().findServer(serverName);
if (server == null) {
return FormValidation.ok();
}
if (StringUtils.isBlank(value)) {
return FormValidation.warning("Credentials are recommended");
}
if (CredentialsProvider.listCredentialsInItem(
StandardCredentials.class,
context,
context instanceof Queue.Task
? ((Queue.Task) context).getDefaultAuthentication2()
: ACL.SYSTEM2,
URIRequirementBuilder.fromUri(serverName).build(),
GitLabServer.CREDENTIALS_MATCHER)
.isEmpty()) {
return FormValidation.error(Messages.GitLabSCMNavigator_selectedCredentialsMissing());
}
return FormValidation.ok();
}

public ListBoxModel doFillCredentialsIdItems(
@AncestorInPath SCMSourceOwner context,
@QueryParameter String serverName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

import com.cloudbees.plugins.credentials.CredentialsMatchers;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import com.cloudbees.plugins.credentials.common.StandardListBoxModel;
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials;
import com.cloudbees.plugins.credentials.domains.URIRequirementBuilder;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
Expand All @@ -28,6 +30,7 @@
import hudson.model.TaskListener;
import hudson.scm.SCM;
import hudson.security.ACL;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import io.jenkins.plugins.gitlabbranchsource.helpers.GitLabAvatar;
import io.jenkins.plugins.gitlabbranchsource.helpers.GitLabLink;
Expand Down Expand Up @@ -836,6 +839,40 @@ public ListBoxModel doFillServerNameItems(
return GitLabServers.get().getServerItems();
}

public FormValidation doCheckCredentialsId(
@AncestorInPath SCMSourceOwner context, @QueryParameter String serverName, @QueryParameter String value)
throws IOException, InterruptedException {
if (context == null) {
if (Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
return FormValidation.ok();
}
} else {
if (!context.hasPermission(Item.EXTENDED_READ)
&& !context.hasPermission(CredentialsProvider.USE_ITEM)) {
return FormValidation.ok();
}
}
GitLabServer server = GitLabServers.get().findServer(serverName);
if (server == null) {
return FormValidation.ok();
}
if (StringUtils.isBlank(value)) {
return FormValidation.warning("Credentials are recommended");
}
if (CredentialsProvider.listCredentialsInItem(
StandardCredentials.class,
context,
context instanceof Queue.Task
? ((Queue.Task) context).getDefaultAuthentication2()
: ACL.SYSTEM2,
URIRequirementBuilder.fromUri(serverName).build(),
GitLabServer.CREDENTIALS_MATCHER)
.isEmpty()) {
return FormValidation.error(Messages.GitLabSCMNavigator_selectedCredentialsMissing());
}
return FormValidation.ok();
}

public ListBoxModel doFillCredentialsIdItems(
@AncestorInPath SCMSourceOwner context,
@QueryParameter String serverName,
Expand Down