90 lines
2.2 KiB
Go
90 lines
2.2 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"`
|
|
Volumes []volumeConfig `json:"volumes"`
|
|
StackScript stackScriptConfig `json:"stackScript"`
|
|
}
|
|
|
|
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"`
|
|
Inbound firewallRuleSet `json:"inbound"`
|
|
}
|
|
|
|
type firewallRuleSet struct {
|
|
Allow []firewallRule `json:"allow"`
|
|
Deny []firewallRule `json:"deny"`
|
|
}
|
|
|
|
type firewallRule struct {
|
|
Label string `json:"label"`
|
|
Protocol string `json:"protocol"`
|
|
Ports string `json:"ports"`
|
|
SourceIpv4s []string `json:"sourceIpv4s"`
|
|
SourceIpv6s []string `json:"sourceIpv6s"`
|
|
}
|
|
|
|
type instanceConfig struct {
|
|
Label string `json:"label"`
|
|
Type string `json:"type"`
|
|
SwapSize int `json:"swapSize"`
|
|
BackupsEnabled bool `json:"backupsEnabled"`
|
|
PrivateIp bool `json:"privateIp"`
|
|
WatchdogEnabled bool `json:"watchdogEnabled"`
|
|
}
|
|
|
|
type volumeConfig struct {
|
|
Label string `json:"label"`
|
|
Size int32 `json:"size"`
|
|
}
|
|
|
|
type stackScriptConfig struct {
|
|
Label string `json:"label"`
|
|
Description string `json:"description"`
|
|
Public bool `json:"public"`
|
|
SharedGroupGid int32 `json:"sharedGroupGid"`
|
|
AuthorizedKey string `json:"authorizedKey"`
|
|
}
|
|
|
|
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
|
|
}
|