[CONSUL-542] Create OS Specific Files for Envoy Package (#88)

pull/15114/head
Jose Ignacio Lorenzo 2 years ago committed by Jose Ignacio Lorenzo
parent 5e0bec20c6
commit 41c02a060e

@ -0,0 +1,6 @@
//go:build linux || darwin
// +build linux darwin
package envoy
const DefaultAdminAccessLogPath = "/dev/null"

@ -0,0 +1,6 @@
//go:build windows
// +build windows
package envoy
const DefaultAdminAccessLogPath = "nul"

@ -7,7 +7,6 @@ import (
"net"
"os"
"os/exec"
"runtime"
"strings"
"github.com/mitchellh/cli"
@ -23,15 +22,12 @@ import (
"github.com/hashicorp/consul/tlsutil"
)
func New(ui cli.Ui, osPlatform string) *cmd {
func New(ui cli.Ui) *cmd {
c := &cmd{UI: ui}
c.init(osPlatform)
c.init()
return c
}
const DefaultUnixAdminAccessLogPath = "/dev/null"
const DefaultWindowsAdminAccessLogPath = "nul"
type cmd struct {
UI cli.Ui
flags *flag.FlagSet
@ -84,7 +80,7 @@ var supportedGateways = map[string]api.ServiceKind{
"ingress": api.ServiceKindIngressGateway,
}
func (c *cmd) init(osPlatform string) {
func (c *cmd) init() {
c.flags = flag.NewFlagSet("", flag.ContinueOnError)
c.flags.StringVar(&c.proxyID, "proxy-id", os.Getenv("CONNECT_PROXY_ID"),
@ -110,17 +106,10 @@ func (c *cmd) init(osPlatform string) {
"The full path to the envoy binary to run. By default will just search "+
"$PATH. Ignored if -bootstrap is used.")
if osPlatform == "windows" {
c.flags.StringVar(&c.adminAccessLogPath, "admin-access-log-path", DefaultWindowsAdminAccessLogPath,
fmt.Sprintf("The path to write the access log for the administration server. If no access "+
"log is desired specify %q. By default it will use %q.",
DefaultWindowsAdminAccessLogPath, DefaultWindowsAdminAccessLogPath))
} else {
c.flags.StringVar(&c.adminAccessLogPath, "admin-access-log-path", DefaultUnixAdminAccessLogPath,
fmt.Sprintf("The path to write the access log for the administration server. If no access "+
"log is desired specify %q. By default it will use %q.",
DefaultUnixAdminAccessLogPath, DefaultUnixAdminAccessLogPath))
}
c.flags.StringVar(&c.adminAccessLogPath, "admin-access-log-path", DefaultAdminAccessLogPath,
fmt.Sprintf("The path to write the access log for the administration server. If no access "+
"log is desired specify %q. By default it will use %q.",
DefaultAdminAccessLogPath, DefaultAdminAccessLogPath))
c.flags.StringVar(&c.adminBind, "admin-bind", "localhost:19000",
"The address:port to start envoy's admin server on. Envoy requires this "+
@ -268,11 +257,10 @@ func (c *cmd) Run(args []string) int {
return 1
}
// TODO: refactor
osPlatform := runtime.GOOS
return c.run(c.flags.Args(), osPlatform)
return c.run(c.flags.Args())
}
func (c *cmd) run(args []string, osPlatform string) int {
func (c *cmd) run(args []string) int {
if c.nodeName != "" && c.proxyID == "" {
c.UI.Error("'-node-name' requires '-proxy-id'")
@ -439,7 +427,7 @@ func (c *cmd) run(args []string, osPlatform string) int {
}
// Generate config
bootstrapJson, err := c.generateConfig(osPlatform)
bootstrapJson, err := c.generateConfig()
if err != nil {
c.UI.Error(err.Error())
return 1
@ -482,7 +470,7 @@ func (c *cmd) findBinary() (string, error) {
return exec.LookPath("envoy")
}
func (c *cmd) templateArgs(osPlatform string) (*BootstrapTplArgs, error) {
func (c *cmd) templateArgs() (*BootstrapTplArgs, error) {
httpCfg := api.DefaultConfig()
c.http.MergeOntoConfig(httpCfg)
@ -525,11 +513,7 @@ func (c *cmd) templateArgs(osPlatform string) (*BootstrapTplArgs, error) {
adminAccessLogPath := c.adminAccessLogPath
if adminAccessLogPath == "" {
if osPlatform == "windows" {
adminAccessLogPath = DefaultWindowsAdminAccessLogPath
} else {
adminAccessLogPath = DefaultUnixAdminAccessLogPath
}
adminAccessLogPath = DefaultAdminAccessLogPath
}
// Fallback to the old certificate configuration, if none was defined.
@ -570,8 +554,8 @@ func (c *cmd) templateArgs(osPlatform string) (*BootstrapTplArgs, error) {
}, nil
}
func (c *cmd) generateConfig(osPlatform string) ([]byte, error) {
args, err := c.templateArgs(osPlatform)
func (c *cmd) generateConfig() ([]byte, error) {
args, err := c.templateArgs()
if err != nil {
return nil, err
}

Loading…
Cancel
Save