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