2021-06-02 15:20:05 +03:00
|
|
|
package apiclientconfig
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2022-12-23 20:35:35 +03:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/cmd/frostfs-node/config"
|
2021-06-02 15:20:05 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
subsection = "apiclient"
|
|
|
|
|
2023-02-03 17:59:15 +03:00
|
|
|
// DialTimeoutDefault is a default dial timeout of FrostFS API client connection.
|
2021-06-02 15:20:05 +03:00
|
|
|
DialTimeoutDefault = 5 * time.Second
|
2022-09-06 18:23:59 +03:00
|
|
|
|
2023-02-03 17:59:15 +03:00
|
|
|
// StreamTimeoutDefault is a default timeout of FrostFS API streaming operation.
|
2022-09-06 18:23:59 +03:00
|
|
|
StreamTimeoutDefault = 15 * time.Second
|
2021-06-02 15:20:05 +03:00
|
|
|
)
|
|
|
|
|
2022-04-21 14:28:05 +03:00
|
|
|
// DialTimeout returns the value of "dial_timeout" config parameter
|
2021-06-02 15:20:05 +03:00
|
|
|
// from "apiclient" section.
|
|
|
|
//
|
2022-04-21 14:28:05 +03:00
|
|
|
// Returns DialTimeoutDefault if the value is not positive duration.
|
2021-06-02 15:20:05 +03:00
|
|
|
func DialTimeout(c *config.Config) time.Duration {
|
|
|
|
v := config.DurationSafe(c.Sub(subsection), "dial_timeout")
|
2021-06-02 15:44:41 +03:00
|
|
|
if v > 0 {
|
2021-06-02 15:20:05 +03:00
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
return DialTimeoutDefault
|
|
|
|
}
|
2022-09-06 18:23:59 +03: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 15:34:01 +03:00
|
|
|
|
2022-12-19 18:03:48 +03:00
|
|
|
// ReconnectTimeout returns the value of "reconnect_timeout" config parameter
|
|
|
|
// from "apiclient" section.
|
|
|
|
//
|
|
|
|
// Returns 0 if the value is not positive duration.
|
|
|
|
func ReconnectTimeout(c *config.Config) time.Duration {
|
|
|
|
v := config.DurationSafe(c.Sub(subsection), "reconnect_timeout")
|
|
|
|
if v > 0 {
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2022-09-26 15:34:01 +03: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")
|
|
|
|
}
|