Skip to content

Commit

Permalink
Turn source image project into a combobox.
Browse files Browse the repository at this point in the history
The previous select was too restrictive as it didn't allow to provide a value for this field other than the project where the VM is to be scheduled.

Source image could be located in a different project and shared to the project where the VM is scheduled.

Also removed usage of anonymous inner class when a simpler alternative is available.
  • Loading branch information
Vlatombe committed Jan 9, 2025
1 parent e3308d4 commit 61fc5da
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import hudson.model.Label;
import hudson.model.Node;
import hudson.model.labels.LabelAtom;
import hudson.util.ComboBoxModel;
import hudson.util.FormValidation;
import hudson.util.ListBoxModel;
import java.io.IOException;
Expand Down Expand Up @@ -98,20 +99,18 @@ public class InstanceConfiguration implements Describable<InstanceConfiguration>
public static final String DEFAULT_RUN_AS_USER = "jenkins";
public static final String METADATA_LINUX_STARTUP_SCRIPT_KEY = "startup-script";
public static final String METADATA_WINDOWS_STARTUP_SCRIPT_KEY = "windows-startup-script-ps1";
public static final List<String> KNOWN_IMAGE_PROJECTS = Collections.unmodifiableList(new ArrayList<String>() {
{
add("centos-cloud");
add("coreos-cloud");
add("cos-cloud");
add("debian-cloud");
add("rhel-cloud");
add("suse-cloud");
add("suse-sap-cloud");
add("ubuntu-os-cloud");
add("windows-cloud");
add("windows-sql-cloud");
}
});
public static final List<String> KNOWN_IMAGE_PROJECTS = Arrays.asList(
"centos-cloud",
"coreos-cloud",
"cos-cloud",
"debian-cloud",
"rhel-cloud",
"suse-cloud",
"suse-sap-cloud",
"ubuntu-os-cloud",
"windows-cloud",
"windows-sql-cloud"
);

private String description;
private String namePrefix;
Expand Down Expand Up @@ -834,17 +833,12 @@ public ListBoxModel doFillBootDiskTypeItems(
}
}

public ListBoxModel doFillBootDiskSourceImageProjectItems(
@AncestorInPath Jenkins context,
@QueryParameter("projectId") @RelativePath("..") final String projectId) {
public ComboBoxModel doFillBootDiskSourceImageProjectItems(@QueryParameter("projectId") @RelativePath("..") final String projectId) {

Check warning

Code scanning / Jenkins Security Scan

Stapler: Missing POST/RequirePOST annotation Warning

Potential CSRF vulnerability: If DescriptorImpl#doFillBootDiskSourceImageProjectItems connects to user-specified URLs, modifies state, or is expensive to run, it should be annotated with @POST or @RequirePOST
checkPermissions(Jenkins.get(), Jenkins.ADMINISTER);
ListBoxModel items = new ListBoxModel();
items.add("");
items.add(projectId);
for (String v : KNOWN_IMAGE_PROJECTS) {
items.add(v);
}
return items;
ComboBoxModel items = new ComboBoxModel();
items.add(projectId);
items.addAll(KNOWN_IMAGE_PROJECTS);
return items;
}

public FormValidation doCheckBootDiskSourceImageProject(@QueryParameter String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@

<f:section title="Boot Disk">
<f:entry field="bootDiskSourceImageProject" title="${%Image project}">
<f:select/>
<f:combobox/>
</f:entry>
<f:entry field="bootDiskSourceImageName" title="${%Image name}">
<f:select/>
Expand Down

0 comments on commit 61fc5da

Please sign in to comment.