2021-06-02 12:20:05 +00:00
|
|
|
package apiclientconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
subsection = "apiclient"
|
|
|
|
|
|
|
|
// DialTimeoutDefault is a default dial timeout of NeoFS API client connection.
|
|
|
|
DialTimeoutDefault = 5 * time.Second
|
2022-09-06 15:23:59 +00:00
|
|
|
|
|
|
|
// StreamTimeoutDefault is a default timeout of NeoFS API streaming operation.
|
|
|
|
StreamTimeoutDefault = 15 * time.Second
|
2021-06-02 12:20:05 +00:00
|
|
|
)
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// DialTimeout returns the value of "dial_timeout" config parameter
|
2021-06-02 12:20:05 +00:00
|
|
|
// from "apiclient" section.
|
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns DialTimeoutDefault if the value is not positive duration.
|
2021-06-02 12:20:05 +00:00
|
|
|
func DialTimeout(c *config.Config) time.Duration {
|
|
|
|
v := config.DurationSafe(c.Sub(subsection), "dial_timeout")
|
2021-06-02 12:44:41 +00:00
|
|
|
if v > 0 {
|
2021-06-02 12:20:05 +00:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
return DialTimeoutDefault
|
|
|
|
}
|
2022-09-06 15:23:59 +00:00
|
|
|
|
|
|
|
// StreamTimeout returns the value of "stream_timeout" config parameter
|
|
|
|
// from "apiclient" section.
|
|
|
|
//
|
|
|
|
// Returns DialTimeoutDefault if the value is not positive duration.
|
|
|
|
func StreamTimeout(c *config.Config) time.Duration {
|
|
|
|
v := config.DurationSafe(c.Sub(subsection), "stream_timeout")
|
|
|
|
if v > 0 {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
return StreamTimeoutDefault
|
|
|
|
}
|
2022-09-26 12:34:01 +00:00
|
|
|
|
|
|
|
// AllowExternal returns the value of "allow_external" config parameter
|
|
|
|
// from "apiclient" section.
|
|
|
|
//
|
|
|
|
// Returns false if the value is missing or invalid.
|
|
|
|
func AllowExternal(c *config.Config) bool {
|
|
|
|
return config.BoolSafe(c.Sub(subsection), "allow_external")
|
|
|
|
}
|