2022-10-15 14:28:03 +00:00
|
|
|
package bootstrap
|
2021-04-20 21:31:37 +00:00
|
|
|
|
|
|
|
import (
|
2022-10-29 19:11:40 +00:00
|
|
|
"cryptic-net/nebula"
|
2021-04-20 21:31:37 +00:00
|
|
|
"fmt"
|
2022-10-29 19:11:40 +00:00
|
|
|
"net"
|
2022-10-15 16:41:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// NebulaHost describes the nebula configuration of a Host which is relevant for
|
|
|
|
// other hosts to know.
|
2021-04-20 21:31:37 +00:00
|
|
|
type NebulaHost struct {
|
2022-11-05 12:57:21 +00:00
|
|
|
CertPEM string `yaml:"cert_pem"`
|
2021-04-20 21:31:37 +00:00
|
|
|
PublicAddr string `yaml:"public_addr,omitempty"`
|
|
|
|
}
|
|
|
|
|
2022-10-15 16:41:07 +00:00
|
|
|
// GarageHost describes a single garage instance in the GarageHost.
|
2021-04-20 21:31:37 +00:00
|
|
|
type GarageHostInstance struct {
|
2022-10-28 22:09:18 +00:00
|
|
|
ID string `yaml:"id"`
|
|
|
|
RPCPort int `yaml:"rpc_port"`
|
|
|
|
S3APIPort int `yaml:"s3_api_port"`
|
2021-04-20 21:31:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-15 16:41:07 +00:00
|
|
|
// GarageHost describes the garage configuration of a Host which is relevant for
|
|
|
|
// other hosts to know.
|
2021-04-20 21:31:37 +00:00
|
|
|
type GarageHost struct {
|
|
|
|
Instances []GarageHostInstance `yaml:"instances"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// Host consolidates all information about a single host from the bootstrap
|
|
|
|
// file.
|
|
|
|
type Host struct {
|
2022-10-15 16:41:07 +00:00
|
|
|
Name string `yaml:"name"`
|
|
|
|
Nebula NebulaHost `yaml:"nebula"`
|
|
|
|
Garage *GarageHost `yaml:"garage,omitempty"`
|
2021-04-20 21:31:37 +00:00
|
|
|
}
|
|
|
|
|
2022-10-29 19:11:40 +00:00
|
|
|
// IP returns the IP address encoded in the Host's nebula certificate, or panics
|
|
|
|
// if there is an error.
|
|
|
|
func (h Host) IP() net.IP {
|
|
|
|
|
|
|
|
ip, err := nebula.IPFromHostCertPEM(h.Nebula.CertPEM)
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("could not parse IP out of cert for host %q: %w", h.Name, err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return ip
|
|
|
|
}
|