-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.go
118 lines (99 loc) · 2.05 KB
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package tinycloud
import (
"fmt"
"strings"
"github.com/jedib0t/go-pretty/v6/table"
)
type Profiles []*Profile
func (ps Profiles) String() string {
tw := table.NewWriter()
tw.AppendHeader(table.Row{"Name", "Description", "Cloud", "Active"})
for _, profile := range []*Profile(ps) {
tw.AppendRow(profile.toBasicRow())
}
tw.SetAutoIndex(false)
return tw.Render()
}
type Profile struct {
Name string
Description string
Active bool
Settings *CloudSettings
}
func (p *Profile) toBasicRow() table.Row {
cloud := p.Settings.ResolveCloudName()
active := ""
if p.Active {
active = "x"
}
return table.Row{p.Name, p.Description, cloud, active}
}
func (p *Profile) Valid() error {
if IsStrEmpty(p.Name) {
return fmt.Errorf("undefined name")
}
if p.Settings == nil {
return fmt.Errorf("cloud settigs not defiend")
}
return p.Settings.Valid()
}
type CloudSettings struct {
Aws *AwsSettings
// gcp
}
type AwsSettings struct {
AwsRegion string
AwsAccessKeyId string
AwsSeacretAccessKey string
}
func (s *AwsSettings) Valid() error {
if IsStrEmpty(s.AwsRegion) {
return fmt.Errorf("undefined aws region")
}
if IsStrEmpty(s.AwsAccessKeyId) {
return fmt.Errorf("undefined aws access key")
}
if IsStrEmpty(s.AwsSeacretAccessKey) {
return fmt.Errorf("undefined aws seacret access key")
}
return nil
}
func (s *CloudSettings) Valid() error {
name := s.ResolveCloudName()
switch name {
case "aws":
return s.Aws.Valid()
default:
return fmt.Errorf("unknown cloud '%s'", name)
}
}
func (s *CloudSettings) ResolveCloudName() string {
if s.Aws != nil {
return "aws"
}
return ""
}
var SupportedClouds []string = []string{
"aws",
"gcp",
}
func IsStrEmpty(str string) bool {
return len(strings.TrimSpace(str)) == 0
}
type RunRequest struct {
DockerImageId string
VmType string
DataOutPath string
}
type TaskDefinition struct {
DockerImageId string
DataOutPath string
DNSName string
SSHKey []byte
BucketName string
}
type Vm struct {
Id string
SSHKey []byte
DNSName string
}