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

[JENKINS-63022] Make Fingerprint Storage Engine configurable from the config page #4834

Merged
merged 34 commits into from
Jul 17, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3580e0e
Move fingerprint configuration to use descriptors
stellargo Jul 8, 2020
ba3788c
Add new line
stellargo Jul 8, 2020
1474ad9
Minor fixes
stellargo Jul 8, 2020
7172979
Move descriptor out of fingerprintstorage class
stellargo Jul 8, 2020
cf07266
Remove redundant import
stellargo Jul 8, 2020
1c99b0e
Fix descriptors implementation
stellargo Jul 8, 2020
2a50bb9
Remove redundant imports
stellargo Jul 8, 2020
7de94e7
Fix json object
stellargo Jul 8, 2020
29cb97b
Merge remote-tracking branch 'upstream/master' into descr
stellargo Jul 8, 2020
1645373
Move to describableList
stellargo Jul 9, 2020
bf7828c
Fix correct fingerprint storage loading
stellargo Jul 9, 2020
c4bcd65
Remove redundant constructor
stellargo Jul 9, 2020
74d9e02
Improve documentation
stellargo Jul 9, 2020
7b855c9
add log for change in fingerprint storage engine
stellargo Jul 9, 2020
b3839a1
Merge remote-tracking branch 'upstream/master' into descr
stellargo Jul 9, 2020
adc4ab4
Add GlobalFingerprintConfiguration#get()
stellargo Jul 9, 2020
f6883f6
Remove name tag from jelly
stellargo Jul 10, 2020
b1158b4
Merge remote-tracking branch 'upstream/master' into descr
stellargo Jul 10, 2020
622ed30
Add symbols
stellargo Jul 10, 2020
dce32c9
Fingerprints not shown at all if no external fingerprint storage avai…
stellargo Jul 10, 2020
e90a590
Add symbol
stellargo Jul 10, 2020
da209e2
remove stray typo
stellargo Jul 10, 2020
d232695
FingerprintStorage symbol rename
stellargo Jul 10, 2020
0ed3910
Var name changed
stellargo Jul 11, 2020
748b747
Logger -> LOGGER
stellargo Jul 13, 2020
b0db94e
Merge remote-tracking branch 'upstream/master' into descr
stellargo Jul 13, 2020
bc10ff8
Remove symbol; fingerprintStorage->storage
stellargo Jul 13, 2020
d9f1acf
Remove stray file
stellargo Jul 13, 2020
6a0baa2
fingerprintStorage->storage
stellargo Jul 14, 2020
40dba11
Merge remote-tracking branch 'upstream/master' into descr
stellargo Jul 14, 2020
106dd78
Change naming
stellargo Jul 15, 2020
3dee952
Add localization
stellargo Jul 16, 2020
b25938e
Merge remote-tracking branch 'upstream/master' into descr
stellargo Jul 16, 2020
e91381e
Add empty line
stellargo Jul 16, 2020
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 @@ -36,6 +36,7 @@
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
import org.xmlpull.v1.XmlPullParserException;

import java.io.EOFException;
Expand All @@ -58,6 +59,9 @@ public class FileFingerprintStorage extends FingerprintStorage {
private static final Logger logger = Logger.getLogger(FileFingerprintStorage.class.getName());
private static final DateConverter DATE_CONVERTER = new DateConverter();

@DataBoundConstructor
public FileFingerprintStorage () {}

/**
* Load the Fingerprint with the given unique id.
*/
Expand Down Expand Up @@ -255,4 +259,14 @@ private static String serialize(Fingerprint.RangeSet src) {
return buf.toString();
}

@Extension
public static class DescriptorImpl extends FingerprintStorageDescriptor {

@Override
public String getDisplayName() {
return "Disabled";
stellargo marked this conversation as resolved.
Show resolved Hide resolved
}

}

}
12 changes: 8 additions & 4 deletions core/src/main/java/jenkins/fingerprints/FingerprintStorage.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.io.IOException;

import hudson.model.AbstractDescribableImpl;
import hudson.model.Fingerprint;
import org.kohsuke.accmod.restrictions.Beta;
import org.kohsuke.accmod.Restricted;
Expand All @@ -39,14 +40,13 @@
* @author Sumit Sarin
*/
@Restricted(Beta.class)
public abstract class FingerprintStorage implements ExtensionPoint {
public abstract class FingerprintStorage extends AbstractDescribableImpl<FingerprintStorage> implements ExtensionPoint {

/**
* Returns the first implementation of FingerprintStorage for the instance.
* External storage plugins which implement FingerprintStorage are given a higher priority.
* Returns the configured {@link FingerprintStorage} engine chosen by the user for the system.
*/
public static FingerprintStorage get() {
return ExtensionList.lookup(FingerprintStorage.class).get(0);
return ExtensionList.lookupSingleton(GlobalFingerprintConfiguration.class).getFingerprintStorage();
}

/**
Expand Down Expand Up @@ -80,4 +80,8 @@ public static FingerprintStorage get() {
*/
public abstract boolean isReady();

@Override public FingerprintStorageDescriptor getDescriptor() {
return (FingerprintStorageDescriptor) super.getDescriptor();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* The MIT License
*
* Copyright (c) 2020, Jenkins project 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 jenkins.fingerprints;

import hudson.DescriptorExtensionList;
import hudson.model.Descriptor;
import jenkins.model.Jenkins;

/**
* Descriptor for {@link FingerprintStorage}. Used for configuring external fingerprint storages.
*/
public class FingerprintStorageDescriptor extends Descriptor<FingerprintStorage> {

public static DescriptorExtensionList<FingerprintStorage, FingerprintStorageDescriptor> all() {
return Jenkins.get().getDescriptorList(FingerprintStorage.class);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* The MIT License
*
* Copyright (c) 2020, Jenkins project 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 jenkins.fingerprints;

import hudson.Extension;
import hudson.ExtensionList;
import jenkins.model.GlobalConfiguration;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;

import java.util.logging.Logger;

@Extension
public class GlobalFingerprintConfiguration extends GlobalConfiguration {

private FingerprintStorage fingerprintStorage = ExtensionList.lookupSingleton(FileFingerprintStorage.class);
stellargo marked this conversation as resolved.
Show resolved Hide resolved
private static final Logger logger = Logger.getLogger(GlobalFingerprintConfiguration.class.getName());
stellargo marked this conversation as resolved.
Show resolved Hide resolved

public GlobalFingerprintConfiguration() {
load();
}

public static GlobalFingerprintConfiguration get() {
return ExtensionList.lookupSingleton(GlobalFingerprintConfiguration.class);
}

public FingerprintStorage getFingerprintStorage() {
return fingerprintStorage;
}

@DataBoundSetter
public void setFingerprintStorage(FingerprintStorage newFingerprintStorage) {
this.fingerprintStorage = newFingerprintStorage;
logger.fine("Fingerprint Storage for the system changed to " +
newFingerprintStorage.getDescriptor().getDisplayName());
}

@Override
public boolean configure(StaplerRequest req, JSONObject json) {
json = json.getJSONObject("fingerprints");
stellargo marked this conversation as resolved.
Show resolved Hide resolved
req.bindJSON(this, json);
save();
return true;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!--
The MIT License
Copyright (c) 2020, Jenkins project 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:f="/lib/form">
<f:section title="${%Fingerprints}" name="fingerprints">
stellargo marked this conversation as resolved.
Show resolved Hide resolved
<f:entry>
<f:dropdownDescriptorSelector field="fingerprintStorage" title="Configure External Fingerprint Storage"/>
stellargo marked this conversation as resolved.
Show resolved Hide resolved
</f:entry>
</f:section>
</j:jelly>