verify.go 1.6 KB

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