[java-shib-profile] branch main updated: JSPROF-9 Consider broadening the module#enable() API

Rod Widdowson rdw at steadingsoftware.com
Fri Nov 22 14:20:52 UTC 2024


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch main
in repository java-shib-profile.

View the commit online:
http://git.shibboleth.net/view/?p=java-shib-profile.git;a=commit;h=f0d5625ca75a113d6f8807767bc5c3c4c5af7c9a

The following commit(s) were added to refs/heads/main by this push:
     new f0d5625  JSPROF-9 Consider broadening the module#enable() API
f0d5625 is described below

commit f0d5625ca75a113d6f8807767bc5c3c4c5af7c9a
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Nov 22 14:16:20 2024 +0000

    JSPROF-9 Consider broadening the module#enable() API
    
    https://shibboleth.atlassian.net/browse/JSPROF-9
    
    1) Widen the ModuleContext to contain the "OperationType"
    
    2) Add a new (defaulted) enable method to the Module interface to indicate
       (if known) whether this is an installer driven enable or re-enable.
---
 .../shibboleth/profile/module/AbstractModule.java  |  8 ++-
 .../java/net/shibboleth/profile/module/Module.java | 20 +++++++-
 .../shibboleth/profile/module/ModuleContext.java   | 59 +++++++++++++++++++++-
 3 files changed, 84 insertions(+), 3 deletions(-)

diff --git a/shib-profile-api/src/main/java/net/shibboleth/profile/module/AbstractModule.java b/shib-profile-api/src/main/java/net/shibboleth/profile/module/AbstractModule.java
index aa55bb8..9791ca4 100644
--- a/shib-profile-api/src/main/java/net/shibboleth/profile/module/AbstractModule.java
+++ b/shib-profile-api/src/main/java/net/shibboleth/profile/module/AbstractModule.java
@@ -46,7 +46,7 @@ import org.slf4j.Logger;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.util.ResourceUtils;
 
-
+import net.shibboleth.profile.module.ModuleContext.OperationType;
 import net.shibboleth.shared.annotation.constraint.NotEmpty;
 import net.shibboleth.shared.annotation.constraint.NotLive;
 import net.shibboleth.shared.annotation.constraint.Unmodifiable;
@@ -167,6 +167,9 @@ public abstract class AbstractModule implements Module {
         if (isHttpClientRequired() && moduleContext.getHttpClient() == null) {
             throw new ModuleException("HTTP client required but not available");
         }
+
+        // test time check
+        assert moduleContext.getOperationType() != OperationType.Unknown;
         
         log.debug("Module {} enabling", getId());
         
@@ -209,6 +212,9 @@ public abstract class AbstractModule implements Module {
 
         log.debug("Module {} disabling", getId());
 
+        // test time check
+        assert moduleContext.getOperationType() != OperationType.Unknown;
+
         final Map<ModuleResource,ResourceResult> results;
         
         if (!moduleResources.isEmpty()) {
diff --git a/shib-profile-api/src/main/java/net/shibboleth/profile/module/Module.java b/shib-profile-api/src/main/java/net/shibboleth/profile/module/Module.java
index d84649b..4283bbc 100644
--- a/shib-profile-api/src/main/java/net/shibboleth/profile/module/Module.java
+++ b/shib-profile-api/src/main/java/net/shibboleth/profile/module/Module.java
@@ -102,11 +102,29 @@ public interface Module extends IdentifiedComponent {
      *
      * @return summary of resource results
      *
-     * @throws ModuleException if not successful 
+     * @throws ModuleException if not successful
      */
     @Nonnull @Unmodifiable @NotLive Map<ModuleResource,ResourceResult> enable(
             @Nonnull final ModuleContext moduleContext) throws ModuleException;
 
+    /**
+     * Enable the module - with information as to whether this is a re-enable.
+     *
+     * <p>This operation MUST be idempotent.</p>
+     *
+     * @param moduleContext module context
+     * @param isReEnable has the installer determined that this was already enabled.
+     * @return summary of resource results
+     *
+     * @throws ModuleException if not successful
+     */
+    default @Nonnull @Unmodifiable @NotLive Map<ModuleResource,ResourceResult> enable(
+            @Nonnull final ModuleContext moduleContext, final boolean isReEnable) throws ModuleException
+    {
+        return enable(moduleContext);
+    }
+
+
     /**
      * Disable the module.
      *
diff --git a/shib-profile-api/src/main/java/net/shibboleth/profile/module/ModuleContext.java b/shib-profile-api/src/main/java/net/shibboleth/profile/module/ModuleContext.java
index 71c972f..d08af3b 100644
--- a/shib-profile-api/src/main/java/net/shibboleth/profile/module/ModuleContext.java
+++ b/shib-profile-api/src/main/java/net/shibboleth/profile/module/ModuleContext.java
@@ -52,9 +52,39 @@ public class ModuleContext {
     /** Output stream for sending output to the module consumer. */
     @Nullable private PrintStream messageStream;
 
+    /** PluginId if there is one. */
+    @Nullable private String pluginId;
+
+    /** What is the caller doing? */
+    public enum OperationType {
+        /**
+         * Called on initial IdP or Plugin Install.
+         * Also called if an upgrade asks for a Module which was not installed.
+         */
+        Install,
+
+        /**
+         * Called on an IdP or Plugin Upgrade if the module was enabled previously.
+         * (a re-enable)
+         */
+        Upgrade,
+
+        /** Called during plugin uninstall. */
+        Uninstall,
+
+        /** Called from the Module command (or in a test. */
+        CommandLine,
+
+        /** We haven not been told. */
+        Unknown
+
+    } ;
+
+    /** What are we doing in this case. */
+    @Nonnull private OperationType operationType = OperationType.Unknown;
+
     /**
      * Constructor.
-     *
      * @param home location of IdP install
      */
     public ModuleContext(@Nonnull @NotEmpty final String home) {
@@ -151,4 +181,31 @@ public class ModuleContext {
         messageStream = stream;
     }
 
+    /** Setter for {@link #pluginId}.
+     * @param id what to set.
+     */
+    public void setPluginId(String id) {
+        pluginId = id;
+    }
+    
+    /** Getter for {@link #pluginId}.
+     * @return Returns the pluginId.
+     */
+    @Nullable public String getPluginId() {
+        return pluginId;
+    }
+
+    /** Getter for {@link #operationType}.
+     * @return Returns the current operation type.
+     */
+    @Nullable public OperationType getOperationType() {
+        return operationType;
+    }
+
+     /** Setter for {@link #operationType}.
+     * @param type what we are about to do.
+     */
+    public void setOperationType(@Nonnull final OperationType type) {
+        operationType = type;
+    }
 }
\ No newline at end of file

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list