Parcourir la source

1.move cors into common config
2.windows can use cors, too
3.remove function setPlatformServerConfig

Signed-off-by: allencloud <allen.sun@daocloud.io>

allencloud il y a 9 ans
Parent
commit
2feb88cbd3
5 fichiers modifiés avec 5 ajouts et 18 suppressions
  1. 3 0
      daemon/config.go
  2. 0 4
      daemon/config_unix.go
  3. 2 1
      docker/daemon.go
  4. 0 8
      docker/daemon_unix.go
  5. 0 5
      docker/daemon_windows.go

+ 3 - 0
daemon/config.go

@@ -77,6 +77,8 @@ type CommonConfig struct {
 	Root                 string              `json:"graph,omitempty"`
 	SocketGroup          string              `json:"group,omitempty"`
 	TrustKeyPath         string              `json:"-"`
+	CorsHeaders          string              `json:"api-cors-headers,omitempty"`
+	EnableCors           bool                `json:"api-enable-cors,omitempty"`
 
 	// ClusterStore is the storage backend used for the cluster information. It is used by both
 	// multihost networking (to store networks and endpoints information) and by the node discovery
@@ -135,6 +137,7 @@ func (config *Config) InstallCommonFlags(cmd *flag.FlagSet, usageFn func(string)
 	cmd.StringVar(&config.ClusterAdvertise, []string{"-cluster-advertise"}, "", usageFn("Address or interface name to advertise"))
 	cmd.StringVar(&config.ClusterStore, []string{"-cluster-store"}, "", usageFn("Set the cluster store"))
 	cmd.Var(opts.NewNamedMapOpts("cluster-store-opts", config.ClusterOpts, nil), []string{"-cluster-store-opt"}, usageFn("Set cluster store options"))
+	cmd.StringVar(&config.CorsHeaders, []string{"-api-cors-header"}, "", usageFn("Set CORS headers in the remote API"))
 }
 
 // IsValueSet returns true if a configuration value

+ 0 - 4
daemon/config_unix.go

@@ -24,11 +24,8 @@ type Config struct {
 	CommonConfig
 
 	// Fields below here are platform specific.
-
 	CgroupParent         string                   `json:"cgroup-parent,omitempty"`
 	ContainerdAddr       string                   `json:"containerd,omitempty"`
-	CorsHeaders          string                   `json:"api-cors-headers,omitempty"`
-	EnableCors           bool                     `json:"api-enable-cors,omitempty"`
 	EnableSelinuxSupport bool                     `json:"selinux-enabled,omitempty"`
 	ExecRoot             string                   `json:"exec-root,omitempty"`
 	RemappedRoot         string                   `json:"userns-remap,omitempty"`
@@ -82,7 +79,6 @@ func (config *Config) InstallFlags(cmd *flag.FlagSet, usageFn func(string) strin
 	cmd.Var(opts.NewIPOpt(&config.bridgeConfig.DefaultIP, "0.0.0.0"), []string{"#ip", "-ip"}, usageFn("Default IP when binding container ports"))
 	cmd.BoolVar(&config.bridgeConfig.EnableUserlandProxy, []string{"-userland-proxy"}, true, usageFn("Use userland proxy for loopback traffic"))
 	cmd.BoolVar(&config.EnableCors, []string{"#api-enable-cors", "#-api-enable-cors"}, false, usageFn("Enable CORS headers in the remote API, this is deprecated by --api-cors-header"))
-	cmd.StringVar(&config.CorsHeaders, []string{"-api-cors-header"}, "", usageFn("Set CORS headers in the remote API"))
 	cmd.StringVar(&config.CgroupParent, []string{"-cgroup-parent"}, "", usageFn("Set parent cgroup for all containers"))
 	cmd.StringVar(&config.RemappedRoot, []string{"-userns-remap"}, "", usageFn("User/Group setting for user namespaces"))
 	cmd.StringVar(&config.ContainerdAddr, []string{"-containerd"}, "", usageFn("Path to containerd socket"))

+ 2 - 1
docker/daemon.go

@@ -179,8 +179,9 @@ func (cli *DaemonCli) start() {
 		Logging:     true,
 		SocketGroup: cli.Config.SocketGroup,
 		Version:     dockerversion.Version,
+		EnableCors:  cli.Config.EnableCors,
+		CorsHeaders: cli.Config.CorsHeaders,
 	}
-	serverConfig = setPlatformServerConfig(serverConfig, cli.Config)
 
 	if cli.Config.TLS {
 		tlsOptions := tlsconfig.Options{

+ 0 - 8
docker/daemon_unix.go

@@ -12,7 +12,6 @@ import (
 	"syscall"
 
 	"github.com/Sirupsen/logrus"
-	apiserver "github.com/docker/docker/api/server"
 	"github.com/docker/docker/daemon"
 	"github.com/docker/docker/libcontainerd"
 	"github.com/docker/docker/pkg/mflag"
@@ -22,13 +21,6 @@ import (
 
 const defaultDaemonConfigFile = "/etc/docker/daemon.json"
 
-func setPlatformServerConfig(serverConfig *apiserver.Config, daemonCfg *daemon.Config) *apiserver.Config {
-	serverConfig.EnableCors = daemonCfg.EnableCors
-	serverConfig.CorsHeaders = daemonCfg.CorsHeaders
-
-	return serverConfig
-}
-
 // currentUserIsOwner checks whether the current user is the owner of the given
 // file.
 func currentUserIsOwner(f string) bool {

+ 0 - 5
docker/daemon_windows.go

@@ -6,7 +6,6 @@ import (
 	"syscall"
 
 	"github.com/Sirupsen/logrus"
-	apiserver "github.com/docker/docker/api/server"
 	"github.com/docker/docker/daemon"
 	"github.com/docker/docker/libcontainerd"
 	"github.com/docker/docker/pkg/mflag"
@@ -15,10 +14,6 @@ import (
 
 var defaultDaemonConfigFile = os.Getenv("programdata") + string(os.PathSeparator) + "docker" + string(os.PathSeparator) + "config" + string(os.PathSeparator) + "daemon.json"
 
-func setPlatformServerConfig(serverConfig *apiserver.Config, daemonCfg *daemon.Config) *apiserver.Config {
-	return serverConfig
-}
-
 // currentUserIsOwner checks whether the current user is the owner of the given
 // file.
 func currentUserIsOwner(f string) bool {