platform/config.go
Dan Anglin f5c0c88c2e
refactor: recreate Pulumi code base.
The Pulumi stack was recreated and the codebase has been refactored. The
platform's configuration is now defined in another repository and
integrated into this project via a sub module. For now we've imported the
domain and the domain records.
2023-02-22 20:12:39 +00:00

74 lines
1.6 KiB
Go

package main
import (
"encoding/json"
"fmt"
"os"
)
type platform struct {
Domain domainConfig `json:"domain"`
Firewall firewallConfig `json:"firewall"`
Instance instanceConfig `json:"instance"`
Region string `json:"region"`
Tags []string `json:"tags"`
TempIP string `json:"tempIP"`
Volumes []volumeConfig `json:"volumes"`
}
type domainConfig struct {
Description string `json:"description"`
Name string `json:"name"`
Email string `json:"email"`
Records []domainRecord `json:"records"`
Type string `json:"type"`
}
type domainRecord struct {
Label string `json:"label"`
Name string `json:"name"`
Type string `json:"type"`
TtlSec int `json:"ttlSec"`
}
type firewallConfig struct {
Label string `json:"label"`
Allow []firewallRule `json:"allow"`
Deny []firewallRule `json:"deny"`
}
type firewallRule struct {
Label string `json:"label"`
Protocol string `json:"protocol"`
Ports string `json:"ports"`
}
type instanceConfig struct {
Label string `json:"label"`
InstanceType string `json:"instanceType"`
SwapSize int `json:"swapSize"`
BackupsEnabled bool `json:"backupsEnabled"`
}
type volumeConfig struct {
Label string `json:"label"`
Size int32 `json:"size"`
}
func newConfig(path string) (*platform, error) {
f, err := os.Open(path)
if err != nil {
return nil, fmt.Errorf("unable to open the file; %w", err)
}
defer f.Close()
decoder := json.NewDecoder(f)
var p platform
if err = decoder.Decode(&p); err != nil {
return nil, fmt.Errorf("unable to decode JSON data; %w", err)
}
return &p, nil
}