99 lines
2.5 KiB
Go
99 lines
2.5 KiB
Go
package daemon
|
|
|
|
import "strconv"
|
|
|
|
type ConfigFirewall struct {
|
|
Conntrack ConfigConntrack `yaml:"conntrack"`
|
|
Outbound []ConfigFirewallRule `yaml:"outbound"`
|
|
Inbound []ConfigFirewallRule `yaml:"inbound"`
|
|
}
|
|
|
|
type ConfigConntrack struct {
|
|
TCPTimeout string `yaml:"tcp_timeout"`
|
|
UDPTimeout string `yaml:"udp_timeout"`
|
|
DefaultTimeout string `yaml:"default_timeout"`
|
|
MaxConnections int `yaml:"max_connections"`
|
|
}
|
|
|
|
type ConfigFirewallRule struct {
|
|
Port string `yaml:"port,omitempty"`
|
|
Code string `yaml:"code,omitempty"`
|
|
Proto string `yaml:"proto,omitempty"`
|
|
Host string `yaml:"host,omitempty"`
|
|
Group string `yaml:"group,omitempty"`
|
|
Groups []string `yaml:"groups,omitempty"`
|
|
CIDR string `yaml:"cidr,omitempty"`
|
|
CASha string `yaml:"ca_sha,omitempty"`
|
|
CAName string `yaml:"ca_name,omitempty"`
|
|
}
|
|
|
|
// ConfigStorageAllocation describes the structure of each storage allocation
|
|
// within the daemon config file.
|
|
type ConfigStorageAllocation struct {
|
|
DataPath string `yaml:"data_path"`
|
|
MetaPath string `yaml:"meta_path"`
|
|
Capacity int `yaml:"capacity"`
|
|
S3APIPort int `yaml:"s3_api_port"`
|
|
RPCPort int `yaml:"rpc_port"`
|
|
AdminPort int `yaml:"admin_port"`
|
|
|
|
// Zone is a secret option which makes it easier to test garage bugs, but
|
|
// which we don't want users to otherwise know about.
|
|
Zone string `yaml:"zone"`
|
|
}
|
|
|
|
// Config describes the structure of the daemon config file.
|
|
type Config struct {
|
|
DNS struct {
|
|
Resolvers []string `yaml:"resolvers"`
|
|
} `yaml:"dns"`
|
|
VPN struct {
|
|
PublicAddr string `yaml:"public_addr"`
|
|
Firewall ConfigFirewall `yaml:"firewall"`
|
|
} `yaml:"vpn"`
|
|
Storage struct {
|
|
Allocations []ConfigStorageAllocation
|
|
} `yaml:"storage"`
|
|
}
|
|
|
|
func (c *Config) fillDefaults() {
|
|
|
|
var firewallGarageInbound []ConfigFirewallRule
|
|
|
|
for i := range c.Storage.Allocations {
|
|
|
|
if c.Storage.Allocations[i].RPCPort == 0 {
|
|
c.Storage.Allocations[i].RPCPort = 3900 + (i * 10)
|
|
}
|
|
|
|
if c.Storage.Allocations[i].S3APIPort == 0 {
|
|
c.Storage.Allocations[i].S3APIPort = 3901 + (i * 10)
|
|
}
|
|
|
|
if c.Storage.Allocations[i].AdminPort == 0 {
|
|
c.Storage.Allocations[i].AdminPort = 3902 + (i * 10)
|
|
}
|
|
|
|
alloc := c.Storage.Allocations[i]
|
|
|
|
firewallGarageInbound = append(
|
|
firewallGarageInbound,
|
|
ConfigFirewallRule{
|
|
Port: strconv.Itoa(alloc.S3APIPort),
|
|
Proto: "tcp",
|
|
Host: "any",
|
|
},
|
|
ConfigFirewallRule{
|
|
Port: strconv.Itoa(alloc.RPCPort),
|
|
Proto: "tcp",
|
|
Host: "any",
|
|
},
|
|
)
|
|
}
|
|
|
|
c.VPN.Firewall.Inbound = append(
|
|
c.VPN.Firewall.Inbound,
|
|
firewallGarageInbound...,
|
|
)
|
|
}
|