| 1 | package validation |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | |
| 6 | "github.com/fatedier/frp/pkg/policy/security" |
| 7 | ) |
| 8 | |
| 9 | // ConfigValidator holds the context dependencies for configuration validation. |
| 10 | type ConfigValidator struct { |
| 11 | unsafeFeatures *security.UnsafeFeatures |
| 12 | } |
| 13 | |
| 14 | // NewConfigValidator creates a new ConfigValidator instance. |
| 15 | func NewConfigValidator(unsafeFeatures *security.UnsafeFeatures) *ConfigValidator { |
| 16 | return &ConfigValidator{ |
| 17 | unsafeFeatures: unsafeFeatures, |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | // ValidateUnsafeFeature checks if a specific unsafe feature is enabled. |
| 22 | func (v *ConfigValidator) ValidateUnsafeFeature(feature string) error { |
| 23 | if !v.unsafeFeatures.IsEnabled(feature) { |
| 24 | return fmt.Errorf("unsafe feature %q is not enabled. "+ |
| 25 | "To enable it, ensure it is allowed in the configuration or command line flags", feature) |
| 26 | } |
| 27 | return nil |
| 28 | } |