2022-03-10 11:46:36 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/caitlinelfring/go-env-default"
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
var u = strings.ToUpper
|
|
|
|
|
|
|
|
func NewFlagSet() (*pflag.FlagSet, Option) {
|
|
|
|
const (
|
2024-10-17 16:09:58 +00:00
|
|
|
addr = "address"
|
|
|
|
secure = "secure"
|
|
|
|
caCert = "ca-cert"
|
|
|
|
clientCert = "client-cert"
|
|
|
|
clientKey = "client-key"
|
2022-03-10 11:46:36 +00:00
|
|
|
)
|
|
|
|
var (
|
|
|
|
optAddress string
|
|
|
|
optSecure bool
|
2024-10-17 16:09:58 +00:00
|
|
|
optCACert string
|
|
|
|
optCert string
|
|
|
|
optKey string
|
2022-03-10 11:46:36 +00:00
|
|
|
)
|
|
|
|
flags := pflag.NewFlagSet("gRPC", pflag.ContinueOnError)
|
|
|
|
flags.StringVar(&optAddress, addr, env.GetDefault(u(addr), "0.0.0.0:0"), "Bind address for the server. 127.0.0.1:9090"+flagEnv(addr))
|
|
|
|
flags.BoolVar(&optSecure, secure, env.GetBoolDefault(u(secure), true), "Generate self signed certificate if none provided"+flagEnv(secure))
|
2024-10-17 16:09:58 +00:00
|
|
|
flags.StringVar(&optCACert, caCert, "", "Path to Root CA certificate"+flagEnv(optCACert))
|
|
|
|
flags.StringVar(&optCert, clientCert, "", "Path to Server certificate"+flagEnv(clientCert))
|
|
|
|
flags.StringVar(&optKey, clientKey, "", "Path to Server key"+flagEnv(clientKey))
|
2022-03-10 11:46:36 +00:00
|
|
|
return flags, func(o *options) {
|
|
|
|
o.addr = optAddress
|
|
|
|
o.secure = optSecure
|
2024-10-17 16:09:58 +00:00
|
|
|
o.caCert = optCACert
|
|
|
|
o.cert = optCert
|
|
|
|
o.key = optKey
|
2022-03-10 11:46:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func flagEnv(name string) string {
|
|
|
|
return fmt.Sprintf(" [$%s]", strings.Replace(u(name), "-", "_", -1))
|
|
|
|
}
|