insecure_serving.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package options
  2. import (
  3. "fmt"
  4. "github.com/spf13/pflag"
  5. )
  6. // InsecureServingOptions 不安全的服务配置信息
  7. type InsecureServeOptions struct {
  8. BindAddress string `json:"bind-address" mapstructure:"bind-address"`
  9. BindPort int `json:"bind-port" mapstructure:"bind-port"`
  10. }
  11. func NewInsecureServingOptions() *InsecureServeOptions {
  12. return &InsecureServeOptions{
  13. BindAddress: "127.0.0.1",
  14. BindPort: 8080,
  15. }
  16. }
  17. func (s *InsecureServeOptions) Validate() []error {
  18. var errors []error
  19. if s.BindPort < 0 || s.BindPort > 65535 {
  20. errors = append(
  21. errors,
  22. fmt.Errorf(
  23. "--insecure.bind-port %v must be between 0 and 65535, inclusive. 0 for turning off insecure (HTTP) port",
  24. s.BindPort,
  25. ),
  26. )
  27. }
  28. return errors
  29. }
  30. func (s *InsecureServeOptions) AddFlags(fs *pflag.FlagSet) {
  31. fs.StringVar(&s.BindAddress, "insecure.bind-address", s.BindAddress, ""+
  32. "The IP address on which to serve the --insecure.bind-port "+
  33. "(set to 0.0.0.0 for all IPv4 interfaces and :: for all IPv6 interfaces).")
  34. fs.IntVar(&s.BindPort, "insecure.bind-port", s.BindPort, ""+
  35. "The port on which to serve unsecured, unauthenticated access. It is assumed "+
  36. "that firewall rules are set up such that this port is not reachable from outside of "+
  37. "the deployed machine and that port 443 on the iam public address is proxied to this "+
  38. "port. This is performed by nginx in the default setup. Set to zero to disable.")
  39. }