Move devMode config option to config pkg

This commit is contained in:
Daniel 2021-01-28 16:49:25 +01:00
parent fa18d1ef4c
commit 7dd62276af
4 changed files with 49 additions and 4 deletions

39
config/devmode.go Normal file
View file

@ -0,0 +1,39 @@
package config
import (
"flag"
"github.com/safing/portbase/log"
)
// Configuration Keys.
var (
CfgDevModeKey = "core/devMode"
defaultDevMode bool
)
func init() {
flag.BoolVar(&defaultDevMode, "devmode", false, "enable development mode")
}
func logDevModeOverride() {
if defaultDevMode {
log.Warning("config: development mode is enabled by default by the -devmode flag")
}
}
func registerDevModeOption() error {
return Register(&Option{
Name: "Development Mode",
Key: CfgDevModeKey,
Description: "In Development Mode, security restrictions are lifted/softened to enable unrestricted access for debugging and testing purposes.",
OptType: OptTypeBool,
ExpertiseLevel: ExpertiseLevelDeveloper,
ReleaseLevel: ReleaseLevelStable,
DefaultValue: defaultDevMode,
Annotations: Annotations{
DisplayOrderAnnotation: 512,
CategoryAnnotation: "Development",
},
})
}

View file

@ -14,7 +14,7 @@ import (
// to change deep configuration settings. // to change deep configuration settings.
type ExpertiseLevel uint8 type ExpertiseLevel uint8
// Expertise Level constants // Expertise Level constants.
const ( const (
ExpertiseLevelUser ExpertiseLevel = 0 ExpertiseLevelUser ExpertiseLevel = 0
ExpertiseLevelExpert ExpertiseLevel = 1 ExpertiseLevelExpert ExpertiseLevel = 1

View file

@ -47,6 +47,12 @@ func prep() error {
modules.SetCmdLineOperation(exportConfigCmd) modules.SetCmdLineOperation(exportConfigCmd)
} }
logDevModeOverride()
err := registerDevModeOption()
if err != nil {
return err
}
return nil return nil
} }

View file

@ -60,7 +60,7 @@ type PossibleValue struct {
// future well-known annotation additions do not conflict // future well-known annotation additions do not conflict
// with vendor/product/package specific annoations. // with vendor/product/package specific annoations.
// //
// Format: <vendor/package>:<scope>:<identifier> // Format: <vendor/package>:<scope>:<identifier> //.
type Annotations map[string]interface{} type Annotations map[string]interface{}
// Well known annotations defined by this package. // Well known annotations defined by this package.
@ -144,7 +144,7 @@ type ValueRequirement struct {
Value interface{} Value interface{}
} }
// Values for the DisplayHintAnnotation // Values for the DisplayHintAnnotation.
const ( const (
// DisplayHintOneOf is used to mark an option // DisplayHintOneOf is used to mark an option
// as a "select"-style option. That is, only one of // as a "select"-style option. That is, only one of
@ -263,7 +263,7 @@ func (option *Option) SetAnnotation(key string, value interface{}) {
option.Annotations[key] = value option.Annotations[key] = value
} }
// GetAnnotation returns the value of the annotation key // GetAnnotation returns the value of the annotation key.
func (option *Option) GetAnnotation(key string) (interface{}, bool) { func (option *Option) GetAnnotation(key string) (interface{}, bool) {
option.Lock() option.Lock()
defer option.Unlock() defer option.Unlock()