| // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | package validation |
| 16 |
| 17 | import ( |
| 18 | "fmt" |
| 19 | "slices" |
| 20 |
| 21 | "github.com/samber/lo" |
| 22 |
| 23 | v1 "github.com/fatedier/frp/pkg/config/v1" |
| 24 | ) |
| 25 |
| 26 | func (v *ConfigValidator) ValidateServerConfig(c *v1.ServerConfig) (Warning, error) { |
| 27 | var ( |
| 28 | warnings Warning |
| 29 | errs error |
| 30 | ) |
| 31 | if !slices.Contains(SupportedAuthMethods, c.Auth.Method) { |
| 32 | errs = AppendError(errs, fmt.Errorf("invalid auth method, optional values are %v", SupportedAuthMethods)) |
| 33 | } |
| 34 | if !lo.Every(SupportedAuthAdditionalScopes, c.Auth.AdditionalScopes) { |
| 35 | errs = AppendError(errs, fmt.Errorf("invalid auth additional scopes, optional values are %v", SupportedAuthAdditionalScopes)) |
| 36 | } |
| 37 |
| 38 | errs = AppendError(errs, v.validateAuthTokenSource(c.Auth.Token, c.Auth.TokenSource)) |
| 39 |
| 40 | if err := validateLogConfig(&c.Log); err != nil { |
| 41 | errs = AppendError(errs, err) |
| 42 | } |
| 43 |
| 44 | if err := validateWebServerConfig(&c.WebServer); err != nil { |
| 45 | errs = AppendError(errs, err) |
| 46 | } |
| 47 |
| 48 | errs = AppendError(errs, ValidatePort(c.BindPort, "bindPort")) |
| 49 | errs = AppendError(errs, ValidatePort(c.KCPBindPort, "kcpBindPort")) |
| 50 | errs = AppendError(errs, ValidatePort(c.QUICBindPort, "quicBindPort")) |
| 51 | errs = AppendError(errs, ValidatePort(c.VhostHTTPPort, "vhostHTTPPort")) |
| 52 | errs = AppendError(errs, ValidatePort(c.VhostHTTPSPort, "vhostHTTPSPort")) |
| 53 | errs = AppendError(errs, ValidatePort(c.TCPMuxHTTPConnectPort, "tcpMuxHTTPConnectPort")) |
| 54 |
| 55 | for _, p := range c.HTTPPlugins { |
| 56 | if !lo.Every(SupportedHTTPPluginOps, p.Ops) { |
| 57 | errs = AppendError(errs, fmt.Errorf("invalid http plugin ops, optional values are %v", SupportedHTTPPluginOps)) |
| 58 | } |
| 59 | } |
| 60 | return warnings, errs |
| 61 | } |