[proxy] Added proxy.Config struct for initialization

This commit is contained in:
Paul Bellamy committed 2015-06-05 13:23:14 +01:00
1 parent c31358259f
commit c0cf9e509c
2 files changed
+70 -80

No files matched your search

+20 -30
View File
@@ -10,33 +10,30 @@ import (
)
var (
version = "(unreleased version)"
defaultTarget = "unix:///var/run/docker.sock"
defaultListen = ":12375"
version = "(unreleased version)"
defaultDockerAddr = "unix:///var/run/docker.sock"
defaultListenAddr = ":12375"
)
func main() {
var (
debug bool
justVersion bool
listen string
target string
tlsConfig proxy.TLSConfig
withDNS bool
withIPAM bool
c proxy.Config
)
c.Version = version
getopt.BoolVarLong(&debug, "debug", 'd', "log debugging information")
getopt.BoolVarLong(&justVersion, "version", 0, "print version and exit")
getopt.StringVar(&listen, 'L', fmt.Sprintf("address on which to listen (default %s)", defaultListen))
getopt.StringVar(&target, 'H', fmt.Sprintf("docker daemon URL to proxy (default %s)", defaultTarget))
getopt.StringVarLong(&tlsConfig.CACert, "tlscacert", 0, "Trust certs signed only by this CA")
getopt.StringVarLong(&tlsConfig.Cert, "tlscert", 0, "Path to TLS certificate file")
getopt.BoolVarLong(&tlsConfig.Enabled, "tls", 0, "Use TLS; implied by --tlsverify")
getopt.StringVarLong(&tlsConfig.Key, "tlskey", 0, "Path to TLS key file")
getopt.BoolVarLong(&tlsConfig.Verify, "tlsverify", 0, "Use TLS and verify the remote")
getopt.BoolVarLong(&withDNS, "with-dns", 'w', "instruct created containers to use weaveDNS as their nameserver")
getopt.BoolVarLong(&withIPAM, "with-ipam", 'i', "automatically allocate addresses for containers without a WEAVE_CIDR")
getopt.StringVar(&c.ListenAddr, 'L', fmt.Sprintf("address on which to listen (default %s)", defaultListenAddr))
getopt.StringVar(&c.DockerAddr, 'H', fmt.Sprintf("docker daemon URL to proxy (default %s)", defaultDockerAddr))
getopt.StringVarLong(&c.TLSConfig.CACert, "tlscacert", 0, "Trust certs signed only by this CA")
getopt.StringVarLong(&c.TLSConfig.Cert, "tlscert", 0, "Path to TLS certificate file")
getopt.BoolVarLong(&c.TLSConfig.Enabled, "tls", 0, "Use TLS; implied by --tlsverify")
getopt.StringVarLong(&c.TLSConfig.Key, "tlskey", 0, "Path to TLS key file")
getopt.BoolVarLong(&c.TLSConfig.Verify, "tlsverify", 0, "Use TLS and verify the remote")
getopt.BoolVarLong(&c.WithDNS, "with-dns", 'w', "instruct created containers to use weaveDNS as their nameserver")
getopt.BoolVarLong(&c.WithIPAM, "with-ipam", 'i', "automatically allocate addresses for containers without a WEAVE_CIDR")
getopt.Parse()
if justVersion {
@@ -48,27 +45,20 @@ func main() {
InitDefaultLogging(true)
}
if target == "" {
target = defaultTarget
if c.DockerAddr == "" {
c.DockerAddr = defaultDockerAddr
}
if listen == "" {
listen = defaultListen
if c.ListenAddr == "" {
c.ListenAddr = defaultListenAddr
}
p, err := proxy.NewProxy(
version,
target,
listen,
withDNS,
withIPAM,
&tlsConfig,
)
p, err := proxy.NewProxy(c)
if err != nil {
Error.Fatalf("Could not start proxy: %s", err)
}
if err := p.ListenAndServe(); err != nil {
Error.Fatalf("Could not listen on %s: %s", listen, err)
Error.Fatalf("Could not listen on %s: %s", p.ListenAddr, err)
}
}