forked from a2call/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
451 lines (394 loc) · 14.2 KB
/
models.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
package models
import (
"github.com/jault3/mow.cli"
)
// AssociatedEnvV1 holds information about an associated environment
type AssociatedEnvV1 struct {
EnvironmentID string `json:"environmentId"`
ServiceID string `json:"serviceId"`
Directory string `json:"dir"`
Name string `json:"name"`
Pod string `json:"pod"`
OrgID string `json:"organizationId"`
}
// AssociatedEnvV2 holds information about an associated environment
type AssociatedEnvV2 struct {
EnvironmentID string `json:"environmentId"`
Name string `json:"name"`
Pod string `json:"pod"`
OrgID string `json:"organizationId"`
}
type Cert struct {
Name string `json:"name"`
PubKey string `json:"sslCertFile"`
PrivKey string `json:"sslPKFile"`
Service string `json:"service,omitempty"`
PubKeyID int `json:"sslCertFileId,omitempty"`
PrivKeyID int `json:"sslPKFileId,omitempty"`
Restricted bool `json:"restricted,omitempty"`
LetsEncrypt LetsEncryptStatus `json:"letsEncrypt,omitempty"`
}
type Command struct {
Name string
ShortHelp string
LongHelp string
CmdFunc func(settings *Settings) func(cmd *cli.Cmd)
}
// ContentDigest contains hash data for an image
type ContentDigest struct {
HashType string
Hash string
Size int64
}
// ConsoleCredentials hold the keys necessary for connecting to a console service
type ConsoleCredentials struct {
URL string `json:"url"`
Token string `json:"token"`
}
type CPUUsage struct {
JobID string `json:"job"`
CorePercent float64 `json:"core_percent"`
TS int `json:"ts"`
}
// DeployKey is an ssh key belonging to an environment's code service
type DeployKey struct {
Name string `json:"name"`
Key string `json:"value"`
Type string `json:"type"`
}
// EncryptionStore holds the values for encryption on backup/import jobs
type EncryptionStore struct {
Key string `json:"key"`
KeyLogs string `json:"keyLogs"`
KeyInternalLogs string `json:"keyInternalLogs"`
IV string `json:"iv"`
}
// Environment environment
type Environment struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Pod string `json:"pod,omitempty"`
Namespace string `json:"namespace,omitempty"`
OrgID string `json:"organizationId"`
}
// Error is a wrapper around an array of errors from the API
type Error struct {
Title string `json:"title"`
Description string `json:"description"`
Code int `json:"code"`
}
// ACL support
type GroupWrapper struct {
Groups *[]Group `json:"groups"`
}
type Group struct {
Name string `json:"name"`
Acls []string `json:"acls"`
Protected bool `json:"protected"`
Members *[]GroupMember `json:"members"`
}
type GroupMember struct {
ID string `json:"id"`
Email string `json:"email"`
}
// Hits contain arrays of log data
type Hits struct {
Total int64 `json:"total"`
MaxScore float64 `json:"max_score"`
Hits *[]LogHits `json:"hits"`
}
type HTTPManager interface {
GetHeaders(sessionToken, version, pod, userID string) map[string][]string
ConvertResp(b []byte, statusCode int, s interface{}) error
ConvertError(b []byte, statuseCode int) (*Error, error)
Get(body []byte, url string, headers map[string][]string) ([]byte, int, error)
Post(body []byte, url string, headers map[string][]string) ([]byte, int, error)
PostFile(filepath string, url string, headers map[string][]string) ([]byte, int, error)
PutFile(filepath string, url string, headers map[string][]string) ([]byte, int, error)
Put(body []byte, url string, headers map[string][]string) ([]byte, int, error)
Delete(body []byte, url string, headers map[string][]string) ([]byte, int, error)
}
// Image contains data about an image
type Image struct {
Name string
Tag string
Digest *ContentDigest
}
// Invite represents an invitation to an organization
type Invite struct {
ID string `json:"id"`
OrgID string `json:"orgID"`
SenderID string `json:"senderID"`
RoleID int `json:"roleID"`
Email string `json:"email"`
Consumed bool `json:"consumed"`
Revoked bool `json:"revoked"`
}
// LetsEncryptStatus code
type LetsEncryptStatus int
const (
// NormalCert is a non-let's encrypt cert
NormalCert LetsEncryptStatus = iota
// Waiting verification and issuance
Waiting
// Valid certificate that has already been issued
Valid
)
func (l LetsEncryptStatus) String() string {
switch l {
case NormalCert:
return "This is not a Let's Encrypt certificate"
case Waiting:
return "Awaiting the certificate to be issued by Let's Encrypt"
case Valid:
return "Certificate successfully issued"
}
return ""
}
// LogHits contain ordering data for logs
type LogHits struct {
Index string `json:"_index"`
Type string `json:"_type"`
ID string `json:"_id"`
Score float64 `json:"_score"`
Fields map[string][]string `json:"fields"`
Source map[string]string `json:"_source"`
}
// Login is used for making an authentication request
type Login struct {
Identifier string `json:"identifier"`
Password string `json:"password"`
}
// Logs hold the log values from a successful LogQuery
type Logs struct {
Hits *Hits `json:"hits"`
}
type Maintenance struct {
UpstreamID string `json:"upstream"`
CreatedAt string `json:"createdAt"`
}
type MemoryUsage struct {
JobID string `json:"job"`
Total float64 `json:"total"`
AVG float64 `json:"ave"`
Max float64 `json:"max"`
Min float64 `json:"min"`
TS int `json:"ts"`
}
// Metrics holds all metrics data for an entire environment or a single service
type Metrics struct {
ServiceName string `json:"serviceName"`
ServiceType string `json:"serviceType"`
ServiceID string `json:"serviceId"`
ServiceLabel string `json:"serviceLabel"`
Size ServiceSize `json:"size"`
Data *MetricsData `json:"metrics"`
}
// MetricsData is a container for each type of metrics: network, memory, etc.
type MetricsData struct {
CPUUsage *[]CPUUsage `json:"cpu.usage"`
MemoryUsage *[]MemoryUsage `json:"memory.usage"`
NetworkUsage *[]NetworkUsage `json:"network.usage"`
}
type NetworkUsage struct {
JobID string `json:"job"`
RXDropped float64 `json:"rx_dropped"`
RXErrors float64 `json:"rx_errors"`
RXKB float64 `json:"rx_kb"`
RXPackets float64 `json:"rx_packets"`
TXDropped float64 `json:"tx_dropped"`
TXErrors float64 `json:"tx_errors"`
TXKB float64 `json:"tx_kb"`
TXPackets float64 `json:"tx_packets"`
TS int `json:"ts"`
}
type NotaryRepo struct {
RootTrustDir string
ImageName string
NotaryServer string
User *User
}
type Org struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
}
// OrgUser users who have access to an org
type OrgUser struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
RoleID int `json:"roleID"`
}
// Payload is the payload of a job
type Payload struct {
Environment map[string]string `json:"environment"`
}
// Pod is a pod returned from the pod router
type Pod struct {
Name string `json:"name"`
}
// Job job
type Job struct {
ID string `json:"id"`
Type string `json:"type"`
Status string `json:"status,omitempty"`
Backup *EncryptionStore `json:"backup,omitempty"`
Restore *EncryptionStore `json:"restore,omitempty"`
CreatedAt string `json:"created_at"`
MetricsData *[]MetricsData `json:"metrics"`
Spec *Spec `json:"spec"`
Target string `json:"target,omitempty"`
IsSnapshotBackup *bool `json:"isSnapshotBackup,omitempty"`
}
// PodWrapper pod wrapper
type PodWrapper struct {
Pods *[]Pod `json:"pods"`
}
type PostInvite struct {
Email string `json:"email"`
Role int `json:"role"`
LinkTemplate string `json:"linkTemplate"`
}
type Release struct {
Name string `json:"release,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
Notes string `json:"metadata,omitempty"`
}
// ReportedError is the standard error model sent back from the API
type ReportedError struct {
Code int `json:"id"`
Message string `json:"message"`
}
type Role struct {
ID int `json:"id"`
Name string `json:"name"`
}
// Service service
type Service struct {
ID string `json:"id,omitempty"`
Identifier string `json:"identifier,omitempty"`
DNS string `json:"internal_domain,omitempty"`
Type string `json:"type,omitempty"`
Label string `json:"label"`
Size ServiceSize `json:"size"`
Name string `json:"name"`
Environment string `json:"environment,omitempty"`
EnvVars map[string]string `json:"environmentVariables,omitempty"`
Source string `json:"source,omitempty"`
LBIP string `json:"load_balancer_ip,omitempty"`
Scale int `json:"scale,omitempty"`
WorkerScale int `json:"worker_scale,omitempty"`
ReleaseVersion string `json:"release_version,omitempty"`
Redeployable bool `json:"redeployable,omitempty"`
}
// ServiceFile is a file associated with a service
type ServiceFile struct {
ID int `json:"id"`
Contents string `json:"contents"`
GID int `json:"gid"`
Mode string `json:"mode"`
Name string `json:"name"`
UID int `json:"uid"`
EnableDownload bool `json:"enable_download"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// ServiceSize holds size information for a service
type ServiceSize struct {
RAM int `json:"ram"`
Storage int `json:"storage"`
Behavior string `json:"behavior,omitempty"`
Type string `json:"type,omitempty"`
CPU int `json:"cpu"`
}
type Settings SettingsV2
// SettingsV1 holds various settings for the current context. All items with
// `json:"-"` are never persisted to disk but used in memory for the current
// command.
type SettingsV1 struct {
AccountsHost string `json:"-"`
AuthHost string `json:"-"`
PaasHost string `json:"-"`
AuthHostVersion string `json:"-"`
PaasHostVersion string `json:"-"`
Version string `json:"-"`
HTTPManager HTTPManager `json:"-"`
Email string `json:"-"`
Password string `json:"-"`
EnvironmentID string `json:"-"` // the id of the environment used for the current command
ServiceID string `json:"-"` // the id of the service used for the current command
Pod string `json:"-"` // the pod used for the current command
EnvironmentName string `json:"-"` // the name of the environment used for the current command
OrgID string `json:"-"` // the org ID the chosen environment for this commands belongs to
PrivateKeyPath string `json:"private_key_path"`
SessionToken string `json:"token"`
UsersID string `json:"user_id"`
Environments map[string]AssociatedEnvV1 `json:"environments"`
Default string `json:"default"`
Pods *[]Pod `json:"pods"`
PodCheck int64 `json:"pod_check"`
}
// SettingsV2 holds various settings for the current context. All items with
// `json:"-"` are never persisted to disk but used in memory for the current
// command.
type SettingsV2 struct {
AccountsHost string `json:"-"`
AuthHost string `json:"-"`
PaasHost string `json:"-"`
AuthHostVersion string `json:"-"`
PaasHostVersion string `json:"-"`
Version string `json:"-"`
HTTPManager HTTPManager `json:"-"`
GivenEnvName string `json:"-"`
Email string `json:"-"`
Password string `json:"-"`
EnvironmentID string `json:"-"` // the id of the environment used for the current command
Pod string `json:"-"` // the pod used for the current command
EnvironmentName string `json:"-"` // the name of the environment used for the current command
OrgID string `json:"-"` // the org ID the chosen environment for this commands belongs to
PrivateKeyPath string `json:"private_key_path"`
SessionToken string `json:"token"`
UsersID string `json:"user_id"`
Environments map[string]AssociatedEnvV2 `json:"environments"`
Pods *[]Pod `json:"pods"`
PodCheck int64 `json:"pod_check"`
Format string `json:"format"`
}
type Site struct {
ID int `json:"id,omitempty"`
Name string `json:"name"`
Cert string `json:"cert"`
SiteFileID int `json:"siteFileId,omitempty"`
UpstreamService string `json:"upstreamService"`
Restricted bool `json:"restricted,omitempty"`
SiteValues map[string]interface{} `json:"site_values"`
}
// Spec is a job specification
type Spec struct {
Payload *Payload `json:"payload"`
}
// TempURL holds a URL for uploading or downloading files from a temporary URL
type TempURL struct {
URL string `json:"url"`
}
// User is an authenticated User
type User struct {
Email string `json:"email"`
SessionToken string `json:"sessionToken"`
UsersID string `json:"id"`
}
// UserKey is a public key belonging to a user
type UserKey struct {
Name string `json:"name"`
Key string `json:"key"`
}
type Volume struct {
ID int `json:"id"`
Type string `json:"type"`
Size int `json:"size"`
}
type Workers struct {
Limit int `json:"worker_limit,omitempty"`
Workers map[string]int `json:"workers"`
}