This commit is contained in:
ponzischeme89
2026-08-22 12:38:26 +12:00
parent f982d391b9
commit b3e3f62c54
26 changed files with 1279 additions and 108 deletions
+33 -10
View File
@@ -400,30 +400,52 @@ func (s *Store) SetMDBListSettings(ctx context.Context, settings MDBListSettings
const FeaturePolicyKey = "feature_policy"
type FeaturePolicySnapshot struct {
Overrides map[string]bool `json:"overrides"`
SafeMode bool `json:"safeMode"`
Revision int64 `json:"revision"`
UpdatedAt time.Time `json:"updatedAt"`
Overrides map[string]bool `json:"overrides"`
Values map[string]json.RawMessage `json:"values,omitempty"`
UserValues map[string]map[string]json.RawMessage `json:"userValues,omitempty"`
DeviceValues map[string]map[string]json.RawMessage `json:"deviceValues,omitempty"`
Experimental map[string]json.RawMessage `json:"experimental,omitempty"`
SafeMode bool `json:"safeMode"`
Revision int64 `json:"revision"`
UpdatedAt time.Time `json:"updatedAt"`
}
type FeaturePolicy struct {
Overrides map[string]bool `json:"overrides"`
SafeMode bool `json:"safeMode"`
Revision int64 `json:"revision"`
UpdatedAt time.Time `json:"updatedAt"`
Previous *FeaturePolicySnapshot `json:"previous,omitempty"`
Overrides map[string]bool `json:"overrides"`
// Values is the central typed configuration store. Raw JSON keeps the store
// forward-compatible while the API validates each catalogue entry's type.
Values map[string]json.RawMessage `json:"values,omitempty"`
UserValues map[string]map[string]json.RawMessage `json:"userValues,omitempty"`
DeviceValues map[string]map[string]json.RawMessage `json:"deviceValues,omitempty"`
Experimental map[string]json.RawMessage `json:"experimental,omitempty"`
SafeMode bool `json:"safeMode"`
Revision int64 `json:"revision"`
UpdatedAt time.Time `json:"updatedAt"`
Previous *FeaturePolicySnapshot `json:"previous,omitempty"`
}
var ErrFeaturePolicyConflict = errors.New("store: feature policy revision conflict")
func DefaultFeaturePolicy() FeaturePolicy {
return FeaturePolicy{Overrides: map[string]bool{}}
return FeaturePolicy{Overrides: map[string]bool{}, Values: map[string]json.RawMessage{}, UserValues: map[string]map[string]json.RawMessage{}, DeviceValues: map[string]map[string]json.RawMessage{}, Experimental: map[string]json.RawMessage{}}
}
func normalizeFeaturePolicy(policy FeaturePolicy) FeaturePolicy {
if policy.Overrides == nil {
policy.Overrides = map[string]bool{}
}
if policy.Values == nil {
policy.Values = map[string]json.RawMessage{}
}
if policy.UserValues == nil {
policy.UserValues = map[string]map[string]json.RawMessage{}
}
if policy.DeviceValues == nil {
policy.DeviceValues = map[string]map[string]json.RawMessage{}
}
if policy.Experimental == nil {
policy.Experimental = map[string]json.RawMessage{}
}
return policy
}
@@ -475,6 +497,7 @@ func (s *Store) SetFeaturePolicy(
next.UpdatedAt = time.Now().UTC()
next.Previous = &FeaturePolicySnapshot{
Overrides: current.Overrides, SafeMode: current.SafeMode,
Values: current.Values, UserValues: current.UserValues, DeviceValues: current.DeviceValues, Experimental: current.Experimental,
Revision: current.Revision, UpdatedAt: current.UpdatedAt,
}
raw, err := json.Marshal(next)