1616
1717package utils
1818
19+ import uk .gov .hmrc .play .bootstrap .config .ServicesConfig
20+
1921import java .time .format .DateTimeFormatter
2022import java .time .{ZoneId , ZonedDateTime }
2123import scala .util .matching .Regex
@@ -54,19 +56,18 @@ object FeatureSwitch {
5456 val dateFormat : DateTimeFormatter = DateTimeFormatter .ISO_OFFSET_DATE_TIME
5557
5658
57- private [utils] def getProperty (name : String ): FeatureSwitch = {
59+ private [utils] def getProperty (name : String )( implicit config : ServicesConfig ) : FeatureSwitch = {
5860 val value = sys.props.get(systemPropertyName(name))
59-
6061 value match {
6162 case Some (" true" ) => BooleanFeatureSwitch (name, enabled = true )
6263 case Some (DisabledIntervalExtractor (start, end)) => DisabledTimedFeatureSwitch (name, toDate(start), toDate(end), ZonedDateTime .now(ZoneId .of(" UTC" )))
6364 case Some (EnabledIntervalExtractor (start, end)) => EnabledTimedFeatureSwitch (name, toDate(start), toDate(end), ZonedDateTime .now(ZoneId .of(" UTC" )))
6465
65- case _ => BooleanFeatureSwitch (name, enabled = false )
66+ case _ => BooleanFeatureSwitch (name, enabled = config.getBoolean( s " feature. $name " ) )
6667 }
6768 }
6869
69- private [utils] def setProperty (name : String , value : String ): FeatureSwitch = {
70+ private [utils] def setProperty (name : String , value : String )( implicit config : ServicesConfig ) : FeatureSwitch = {
7071 sys.props += ((systemPropertyName(name), value))
7172 getProperty(name)
7273 }
@@ -81,21 +82,21 @@ object FeatureSwitch {
8182
8283 private [utils] def systemPropertyName (name : String ) = s " feature. $name"
8384
84- def enable (fs : FeatureSwitch ): FeatureSwitch = setProperty(fs.name, " true" )
85- def disable (fs : FeatureSwitch ): FeatureSwitch = setProperty(fs.name, " false" )
85+ def enable (fs : FeatureSwitch )( implicit config : ServicesConfig ) : FeatureSwitch = setProperty(fs.name, " true" )
86+ def disable (fs : FeatureSwitch )( implicit config : ServicesConfig ) : FeatureSwitch = setProperty(fs.name, " false" )
8687
87- def apply (name : String , enabled : Boolean = false ): FeatureSwitch = getProperty(name)
88+ def apply (name : String , enabled : Boolean = false )( implicit config : ServicesConfig ) : FeatureSwitch = getProperty(name)
8889 def unapply (fs : FeatureSwitch ): Option [(String , Boolean )] = Some (fs.name -> fs.enabled)
8990}
9091
9192object AWRSFeatureSwitches extends AWRSFeatureSwitches
9293
9394trait AWRSFeatureSwitches {
9495
95- def regimeCheck (): FeatureSwitch = FeatureSwitch .getProperty(" regimeCheck" )
96- def hipSwitch (): FeatureSwitch = FeatureSwitch .getProperty(" hipSwitch" )
96+ def regimeCheck ()( implicit config : ServicesConfig ) : FeatureSwitch = FeatureSwitch .getProperty(" regimeCheck" )
97+ def hipSwitch ()( implicit config : ServicesConfig ) : FeatureSwitch = FeatureSwitch .getProperty(" hipSwitch" )
9798
98- def apply (name : String ): Option [FeatureSwitch ] = name match {
99+ def apply (name : String )( implicit config : ServicesConfig ) : Option [FeatureSwitch ] = name match {
99100 case " regimeCheck" => Some (regimeCheck())
100101 case " hipSwitch" => Some (hipSwitch())
101102 case _ => None
0 commit comments