diff --git a/cmd/gate/app-settings.go b/cmd/gate/app-settings.go index e38a73ac..a504758e 100644 --- a/cmd/gate/app-settings.go +++ b/cmd/gate/app-settings.go @@ -75,6 +75,7 @@ const ( // settings cfgEnableMetrics = "metrics" cfgEnableProfiler = "pprof" cfgListenAddress = "listen_address" + cfgListenDomains = "listen_domains" // Peers cfgPeers = "peers" @@ -127,6 +128,21 @@ func fetchPeers(l *zap.Logger, v *viper.Viper) map[string]float64 { return peers } +func fetchDomains(v *viper.Viper) []string { + cnt := v.GetInt(cfgListenDomains + ".count") + res := make([]string, 0, cnt) + for i := 0; ; i++ { + domain := v.GetString(cfgListenDomains + "." + strconv.Itoa(i)) + if domain == "" { + break + } + + res = append(res, domain) + } + + return res +} + func newSettings() *viper.Viper { v := viper.New() @@ -162,6 +178,8 @@ func newSettings() *viper.Viper { flags.String(cfgListenAddress, "0.0.0.0:8080", "set address to listen") peers := flags.StringArrayP(cfgPeers, "p", nil, "set NeoFS nodes") + domains := flags.StringArrayP(cfgListenDomains, "d", nil, "set domains to be listened") + // set prefers: v.Set(cfgApplicationName, misc.ApplicationName) v.Set(cfgApplicationVersion, misc.Version) @@ -203,6 +221,14 @@ func newSettings() *viper.Viper { } } + if domains != nil && len(*domains) > 0 { + for i := range *domains { + v.SetDefault(cfgListenDomains+"."+strconv.Itoa(i), (*domains)[i]) + } + + v.SetDefault(cfgListenDomains+".count", len(*domains)) + } + switch { case help != nil && *help: fmt.Printf("NeoFS S3 Gateway %s (%s)\n", misc.Version, misc.Build) diff --git a/cmd/gate/app.go b/cmd/gate/app.go index bc183bfc..d13d782b 100644 --- a/cmd/gate/app.go +++ b/cmd/gate/app.go @@ -214,7 +214,10 @@ func (a *App) Server(ctx context.Context) { attachProfiler(router, a.cfg, a.log) // Attach S3 API: - api.Attach(router, a.maxClients, a.api, a.ctr, a.log) + domains := fetchDomains(a.cfg) + a.log.Info("fetch domains, prepare to use API", + zap.Strings("domains", domains)) + api.Attach(router, domains, a.maxClients, a.api, a.ctr, a.log) // Use mux.Router as http.Handler srv.Handler = router