1
0

verify.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2021 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 sub
  15. import (
  16. "fmt"
  17. "os"
  18. "github.com/spf13/cobra"
  19. "github.com/fatedier/frp/pkg/config"
  20. v1 "github.com/fatedier/frp/pkg/config/v1"
  21. "github.com/fatedier/frp/pkg/config/v1/validation"
  22. )
  23. func init() {
  24. rootCmd.AddCommand(verifyCmd)
  25. }
  26. var verifyCmd = &cobra.Command{
  27. Use: "verify",
  28. Short: "Verify that the configures is valid",
  29. RunE: func(cmd *cobra.Command, args []string) error {
  30. if cfgFile == "" {
  31. fmt.Println("frpc: the configuration file is not specified")
  32. return nil
  33. }
  34. cliCfg, proxyCfgs, visitorCfgs, _, err := config.LoadClientConfig(cfgFile, strictConfigMode)
  35. if err != nil {
  36. fmt.Println(err)
  37. os.Exit(1)
  38. }
  39. unsafeFeatures := v1.NewUnsafeFeatures(allowUnsafe)
  40. warning, err := validation.ValidateAllClientConfig(cliCfg, proxyCfgs, visitorCfgs, unsafeFeatures)
  41. if warning != nil {
  42. fmt.Printf("WARNING: %v\n", warning)
  43. }
  44. if err != nil {
  45. fmt.Println(err)
  46. os.Exit(1)
  47. }
  48. fmt.Printf("frpc: the configuration file %s syntax is ok\n", cfgFile)
  49. return nil
  50. },
  51. }