Skip to content

Commit

Permalink
feat(settings): add feature flags functionality IQSS#9297
Browse files Browse the repository at this point in the history
  • Loading branch information
poikilotherm committed Jan 18, 2023
1 parent e54c86f commit 5965c4f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/settings/FeatureFlags.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package edu.harvard.iq.dataverse.settings;

/**
* <p>
* This enum holds so-called "feature flags" aka "feature gates", etc. 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><p>
* If you add any new flags, please add it here, think of a default status, add some Javadocs about the flagged
* feature and add a "@since" tag to make it easier to identify when a flag has been introduced.
* </p><p>
* When removing a flag because of a feature being removed, drop the entry. When a feature matures, drop the flag,
* too! Flags are not meant to be switches for configuration!
* </p>
*
* @see <a href="https://guides.dataverse.org/en/latest/installation/config.html#feature-flags">Configuration Guide</a>
* @see <a href="https://guides.dataverse.org/en/latest/developers/configuration.html#adding-a-feature-flag">Developer Guide</a>
*/
public enum FeatureFlags {

/* None yet - please add the first here. Example code:
*
* MY_FLAG_NAME_HERE("sth-fancy", false),
*
*/

;

final String flag;
final boolean defaultStatus;

FeatureFlags(String flag, boolean defaultStatus) {
this.flag = flag;
this.defaultStatus = defaultStatus;
}

public boolean enabled() {
return JvmSettings.FEATURE_FLAG.lookupOptional(Boolean.class, flag).orElse(defaultStatus);
}

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

// FEATURE FLAGS SETTINGS
SCOPE_FLAGS(PREFIX, "feature"),
FEATURE_FLAG(SCOPE_FLAGS), // this is a placeholder, to be filled in by FeatureFlag entries

;

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

0 comments on commit 5965c4f

Please sign in to comment.