[#25] Show default environments
- Add possibility to display default environments - Add Prefix constant - Update README closes #25 Signed-off-by: Evgeniy Kulikov <kim@nspcc.ru>
This commit is contained in:
parent
424fb7a1d1
commit
14517d682c
3 changed files with 109 additions and 15 deletions
52
README.md
52
README.md
|
@ -1,11 +1,59 @@
|
|||
# NeoFS S3 Gate
|
||||
|
||||
...
|
||||
## Example of configuration
|
||||
|
||||
```
|
||||
# Flags
|
||||
--pprof enable pprof
|
||||
--metrics enable prometheus metrics
|
||||
-h, --help show help
|
||||
-v, --version show version
|
||||
--neofs-key string set value to hex string, WIF string, or path to NeoFS private key file (use "generated" to generate key) (default "generated")
|
||||
--auth-key string set path to file with auth (curve25519) private key to use in auth scheme
|
||||
--verbose set debug mode of gRPC connections
|
||||
--request_timeout duration set gRPC request timeout (default 15s)
|
||||
--connect_timeout duration set gRPC connect timeout (default 30s)
|
||||
--rebalance_timer duration set gRPC connection rebalance timer (default 15s)
|
||||
--max_clients_count int set max-clients count (default 100)
|
||||
--max_clients_deadline duration set max-clients deadline (default 30s)
|
||||
-t, --con_ttl duration set gRPC connection time to live (default 5m0s)
|
||||
--listen_address string set address to listen (default "0.0.0.0:8080")
|
||||
-p, --peers stringArray set NeoFS nodes
|
||||
|
||||
# Environments
|
||||
|
||||
S3_AUTH-KEY =
|
||||
S3_CON_TTL = 5m0s
|
||||
S3_CONNECT_TIMEOUT = 30s
|
||||
S3_KEEPALIVE_PERMIT_WITHOUT_STREAM = true
|
||||
S3_KEEPALIVE_TIME = 10s
|
||||
S3_KEEPALIVE_TIMEOUT = 10s
|
||||
S3_LISTEN_ADDRESS = 0.0.0.0:8080
|
||||
S3_LOGGER_FORMAT = console
|
||||
S3_LOGGER_LEVEL = debug
|
||||
S3_LOGGER_NO_DISCLAIMER = true
|
||||
S3_LOGGER_SAMPLING_INITIAL = 1000
|
||||
S3_LOGGER_SAMPLING_THEREAFTER = 1000
|
||||
S3_LOGGER_TRACE_LEVEL = panic
|
||||
S3_MAX_CLIENTS_COUNT = 100
|
||||
S3_MAX_CLIENTS_DEADLINE = 30s
|
||||
S3_METRICS = false
|
||||
S3_NEOFS-KEY = generated
|
||||
S3_PPROF = false
|
||||
S3_REBALANCE_TIMER = 15s
|
||||
S3_REQUEST_TIMEOUT = 15s
|
||||
S3_VERBOSE = false
|
||||
|
||||
# Peers preset
|
||||
|
||||
S3_PEERS_[N]_ADDRESS = string
|
||||
S3_PEERS_[N]_WEIGHT = 0..1 (float)
|
||||
```
|
||||
|
||||
---
|
||||
<footer>
|
||||
|
||||
# MinIO Fork
|
||||
#### MinIO Fork
|
||||
|
||||
Forked from https://github.com/minio/minio (https://github.com/minio/minio/releases/tag/RELEASE.2020-07-02T00-15-09Z)
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
@ -84,14 +85,32 @@ const ( // settings
|
|||
cfgEnableProfiler = "pprof"
|
||||
cfgListenAddress = "listen_address"
|
||||
|
||||
// Peers
|
||||
cfgPeers = "peers"
|
||||
|
||||
// Application
|
||||
cfgApplicationName = "app.name"
|
||||
cfgApplicationVersion = "app.version"
|
||||
cfgApplicationBuildTime = "app.build_time"
|
||||
|
||||
// command line args
|
||||
cmdHelp = "help"
|
||||
cmdVersion = "version"
|
||||
)
|
||||
|
||||
type empty int
|
||||
|
||||
var ignore = map[string]struct{}{
|
||||
cfgApplicationName: {},
|
||||
cfgApplicationVersion: {},
|
||||
cfgApplicationBuildTime: {},
|
||||
|
||||
cfgPeers: {},
|
||||
|
||||
cmdHelp: {},
|
||||
cmdVersion: {},
|
||||
}
|
||||
|
||||
func (empty) Read([]byte) (int, error) { return 0, io.EOF }
|
||||
|
||||
func fetchGateAuthKeys(v *viper.Viper) (*hcs.X25519Keys, error) {
|
||||
|
@ -142,7 +161,7 @@ func fetchPeers(l *zap.Logger, v *viper.Viper) []pool.Peer {
|
|||
|
||||
for i := 0; ; i++ {
|
||||
|
||||
key := "peers." + strconv.Itoa(i) + "."
|
||||
key := cfgPeers + "." + strconv.Itoa(i) + "."
|
||||
address := v.GetString(key + "address")
|
||||
weight := v.GetFloat64(key + "weight")
|
||||
|
||||
|
@ -164,7 +183,7 @@ func newSettings() *viper.Viper {
|
|||
v := viper.New()
|
||||
|
||||
v.AutomaticEnv()
|
||||
v.SetEnvPrefix("S3")
|
||||
v.SetEnvPrefix(misc.Prefix)
|
||||
v.SetConfigType("yaml")
|
||||
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||
|
||||
|
@ -175,8 +194,8 @@ func newSettings() *viper.Viper {
|
|||
flags.Bool(cfgEnableProfiler, false, "enable pprof")
|
||||
flags.Bool(cfgEnableMetrics, false, "enable prometheus metrics")
|
||||
|
||||
help := flags.BoolP("help", "h", false, "show help")
|
||||
version := flags.BoolP("version", "v", false, "show version")
|
||||
help := flags.BoolP(cmdHelp, "h", false, "show help")
|
||||
version := flags.BoolP(cmdVersion, "v", false, "show version")
|
||||
|
||||
flags.String(cfgNeoFSPrivateKey, generated, fmt.Sprintf(`set value to hex string, WIF string, or path to NeoFS private key file (use "%s" to generate key)`, generated))
|
||||
flags.String(cfgGateAuthPrivateKey, "", "set path to file with auth (curve25519) private key to use in auth scheme")
|
||||
|
@ -192,7 +211,7 @@ func newSettings() *viper.Viper {
|
|||
ttl := flags.DurationP(cfgConnectionTTL, "t", defaultTTL, "set gRPC connection time to live")
|
||||
|
||||
flags.String(cfgListenAddress, "0.0.0.0:8080", "set address to listen")
|
||||
peers := flags.StringArrayP("peers", "p", nil, "set NeoFS nodes")
|
||||
peers := flags.StringArrayP(cfgPeers, "p", nil, "set NeoFS nodes")
|
||||
|
||||
// set prefers:
|
||||
v.Set(cfgApplicationName, misc.ApplicationName)
|
||||
|
@ -227,10 +246,40 @@ func newSettings() *viper.Viper {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
if peers != nil && len(*peers) > 0 {
|
||||
for i := range *peers {
|
||||
v.SetDefault(cfgPeers+"."+strconv.Itoa(i)+".address", (*peers)[i])
|
||||
v.SetDefault(cfgPeers+"."+strconv.Itoa(i)+".weight", 1)
|
||||
}
|
||||
}
|
||||
|
||||
switch {
|
||||
case help != nil && *help:
|
||||
fmt.Printf("NeoFS S3 Gateway %s (%s)\n", misc.Version, misc.Build)
|
||||
flags.PrintDefaults()
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("Default environments:")
|
||||
fmt.Println()
|
||||
keys := v.AllKeys()
|
||||
sort.Strings(keys)
|
||||
|
||||
for i := range keys {
|
||||
if _, ok := ignore[keys[i]]; ok {
|
||||
continue
|
||||
}
|
||||
|
||||
k := strings.Replace(keys[i], ".", "_", -1)
|
||||
fmt.Printf("%s_%s = %v\n", misc.Prefix, strings.ToUpper(k), v.Get(keys[i]))
|
||||
}
|
||||
|
||||
fmt.Println()
|
||||
fmt.Println("Peers preset:")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Printf("%s_%s_[N]_ADDRESS = string\n", misc.Prefix, strings.ToUpper(cfgPeers))
|
||||
fmt.Printf("%s_%s_[N]_WEIGHT = 0..1 (float)\n", misc.Prefix, strings.ToUpper(cfgPeers))
|
||||
|
||||
os.Exit(0)
|
||||
case version != nil && *version:
|
||||
fmt.Printf("NeoFS S3 Gateway %s (%s)\n", misc.Version, misc.Build)
|
||||
|
@ -239,12 +288,5 @@ func newSettings() *viper.Viper {
|
|||
fmt.Printf("connection ttl should not be less than %s", defaultTTL)
|
||||
}
|
||||
|
||||
if peers != nil && len(*peers) > 0 {
|
||||
for i := range *peers {
|
||||
v.SetDefault("peers."+strconv.Itoa(i)+".address", (*peers)[i])
|
||||
v.SetDefault("peers."+strconv.Itoa(i)+".weight", 1)
|
||||
}
|
||||
}
|
||||
|
||||
return v
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
package misc
|
||||
|
||||
const ApplicationName = "neofs-s3-gate"
|
||||
const (
|
||||
Prefix = "S3"
|
||||
|
||||
ApplicationName = "neofs-s3-gate"
|
||||
)
|
||||
|
||||
var (
|
||||
Build = "now"
|
||||
|
|
Loading…
Reference in a new issue