1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

api: add Hosts to API Config

This makes the API configuration more self-contained.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-06-05 21:25:02 +02:00
parent fee8a6a5c4
commit 717a503590
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 7 additions and 4 deletions

View file

@ -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

View file

@ -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)
}