isle/go/admin/admin.go

45 lines
1.2 KiB
Go
Raw Normal View History

2022-11-02 13:02:21 +00:00
// Package admin deals with the parsing and creation of admin.yml files.
package admin
import (
"isle/garage"
"isle/nebula"
"io"
"gopkg.in/yaml.v3"
)
2022-10-16 15:05:05 +00:00
// CreationParams are general parameters used when creating a new network. These
// are available to all hosts within the network via their bootstrap files.
type CreationParams struct {
ID string `yaml:"id"`
2022-11-05 11:34:49 +00:00
Name string `yaml:"name"`
Domain string `yaml:"domain"`
2022-10-16 15:05:05 +00:00
}
2022-11-02 13:02:21 +00:00
// Admin is used for accessing all information contained within an admin.yml.
type Admin struct {
2022-11-02 13:02:21 +00:00
CreationParams CreationParams `yaml:"creation_params"`
2022-11-02 13:02:21 +00:00
Nebula struct {
CACredentials nebula.CACredentials `yaml:"ca_credentials"`
} `yaml:"nebula"`
2022-11-02 13:02:21 +00:00
Garage struct {
RPCSecret string `yaml:"rpc_secret"`
GlobalBucketS3APICredentials garage.S3APICredentials `yaml:"global_bucket_s3_api_credentials"`
} `yaml:"garage"`
}
2022-11-02 13:02:21 +00:00
// FromReader reads an admin.yml from the given io.Reader.
func FromReader(r io.Reader) (Admin, error) {
2022-11-02 13:02:21 +00:00
var a Admin
err := yaml.NewDecoder(r).Decode(&a)
return a, err
}
2022-11-02 13:02:21 +00:00
// WriteTo writes the Admin as an admin.yml to the given io.Writer.
func (a Admin) WriteTo(into io.Writer) error {
2022-11-02 13:02:21 +00:00
return yaml.NewEncoder(into).Encode(a)
}