plugin.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. "errors"
  17. v1 "github.com/fatedier/frp/pkg/config/v1"
  18. )
  19. func ValidateClientPluginOptions(c v1.ClientPluginOptions) error {
  20. switch v := c.(type) {
  21. case *v1.HTTP2HTTPSPluginOptions:
  22. return validateHTTP2HTTPSPluginOptions(v)
  23. case *v1.HTTPS2HTTPPluginOptions:
  24. return validateHTTPS2HTTPPluginOptions(v)
  25. case *v1.HTTPS2HTTPSPluginOptions:
  26. return validateHTTPS2HTTPSPluginOptions(v)
  27. case *v1.StaticFilePluginOptions:
  28. return validateStaticFilePluginOptions(v)
  29. case *v1.UnixDomainSocketPluginOptions:
  30. return validateUnixDomainSocketPluginOptions(v)
  31. case *v1.TLS2RawPluginOptions:
  32. return validateTLS2RawPluginOptions(v)
  33. }
  34. return nil
  35. }
  36. func validateHTTP2HTTPSPluginOptions(c *v1.HTTP2HTTPSPluginOptions) error {
  37. if c.LocalAddr == "" {
  38. return errors.New("localAddr is required")
  39. }
  40. return nil
  41. }
  42. func validateHTTPS2HTTPPluginOptions(c *v1.HTTPS2HTTPPluginOptions) error {
  43. if c.LocalAddr == "" {
  44. return errors.New("localAddr is required")
  45. }
  46. return nil
  47. }
  48. func validateHTTPS2HTTPSPluginOptions(c *v1.HTTPS2HTTPSPluginOptions) error {
  49. if c.LocalAddr == "" {
  50. return errors.New("localAddr is required")
  51. }
  52. return nil
  53. }
  54. func validateStaticFilePluginOptions(c *v1.StaticFilePluginOptions) error {
  55. if c.LocalPath == "" {
  56. return errors.New("localPath is required")
  57. }
  58. return nil
  59. }
  60. func validateUnixDomainSocketPluginOptions(c *v1.UnixDomainSocketPluginOptions) error {
  61. if c.UnixPath == "" {
  62. return errors.New("unixPath is required")
  63. }
  64. return nil
  65. }
  66. func validateTLS2RawPluginOptions(c *v1.TLS2RawPluginOptions) error {
  67. if c.LocalAddr == "" {
  68. return errors.New("localAddr is required")
  69. }
  70. return nil
  71. }