Skip to content

Commit

Permalink
feat(settings): add feature gates functionality for the first time IQ…
Browse files Browse the repository at this point in the history
  • Loading branch information
poikilotherm committed Dec 14, 2022
1 parent 861b93c commit f5862e3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/settings/FeatureGates.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package edu.harvard.iq.dataverse.settings;

/**
* <p>This enum holds so-called "feature gates" aka "feature flags". It can be used throughout the application
* to avoid activating or using experimental functionality or feature previews that are opt-in.</p>
*
* <p>The current implementation reuses {@link JvmSettings} to interpret any
* <a href="https://download.eclipse.org/microprofile/microprofile-config-3.0/microprofile-config-spec-3.0.html#_built_in_converters">boolean values</a>
* (true == case-insensitive one of "true", "1", "YES", "Y", "ON") and hook into the usual settings system
* (any MicroProfile Config Source available).</p>
*
* If you add any new gates, please add a setting in JvmSettings, think of a default status, add some Javadocs
* about the gated feature and add a "@since" tag to make it easier to identify when a gate has been introduced.
*
*/
public enum FeatureGates {

/**
* Enabling will unblock access to the API with an OIDC access token in addition to other available methods.
* @apiNote Open gate by setting "dataverse.feature.api-oidc-access"
* @since Dataverse 5.13
* @see JvmSettings#GATE_API_OIDC_ACCESS
*/
API_OIDC_ACCESS(JvmSettings.GATE_API_OIDC_ACCESS, false),

;

final JvmSettings setting;
final boolean defaultStatus;

FeatureGates(JvmSettings setting, boolean defaultStatus) {
this.setting = setting;
this.defaultStatus = defaultStatus;
}

public boolean enabled() {
return setting.lookupOptional(Boolean.class).orElse(defaultStatus);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ public enum JvmSettings {
SCOPE_API(PREFIX, "api"),
API_SIGNING_SECRET(SCOPE_API, "signing-secret"),

// FEATURE GATES SETTINGS
SCOPE_GATES(PREFIX, "feature"),
GATE_API_OIDC_ACCESS(SCOPE_GATES, "api-oidc-access"),

;

private static final String SCOPE_SEPARATOR = ".";
Expand Down

0 comments on commit f5862e3

Please sign in to comment.