-
Notifications
You must be signed in to change notification settings - Fork 12
/
schema.go
133 lines (115 loc) · 2.85 KB
/
schema.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package schema
import (
"context"
"fmt"
)
// Provider is an interface implemented by any cloud service provider.
//
// It provides the bare minimum of methods to allow complete overview of user
// data.
type Provider interface {
// Name returns the name of the provider
Name() string
// Resources returns the provider for an resource deployment source.
Resources(ctx context.Context) (Resources, error)
UserManagement(action, uname, pwd string)
BucketDump(action, bucketname string)
EventDump(sourceIp string)
}
// NewResources creates a new resources structure
func NewResources() Resources {
return Resources{
Hosts: make([]Host, 0),
Storages: make([]Storage, 0),
Users: make([]User, 0),
Databases: make([]Database, 0),
Domains: make([]Domain, 0),
}
}
type Resources struct {
Provider string
Hosts []Host
Storages []Storage
Users []User
Databases []Database
Domains []Domain
Sms Sms
}
type Host struct {
PublicIPv4 string `table:"Public IP"`
PrivateIpv4 string `table:"Private IP"`
DNSName string `table:"DNS Name"`
Public bool `table:"Public"`
Region string `table:"Region"`
}
type Storage struct {
BucketName string `table:"Bucket"`
AccountName string `table:"Storage Account"`
Region string `table:"Region"`
}
type User struct {
UserName string `table:"User"`
UserId string `table:"ID"`
EnableLogin bool `table:"Enable Login"`
LastLogin string `table:"Last Login"`
CreateTime string `table:"Creat Time"`
}
type Database struct {
DBInstanceId string `table:"ID"`
Engine string `table:"Engine"`
EngineVersion string `table:"Version"`
Region string `table:"Region"`
Address string `table:"Address"`
}
type Domain struct {
DomainName string
Records []Record
}
type Record struct {
RR string
Type string
Value string
Status string
}
type Sms struct {
Signs []SmsSign
Templates []SmsTemplate
DailySize int64
}
type SmsSign struct {
Name string `table:"Name"`
Type string `table:"Type"`
Status string `table:"Status"`
}
type SmsTemplate struct {
Name string `table:"Name"`
Status string `table:"Status"`
Content string `table:"Content"`
}
type Event struct {
Name string
Affected string
API string
Status string
SourceIp string `table:"Source IP"`
AccessKey string
Time string
}
// ErrNoSuchKey means no such key exists in metadata.
type ErrNoSuchKey struct {
Name string
}
// Error returns the value of the metadata key
func (e *ErrNoSuchKey) Error() string {
return fmt.Sprintf("no such key: %s", e.Name)
}
// Options contains configuration options for a provider
type Options map[string]string
// GetMetadata returns the value for a key if it exists.
func (o Options) GetMetadata(key string) (string, bool) {
data, ok := o[key]
if !ok || data == "" {
return "", false
}
return data, true
}