Merge pull request from safing/feature/config-annotation

Add config annotation to mark a setting as "plan requires"
This commit is contained in:
Daniel Hovie 2023-07-20 14:29:21 +02:00 committed by GitHub
commit e033cff403
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

2
.gitignore vendored
View file

@ -4,3 +4,5 @@ misc
go.mod.*
vendor
go.work
go.work.sum

View file

@ -108,6 +108,10 @@ const (
// requirement. The type of RequiresAnnotation is []ValueRequirement
// or ValueRequirement.
RequiresAnnotation = "safing/portbase:config:requires"
// RequiresFeaturePlan can be used to mark a setting as only available
// when the user has a certain feature ID in the subscription plan.
// The type is []string or string.
RequiresFeatureID = "safing/portmaster:ui:config:requires-feature"
)
// QuickSettingsAction defines the action of a quick setting.

View file

@ -52,6 +52,7 @@ func replaceConfig(newValues map[string]interface{}) []*ValidationError {
option.Lock()
option.activeValue = nil
if ok {
valueCache, err := validateValue(option, newValue)
if err == nil {
@ -103,11 +104,11 @@ func replaceDefaultConfig(newValues map[string]interface{}) []*ValidationError {
}
// SetConfigOption sets a single value in the (prioritized) user defined config.
func SetConfigOption(key string, value interface{}) error {
func SetConfigOption(key string, value any) error {
return setConfigOption(key, value, true)
}
func setConfigOption(key string, value interface{}, push bool) (err error) {
func setConfigOption(key string, value any, push bool) (err error) {
option, err := GetOption(key)
if err != nil {
return err