2021-06-01 18:22:41 +00:00
|
|
|
package metabaseconfig
|
|
|
|
|
|
|
|
import (
|
2021-06-28 14:01:31 +00:00
|
|
|
"io/fs"
|
2021-06-01 18:22:41 +00:00
|
|
|
|
|
|
|
"github.com/nspcc-dev/neofs-node/cmd/neofs-node/config"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Config is a wrapper over the config section
|
|
|
|
// which provides access to Metabase configurations.
|
|
|
|
type Config config.Config
|
|
|
|
|
|
|
|
// config defaults
|
|
|
|
const (
|
|
|
|
// PermDefault is a default permission bits for metabase file.
|
2021-07-29 13:37:23 +00:00
|
|
|
PermDefault = 0660
|
2021-06-01 18:22:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// From wraps config section into Config.
|
|
|
|
func From(c *config.Config) *Config {
|
|
|
|
return (*Config)(c)
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Path returns the value of "path" config parameter.
|
2021-06-01 18:22:41 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Panics if the value is not a non-empty string.
|
2021-06-01 18:22:41 +00:00
|
|
|
func (x *Config) Path() string {
|
|
|
|
p := config.String(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"path",
|
|
|
|
)
|
|
|
|
|
|
|
|
if p == "" {
|
|
|
|
panic("metabase path not set")
|
|
|
|
}
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
2022-04-21 11:28:05 +00:00
|
|
|
// Perm returns the value of "perm" config parameter as a fs.FileMode.
|
2021-06-01 18:22:41 +00:00
|
|
|
//
|
2022-04-21 11:28:05 +00:00
|
|
|
// Returns PermDefault if the value is not a positive number.
|
2021-06-28 14:01:31 +00:00
|
|
|
func (x *Config) Perm() fs.FileMode {
|
2021-06-01 18:22:41 +00:00
|
|
|
p := config.UintSafe(
|
|
|
|
(*config.Config)(x),
|
|
|
|
"perm",
|
|
|
|
)
|
|
|
|
|
|
|
|
if p == 0 {
|
|
|
|
p = PermDefault
|
|
|
|
}
|
|
|
|
|
2021-06-28 14:01:31 +00:00
|
|
|
return fs.FileMode(p)
|
2021-06-01 18:22:41 +00:00
|
|
|
}
|