2022-02-06 02:22:23 +04:00
|
|
|
package configuration
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Configuration holds a list of process names to be tracked and a listen address.
|
|
|
|
type Configuration struct {
|
|
|
|
ListenOn string `yaml:"listen_on"`
|
2022-02-07 04:47:26 +04:00
|
|
|
HashSalt string `yaml:"hash_salt"`
|
2022-02-07 20:34:04 +04:00
|
|
|
User string `yaml:"user"`
|
|
|
|
Log struct {
|
2022-02-07 21:24:25 +04:00
|
|
|
Error string `yaml:"error"`
|
|
|
|
Upload string `yaml:"upload"`
|
|
|
|
Download string `yaml:"download"`
|
2022-07-01 03:27:14 +04:00
|
|
|
Delete string `yaml:"delete"`
|
2022-03-20 18:19:59 +04:00
|
|
|
Clean string `yaml:"clean"`
|
|
|
|
CleanError string `yaml:"clean_error"`
|
2022-02-07 20:34:04 +04:00
|
|
|
} `yaml:"log"`
|
|
|
|
Uploads struct {
|
2022-02-06 02:22:23 +04:00
|
|
|
Directory string `yaml:"directory"`
|
|
|
|
Limits struct {
|
2022-02-07 04:47:26 +04:00
|
|
|
FileSize int64 `yaml:"file_size"`
|
|
|
|
KeepForHours int `yaml:"keep_for_hours"`
|
|
|
|
Storage int64 `yaml:"storage"`
|
2022-02-06 02:22:23 +04:00
|
|
|
} `yaml:"limits"`
|
|
|
|
} `yaml:"uploads"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func LoadConfiguration(path string) (*Configuration, error) {
|
2022-02-06 03:01:16 +04:00
|
|
|
configFile, err := os.Open(path)
|
2022-02-06 02:22:23 +04:00
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "failed to open configuration file")
|
|
|
|
}
|
2022-02-07 18:21:40 +04:00
|
|
|
defer configFile.Close()
|
2022-02-06 02:22:23 +04:00
|
|
|
|
|
|
|
config := &Configuration{}
|
|
|
|
|
2022-02-06 03:01:16 +04:00
|
|
|
if err := yaml.NewDecoder(configFile).Decode(config); err != nil {
|
2022-02-07 18:21:40 +04:00
|
|
|
return nil, errors.Wrap(err, "failed to parse configuration file")
|
2022-02-06 02:22:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|
|
|
|
|
2022-02-07 18:21:40 +04:00
|
|
|
// SplitNetworkAddress splits ListenOn option and returns as two strings
|
|
|
|
// network type (e.g. tcp, unix, udp) and address:port or /path/to/prog.socket
|
|
|
|
// to listen on.
|
2022-02-07 22:08:02 +04:00
|
|
|
func (c *Configuration) SplitNetworkAddress() (string, string) {
|
2022-02-06 02:22:23 +04:00
|
|
|
s := strings.Split(c.ListenOn, " ")
|
2022-02-07 22:08:02 +04:00
|
|
|
return s[0], s[1]
|
2022-02-06 02:22:23 +04:00
|
|
|
}
|