diff --git a/README.md b/README.md index 45e368f72..e077cc47c 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ $ S3_GW_PEERS_0_ADDRESS=grpcs://192.168.130.72:8080 \ In general, everything available as CLI parameter can also be specified via environment variables, so they're not specifically mentioned in most cases -(see `--help` also). +(see `--help` also). If you prefer a config file you can use it in yaml format. ### Nodes and weights @@ -107,6 +107,42 @@ Pprof and Prometheus are integrated into the gateway, but not enabled by default. To enable them use `--pprof` and `--metrics` flags or `HTTP_GW_PPROF`/`HTTP_GW_METRICS` environment variables. +### Yaml file +Configuration file is optional and can be used instead of environment variables/other parameters. +It can be specified with `--config` parameter: +``` +$ neofs-s3-gw --config your-config.yaml +``` + +Configuration file example: +``` +listen_address: 0.0.0.0:8084 + +wallet: + passphrase: 123456 + +logger: + level: debug + +peers: + 0: + address: s01.neofs.devenv:8080 + weight: 1 +``` + +To know nesting level of variable you need to cut off the prefix `S3_GW` from variable and split the rest parts by `_`. +For example variable `S3_GW_PEERS_0_WEIGHT=1` will be transformed to: +``` +peers: + 0: + weight: 1 +``` + +If parameter doesn't support environment variable (e.g. `--listen_address 0.0.0.0:8084`) form it is used as is: +``` +listen_address: 0.0.0.0:8084 +``` + ## NeoFS AuthMate Authmate is a tool to create gateway AWS credentials. AWS users diff --git a/cmd/s3-gw/app-settings.go b/cmd/s3-gw/app-settings.go index 74cf2a5f3..44441ebb2 100644 --- a/cmd/s3-gw/app-settings.go +++ b/cmd/s3-gw/app-settings.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "io" "os" "sort" "strconv" @@ -17,8 +16,6 @@ import ( ) const ( - devNull = empty(0) - minimumTTLInMinutes = 5 defaultTTL = minimumTTLInMinutes * time.Minute @@ -81,6 +78,7 @@ const ( // Settings. // Command line args. cmdHelp = "help" cmdVersion = "version" + cmdConfig = "config" // applicationName is gateway name. applicationName = "neofs-s3-gw" @@ -89,8 +87,6 @@ const ( // Settings. envPrefix = "S3_GW" ) -type empty int - var ignore = map[string]struct{}{ cfgApplicationName: {}, cfgApplicationVersion: {}, @@ -102,8 +98,6 @@ var ignore = map[string]struct{}{ cmdVersion: {}, } -func (empty) Read([]byte) (int, error) { return 0, io.EOF } - func fetchPeers(l *zap.Logger, v *viper.Viper) *pool.Builder { pb := new(pool.Builder) @@ -166,6 +160,7 @@ func newSettings() *viper.Viper { flags.StringP(cfgWallet, "w", "", `path to the wallet`) flags.String(cfgAddress, "", `address of wallet account`) + config := flags.String(cmdConfig, "", "config path") flags.Bool(cfgGRPCVerbose, false, "set debug mode of gRPC connections") flags.Duration(cfgRequestTimeout, defaultRequestTimeout, "set gRPC request timeout") @@ -204,10 +199,6 @@ func newSettings() *viper.Viper { panic(err) } - if err := v.ReadConfig(devNull); err != nil { - panic(err) - } - if err := flags.Parse(os.Args); err != nil { panic(err) } @@ -262,5 +253,13 @@ func newSettings() *viper.Viper { fmt.Printf("connection ttl should not be less than %s", defaultTTL) } + if v.IsSet(cmdConfig) { + if cfgFile, err := os.Open(*config); err != nil { + panic(err) + } else if err := v.ReadConfig(cfgFile); err != nil { + panic(err) + } + } + return v }