-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmodel.go
More file actions
315 lines (255 loc) · 8.27 KB
/
model.go
File metadata and controls
315 lines (255 loc) · 8.27 KB
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
package mockapi
// TODO unify these models with the 'api' package, and/or use OpenAPI or similar to generate them
import (
"strings"
"time"
)
type HALLink struct {
HREF string `json:"href"`
}
type HalLinks map[string]HALLink
// MakeHALLinks helps make a list of HAL links out of arguments in the format name=path.
func MakeHALLinks(nameAndPath ...string) HalLinks {
links := make(HalLinks, len(nameAndPath))
for _, p := range nameAndPath {
parts := strings.SplitN(p, "=", 2)
links[parts[0]] = HALLink{parts[1]}
}
return links
}
type Subscription struct {
ID string `json:"id"`
Links HalLinks `json:"_links"`
ProjectID string `json:"project_id"`
ProjectRegion string `json:"project_region"`
ProjectTitle string `json:"project_title"`
Status string `json:"status"`
ProjectUI string `json:"project_ui"`
}
type CanCreateRequiredAction struct {
Action string `json:"action"`
Type string `json:"type"`
}
type CanCreateResponse struct {
CanCreate bool `json:"can_create"`
Message string `json:"message"`
RequiredAction *CanCreateRequiredAction `json:"required_action"`
}
type ProjectRepository struct {
URL string `json:"url"`
}
type Project struct {
ID string `json:"id"`
Title string `json:"title"`
Region string `json:"region"`
Organization string `json:"organization"`
Vendor string `json:"vendor"`
Repository ProjectRepository `json:"repository"`
DefaultBranch string `json:"default_branch"`
Links HalLinks `json:"_links"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Subscription ProjectSubscriptionInfo `json:"subscription,omitempty"`
SubscriptionID string `json:"-"`
}
type ProjectSubscriptionInfo struct {
LicenseURI string `json:"license_uri,omitempty"`
Plan string `json:"plan,omitempty"`
Environments int `json:"environments,omitempty"`
Storage int `json:"storage,omitempty"`
IncludedUsers int `json:"included_users,omitempty"`
UserLicenses int `json:"user_licenses,omitempty"`
ManagementURI string `json:"subscription_management_uri,omitempty"`
Restricted bool `json:"restricted,omitempty"`
Suspended bool `json:"suspended,omitempty"`
}
func (p *Project) AsRef() *ProjectRef {
return &ProjectRef{
ID: p.ID,
Region: p.Region,
Title: p.Title,
Status: "active",
OrganizationID: p.Organization,
SubscriptionID: p.SubscriptionID,
Vendor: p.Vendor,
CreatedAt: p.CreatedAt,
UpdatedAt: p.UpdatedAt,
}
}
type Environment struct {
ID string `json:"id"`
Name string `json:"name"`
MachineName string `json:"machine_name"`
Title string `json:"title"`
Type string `json:"type"`
Status string `json:"status"`
Parent any `json:"parent"`
Project string `json:"project"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Links HalLinks `json:"_links"`
currentDeployment *Deployment
settings map[string]any
}
func (e *Environment) SetCurrentDeployment(d *Deployment) {
e.currentDeployment = d
}
func (e *Environment) SetSetting(key string, val any) {
if e.settings == nil {
e.settings = make(map[string]any)
}
e.settings[key] = val
}
type Mount struct {
Source string `json:"source"`
SourcePath string `json:"source_path"`
}
type App struct {
Name string `json:"name"`
Type string `json:"type"`
Size string `json:"size"`
Disk int `json:"disk"`
Mounts map[string]Mount `json:"mounts"`
}
type Commands struct {
Start string `json:"start"`
}
type WorkerInfo struct {
Commands Commands `json:"commands"`
}
type Worker struct {
App
Worker WorkerInfo `json:"worker"`
}
type Deployment struct {
WebApps map[string]App `json:"webapps"`
Services map[string]App `json:"services"`
Workers map[string]Worker `json:"workers"`
Routes map[string]any `json:"routes"`
Links HalLinks `json:"_links"`
}
type Org struct {
ID string `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Label string `json:"label"`
Owner string `json:"owner_id"`
Capabilities []string `json:"capabilities"`
Links HalLinks `json:"_links"`
}
func (o *Org) AsRef() *OrgRef {
return &OrgRef{
ID: o.ID,
Type: o.Type,
Name: o.Name,
Label: o.Label,
Owner: o.Owner,
}
}
type OrgRef struct {
ID string `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Label string `json:"label"`
Owner string `json:"owner_id"`
}
type ProjectUserGrant struct {
ProjectID string `json:"project_id"`
OrganizationID string `json:"organization_id"`
UserID string `json:"user_id"`
Permissions []string `json:"permissions"`
GrantedAt time.Time `json:"granted_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type UserGrant struct {
ResourceID string `json:"resource_id"`
ResourceType string `json:"resource_type"`
OrganizationID string `json:"organization_id"`
UserID string `json:"user_id"`
Permissions []string `json:"permissions"`
GrantedAt time.Time `json:"granted_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type UserRef struct {
ID string `json:"id"`
Email string `json:"email"`
Username string `json:"username"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
type ProjectRef struct {
ID string `json:"id"`
Region string `json:"region"`
Title string `json:"title"`
Status string `json:"status"`
OrganizationID string `json:"organization_id"`
SubscriptionID string `json:"subscription_id"`
Vendor string `json:"vendor"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type User struct {
ID string `json:"id"`
Deactivated bool `json:"deactivated"`
Namespace string `json:"namespace"`
Username string `json:"username"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
Email string `json:"email"`
EmailVerified bool `json:"email_verified"`
Picture string `json:"picture"`
Country string `json:"country"`
PhoneNumberVerified bool `json:"phone_number_verified"`
MFAEnabled bool `json:"mfa_enabled"`
SSOEnabled bool `json:"sso_enabled"`
ConsentMethod string `json:"consent_method"`
ConsentedAt time.Time `json:"consented_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type Backup struct {
ID string `json:"id"`
EnvironmentID string `json:"environment"`
Status string `json:"status"`
Safe bool `json:"safe"`
Restorable bool `json:"restorable"`
Automated bool `json:"automated"`
CommitID string `json:"commit_id"`
ExpiresAt time.Time `json:"expires_at"`
Links HalLinks `json:"_links"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type Activity struct {
ID string `json:"id"`
Type string `json:"type"`
State string `json:"state"`
Result string `json:"result"`
CompletionPercent int `json:"completion_percent"`
CompletedAt time.Time `json:"completed_at"`
StartedAt time.Time `json:"started_at"`
Project string `json:"project"`
Environments []string `json:"environments"`
Description string `json:"description"`
Text string `json:"text"`
Payload any `json:"payload"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type Variable struct {
Name string `json:"name"`
Value string `json:"value,omitempty"`
IsSensitive bool `json:"is_sensitive"`
VisibleBuild bool `json:"visible_build"`
VisibleRuntime bool `json:"visible_runtime"`
ApplicationScope []string `json:"application_scope,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Links HalLinks `json:"_links"`
}
type EnvLevelVariable struct {
Variable
IsEnabled bool `json:"is_enabled"`
Inherited bool `json:"inherited"`
IsInheritable bool `json:"is_inheritable"`
}