[java-identity-provider] branch main updated: IDP-1683 Plugin Improvements - templating
Rod Widdowson
rdw at steadingsoftware.com
Mon Oct 12 14:05:47 UTC 2020
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch main
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=4742d5a98e212f0e80f9ba472cb5546511fd4fcb
The following commit(s) were added to refs/heads/main by this push:
new 4742d5a98 IDP-1683 Plugin Improvements - templating
4742d5a98 is described below
commit 4742d5a98e212f0e80f9ba472cb5546511fd4fcb
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Mon Oct 12 14:56:12 2020 +0100
IDP-1683 Plugin Improvements - templating
https://issues.shibboleth.net/jira/browse/IDP-1683
---
.../net/shibboleth/idp/plugin/PluginSupport.java | 8 ++++++-
.../idp/installer/plugin/impl/PluginState.java | 26 +++++++++++++++++++---
.../idp/installer/plugin/impl/PluginStateTest.java | 20 +++++++++++++++--
.../net/shibboleth/idp/plugin/plugins.props | 11 ++++-----
4 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PluginSupport.java b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PluginSupport.java
index 88fddfe60..32280e376 100644
--- a/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PluginSupport.java
+++ b/idp-admin-api/src/main/java/net/shibboleth/idp/plugin/PluginSupport.java
@@ -47,6 +47,12 @@ public final class PluginSupport {
/** Property Name for support level inside inside {@link IdPPlugin#getUpdateURLs()}. */
@Nonnull public static final String SUPPORT_LEVEL_INTERFIX = ".supportLevel.";
+ /** Used for specifying templated keynames. */
+ @Nonnull public static final String VERSION_PATTERN = "%{version}";
+
+ /** Used for specifying templated results. */
+ @Nonnull public static final String VERSION_PATTERN_REGEX = "\\%\\{version\\}";
+
/** Value for support level pointed to by {@link #SUPPORT_LEVEL_INTERFIX}.*/
public static enum SupportLevel {
/** The current release. */
@@ -62,7 +68,7 @@ public final class PluginSupport {
/** Nothing published. */
Unknown
}
-
+
/** Class logger. */
@Nonnull private static Logger log = LoggerFactory.getLogger(PluginSupport.class);
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginState.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginState.java
index 0abd246f9..11827c786 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginState.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/plugin/impl/PluginState.java
@@ -121,6 +121,26 @@ public class PluginState extends AbstractInitializableComponent {
ComponentSupport.ifInitializedThrowUnmodifiabledComponentException(this);
httpClient = Constraint.isNotNull(what, "HttpClient must be non null");
}
+
+ /** look up the key derived from the pluginId, the interfix and the version, but if that
+ * fails look for a templated definition.
+ * @param props what to look in
+ * @param interfix the interface (between the ID and the version)
+ * @param version the version.
+ * @return the suitable value
+ */
+ @Nullable private String getDefaultedValue(final Properties props, final String interfix, final String version) {
+
+ String result = props.getProperty(plugin.getPluginId() + interfix + version);
+ if (result != null) {
+ return result;
+ }
+ result = props.getProperty(plugin.getPluginId() + interfix + PluginSupport.VERSION_PATTERN);
+ if (result == null) {
+ return result;
+ }
+ return result.replaceAll(PluginSupport.VERSION_PATTERN_REGEX, version);
+ }
/** Given a version find out more.
* @param props the property files for this plugin we are looking at
@@ -128,7 +148,7 @@ public class PluginState extends AbstractInitializableComponent {
* @return true if we processed everything OK.
*/
// Checkstyle: CyclomaticComplexity OFF
- private boolean handleAvailableVersion(final Properties props, final String version) {
+ private boolean handleAvailableVersion(final Properties props, final String version) {
final PluginVersion theVersion = new PluginVersion(version);
if (theVersion.getMajor() == 0 && theVersion.getMinor() == 0 && theVersion.getPatch() == 0) {
log.warn("Plugin {}: improbable version {}", plugin.getPluginId(), version);
@@ -176,9 +196,9 @@ public class PluginState extends AbstractInitializableComponent {
myVersionInfo = info;
}
String downloadURL = StringSupport.trimOrNull(
- props.getProperty(plugin.getPluginId() + PluginSupport.DOWNLOAD_URL_INTERFIX + version));
+ getDefaultedValue(props, PluginSupport.DOWNLOAD_URL_INTERFIX, version));
final String baseName = StringSupport.trimOrNull(
- props.getProperty(plugin.getPluginId() + PluginSupport.BASE_NAME_INTERFIX + version));
+ getDefaultedValue(props, PluginSupport.BASE_NAME_INTERFIX, version));
if (baseName != null && downloadURL != null) {
try {
if (!downloadURL.endsWith("/")) {
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginStateTest.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginStateTest.java
index b58f6e429..a4bdc4e97 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginStateTest.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/plugin/impl/PluginStateTest.java
@@ -82,9 +82,25 @@ public class PluginStateTest {
assertTrue(testSupportState(v2, state, "6.0.0"));
assertTrue(testSupportState(v2, state, "7.0.0"));
assertFalse(testSupportState(v2, state, "8"));
-
}
-
+
+ @Test
+ public void testTemplating() throws ComponentInitializationException, MalformedURLException {
+ final PluginState state = new PluginState(new TestPlugin());
+ state.initialize();
+ final PluginVersion v123 = new PluginVersion(1,2,3);
+ final PluginVersion v124 = new PluginVersion(1,2,4);
+ final PluginVersion v2 = new PluginVersion(2,0,0);
+
+ assertEquals(state.getUpdateURL(v123), new URL("https://example.org/plugins/"));
+ assertEquals(state.getUpdateURL(v124), new URL("https://example.org/plugins4/"));
+ assertEquals(state.getUpdateURL(v2), new URL("https://example.org/plugins2/"));
+
+ assertEquals(state.getUpdateBaseName(v123), "base-1.2.3-1.2.3");
+ assertEquals(state.getUpdateBaseName(v124), "base-1.2.4-1.2.4");
+ assertEquals(state.getUpdateBaseName(v2), "base-1-2-4");
+ }
+
@Test
public void testMulti() throws IOException, Exception {
diff --git a/idp-installer/src/test/resources/net/shibboleth/idp/plugin/plugins.props b/idp-installer/src/test/resources/net/shibboleth/idp/plugin/plugins.props
index 6bf766e86..4771e98e7 100644
--- a/idp-installer/src/test/resources/net/shibboleth/idp/plugin/plugins.props
+++ b/idp-installer/src/test/resources/net/shibboleth/idp/plugin/plugins.props
@@ -1,24 +1,25 @@
net.shibboleth.plugin.test.versions=1.2.3 1.2.4 2.0.0
+
+net.shibboleth.plugin.test.baseName.%{version}=base-%{version}-%{version}
+net.shibboleth.plugin.test.downloadURL.%{version}=https://example.org/plugins
+
#
# 1.2.3
#
-net.shibboleth.plugin.test.downloadURL.1.2.3=https://example.org/plugins
-net.shibboleth.plugin.test.baseName.1.2.3=base-1-2-3
net.shibboleth.plugin.test.idpVersionMax.1.2.3=5.0.0
net.shibboleth.plugin.test.idpVersionMin.1.2.3=4.1.0
net.shibboleth.plugin.test.supportLevel.1.2.3 = Current
#
# 1.2.4
#
-net.shibboleth.plugin.test.downloadURL.1.2.4=https://example.org/plugins
-net.shibboleth.plugin.test.baseName.1.2.4=base-1-2-4
+net.shibboleth.plugin.test.downloadURL.1.2.4=https://example.org/plugins4
net.shibboleth.plugin.test.idpVersionMax.1.2.4=5.0.0
net.shibboleth.plugin.test.idpVersionMin.1.2.4=4.2.0
net.shibboleth.plugin.test.supportLevel.1.2.4 = OutOfDate
#
# 2.0.0.
#
-net.shibboleth.plugin.test.downloadURL.2.0.0=https://example.org/plugins
+net.shibboleth.plugin.test.downloadURL.2.0.0=https://example.org/plugins2
net.shibboleth.plugin.test.baseName.2.0.0=base-1-2-4
net.shibboleth.plugin.test.idpVersionMax.2.0.0=8.0.0
net.shibboleth.plugin.test.idpVersionMin.2.0.0=4.99.1
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list