server.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // Copyright 2023 The frp Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  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. package validation
  15. import (
  16. "fmt"
  17. "github.com/samber/lo"
  18. v1 "github.com/fatedier/frp/pkg/config/v1"
  19. )
  20. func ValidateServerConfig(c *v1.ServerConfig) (Warning, error) {
  21. var (
  22. warnings Warning
  23. errs error
  24. )
  25. if !lo.Contains(SupportedAuthMethods, c.Auth.Method) {
  26. errs = AppendError(errs, fmt.Errorf("invalid auth method, optional values are %v", SupportedAuthMethods))
  27. }
  28. if !lo.Every(SupportedAuthAdditionalScopes, c.Auth.AdditionalScopes) {
  29. errs = AppendError(errs, fmt.Errorf("invalid auth additional scopes, optional values are %v", SupportedAuthAdditionalScopes))
  30. }
  31. if err := validateLogConfig(&c.Log); err != nil {
  32. errs = AppendError(errs, err)
  33. }
  34. if err := validateWebServerConfig(&c.WebServer); err != nil {
  35. errs = AppendError(errs, err)
  36. }
  37. errs = AppendError(errs, ValidatePort(c.BindPort, "bindPort"))
  38. errs = AppendError(errs, ValidatePort(c.KCPBindPort, "kcpBindPort"))
  39. errs = AppendError(errs, ValidatePort(c.QUICBindPort, "quicBindPort"))
  40. errs = AppendError(errs, ValidatePort(c.VhostHTTPPort, "vhostHTTPPort"))
  41. errs = AppendError(errs, ValidatePort(c.VhostHTTPSPort, "vhostHTTPSPort"))
  42. errs = AppendError(errs, ValidatePort(c.TCPMuxHTTPConnectPort, "tcpMuxHTTPConnectPort"))
  43. for _, p := range c.HTTPPlugins {
  44. if !lo.Every(SupportedHTTPPluginOps, p.Ops) {
  45. errs = AppendError(errs, fmt.Errorf("invalid http plugin ops, optional values are %v", SupportedHTTPPluginOps))
  46. }
  47. }
  48. return warnings, errs
  49. }