Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-50726] GUI to configure the plugin (#37)
[JENKINS-50726] GUI to configure the plugin
- Loading branch information
1 parent
5d3bac0
commit ab3412d
Showing
20 changed files
with
324 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
src/main/java/io/jenkins/plugins/artifact_manager_s3/S3BlobStoreConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2018 CloudBees, Inc. | ||
* | ||
* 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 io.jenkins.plugins.artifact_manager_s3; | ||
|
||
import java.util.logging.Logger; | ||
import java.util.regex.Pattern; | ||
import javax.annotation.Nonnull; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.jclouds.aws.domain.Region; | ||
import org.kohsuke.stapler.DataBoundConstructor; | ||
import org.kohsuke.stapler.DataBoundSetter; | ||
import org.kohsuke.stapler.QueryParameter; | ||
import hudson.Extension; | ||
import hudson.ExtensionList; | ||
import hudson.util.FormValidation; | ||
import hudson.util.ListBoxModel; | ||
import jenkins.model.GlobalConfiguration; | ||
|
||
/** | ||
* Store the S3BlobStore configuration to save it on a separate file. This make that | ||
* the change of container does not affected to the Artifact functionality, you could change the container | ||
* and it would still work if both container contains the same data. | ||
*/ | ||
@Extension | ||
public class S3BlobStoreConfig extends GlobalConfiguration { | ||
|
||
private static final String BUCKET_REGEXP = "^([a-z]|(\\d(?!\\d{0,2}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})))([a-z\\d]|(\\.(?!(\\.|-)))|(-(?!\\.))){1,61}[a-z\\d\\.]$"; | ||
private static final Pattern bucketPattern = Pattern.compile(BUCKET_REGEXP); | ||
|
||
private static final Logger LOGGER = Logger.getLogger(S3BlobStoreConfig.class.getName()); | ||
|
||
@SuppressWarnings("FieldMayBeFinal") | ||
private static boolean DELETE_ARTIFACTS = Boolean.getBoolean(S3BlobStoreConfig.class.getName() + ".deleteArtifacts"); | ||
@SuppressWarnings("FieldMayBeFinal") | ||
private static boolean DELETE_STASHES = Boolean.getBoolean(S3BlobStoreConfig.class.getName() + ".deleteStashes"); | ||
|
||
/** | ||
* Name of the S3 Bucket. | ||
*/ | ||
private String container; | ||
/** | ||
* Prefix to use for files, use to be a folder. | ||
*/ | ||
private String prefix; | ||
/** | ||
* force the region to use for the URLs generated. | ||
*/ | ||
private String region; | ||
|
||
@DataBoundConstructor | ||
public S3BlobStoreConfig() { | ||
load(); | ||
} | ||
|
||
public String getContainer() { | ||
return container; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setContainer(String container) { | ||
this.container = container; | ||
save(); | ||
} | ||
|
||
public String getPrefix() { | ||
return prefix; | ||
} | ||
|
||
@DataBoundSetter | ||
public void setPrefix(String prefix) { | ||
this.prefix = prefix; | ||
save(); | ||
} | ||
|
||
public String getRegion() { | ||
return region; | ||
} | ||
@DataBoundSetter | ||
public void setRegion(String region) { | ||
this.region = region; | ||
save(); | ||
} | ||
|
||
public boolean isDeleteArtifacts() { | ||
return DELETE_ARTIFACTS; | ||
} | ||
|
||
public boolean isDeleteStashes() { | ||
return DELETE_STASHES; | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getDisplayName() { | ||
return "Amazon S3 Bucket Access settings"; | ||
} | ||
|
||
@Nonnull | ||
public static S3BlobStoreConfig get() { | ||
return ExtensionList.lookupSingleton(S3BlobStoreConfig.class); | ||
} | ||
|
||
public ListBoxModel doFillRegionItems() { | ||
ListBoxModel regions = new ListBoxModel(); | ||
regions.add("Auto", ""); | ||
for (String s : Region.DEFAULT_S3) { | ||
regions.add(s); | ||
} | ||
return regions; | ||
} | ||
|
||
public FormValidation doCheckContainer(@QueryParameter String container){ | ||
FormValidation ret = FormValidation.ok(); | ||
if (StringUtils.isBlank(container)){ | ||
ret = FormValidation.warning("The container name cannot be empty"); | ||
} else if (!bucketPattern.matcher(container).matches()){ | ||
ret = FormValidation.error("The S3 Bucket name does not match with S3 bucket rules"); | ||
} | ||
return ret; | ||
} | ||
|
||
public FormValidation doCheckPrefix(@QueryParameter String prefix){ | ||
FormValidation ret; | ||
if (StringUtils.isBlank(prefix)) { | ||
ret = FormValidation.ok("Artifacts will be stored in the root folder of the S3 Bucket."); | ||
} else if (prefix.endsWith("/")) { | ||
ret = FormValidation.ok(); | ||
} else { | ||
ret = FormValidation.error("A prefix must end with a slash."); | ||
} | ||
return ret; | ||
} | ||
|
||
public FormValidation doCheckRegion(@QueryParameter String region){ | ||
FormValidation ret = FormValidation.ok(); | ||
if (StringUtils.isNotBlank(region) && !Region.DEFAULT_REGIONS.contains(region)){ | ||
ret = FormValidation.error("Region is not valid"); | ||
} | ||
return ret; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/resources/io/jenkins/plugins/artifact_manager_s3/S3BlobStore/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<j:if test="${!instance.isConfigured()}"> | ||
<div class="alert alert-warning"> | ||
<strong>${%configure_first}</strong> | ||
</div> | ||
</j:if> | ||
</j:jelly> |
1 change: 1 addition & 0 deletions
1
src/main/resources/io/jenkins/plugins/artifact_manager_s3/S3BlobStore/config.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
configure_first=You have to configure your Amazon S3 setting in the section "Amazon S3 Bucket Access settings" |
21 changes: 21 additions & 0 deletions
21
src/main/resources/io/jenkins/plugins/artifact_manager_s3/S3BlobStoreConfig/config.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form"> | ||
<f:section title="${%Amazon S3 Bucket Access settings}"> | ||
<f:entry title="${%S3 Bucket Name}" field="container"> | ||
<f:textbox/> | ||
</f:entry> | ||
<f:entry title="${%S3 Bucket Region}" field="region"> | ||
<f:select/> | ||
</f:entry> | ||
<f:entry title="${%Base Prefix}" field="prefix"> | ||
<f:textbox/> | ||
</f:entry> | ||
<f:entry title="${%Delete Artifacts}" field="deleteArtifacts"> | ||
<f:checkbox readonly="true"/> | ||
</f:entry> | ||
<f:entry title="${%Delete Stashes}" field="deleteStashes"> | ||
<f:checkbox readonly="true"/> | ||
</f:entry> | ||
</f:section> | ||
</j:jelly> |
1 change: 1 addition & 0 deletions
1
...in/resources/io/jenkins/plugins/artifact_manager_s3/S3BlobStoreConfig/help-container.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div>Name of the S3 Bucket, the S3 Bucket should exists and the AWS account/profile/role used to access should have access to it</div> |
Oops, something went wrong.