From 717a503590f5b864ee467d3d8e825748570d6e4b Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 5 Jun 2022 21:25:02 +0200 Subject: [PATCH] api: add Hosts to API Config This makes the API configuration more self-contained. Signed-off-by: Sebastiaan van Stijn --- api/server/server.go | 2 ++ cmd/dockerd/daemon.go | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/api/server/server.go b/api/server/server.go index 89c2902427..5f01a8b1dd 100644 --- a/api/server/server.go +++ b/api/server/server.go @@ -27,6 +27,8 @@ type Config struct { Version string SocketGroup string TLSConfig *tls.Config + // Hosts is a list of addresses for the API to listen on. + Hosts []string } // Server contains instance details for the server diff --git a/cmd/dockerd/daemon.go b/cmd/dockerd/daemon.go index d11e193227..b7c6d30462 100644 --- a/cmd/dockerd/daemon.go +++ b/cmd/dockerd/daemon.go @@ -639,6 +639,7 @@ func newAPIServerConfig(config *config.Config) (*apiserver.Config, error) { Version: dockerversion.Version, CorsHeaders: config.CorsHeaders, TLSConfig: tlsConfig, + Hosts: config.Hosts, }, nil } @@ -668,14 +669,14 @@ func checkTLSAuthOK(c *config.Config) bool { } func loadListeners(cli *DaemonCli, serverConfig *apiserver.Config) ([]string, error) { - if len(cli.Config.Hosts) == 0 { + if len(serverConfig.Hosts) == 0 { return nil, errors.New("no hosts configured") } var hosts []string - for i := 0; i < len(cli.Config.Hosts); i++ { - protoAddr := cli.Config.Hosts[i] - protoAddrParts := strings.SplitN(cli.Config.Hosts[i], "://", 2) + for i := 0; i < len(serverConfig.Hosts); i++ { + protoAddr := serverConfig.Hosts[i] + protoAddrParts := strings.SplitN(serverConfig.Hosts[i], "://", 2) if len(protoAddrParts) != 2 { return nil, fmt.Errorf("bad format %s, expected PROTO://ADDR", protoAddr) }