-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathmodels.go
More file actions
530 lines (439 loc) · 14.5 KB
/
Copy pathmodels.go
File metadata and controls
530 lines (439 loc) · 14.5 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
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
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
package doppler
import (
"encoding/json"
"errors"
"sort"
"strings"
)
type ComputedSecret struct {
Name string
Value string
}
func ParseComputedSecrets(response []byte) ([]ComputedSecret, error) {
var result map[string]string
err := json.Unmarshal(response, &result)
if err != nil {
return nil, err
}
secrets := make([]ComputedSecret, 0)
for key, value := range result {
secret := ComputedSecret{Name: key, Value: value}
secrets = append(secrets, secret)
}
sort.Slice(secrets, func(i, j int) bool {
return secrets[i].Name < secrets[j].Name
})
return secrets, nil
}
type Secret struct {
Name string `json:"name"`
Value SecretValue `json:"value"`
}
type SecretValue struct {
Raw *string `json:"raw,omitempty"`
Computed *string `json:"computed,omitempty"`
RawVisibility *string `json:"rawVisibility,omitempty"`
ComputedVisibility *string `json:"computedVisibility,omitempty"`
RawValueType *ValueType `json:"rawValueType,omitempty"`
ComputedValueType *ValueType `json:"computedValueType,omitempty"`
}
func getSecretsId(project string, config string) string {
return strings.Join([]string{project, config}, ".")
}
func getSecretId(project string, config string, name string) string {
return strings.Join([]string{project, config, name}, ".")
}
func parseSecretId(id string) (project string, config string, name string, err error) {
tokens := strings.Split(id, ".")
if len(tokens) != 3 {
return "", "", "", errors.New("invalid secret ID")
}
return tokens[0], tokens[1], tokens[2], nil
}
type ChangeRequest struct {
OriginalName *string `json:"originalName,omitempty"`
OriginalValue *string `json:"originalValue,omitempty"`
OriginalVisibility *string `json:"originalVisibility,omitempty"`
Name string `json:"name"`
Value *string `json:"value"`
ShouldDelete bool `json:"shouldDelete"`
Visibility string `json:"visibility,omitempty"`
ValueType *ValueType `json:"valueType,omitempty"`
}
type ValueType struct {
Type string `json:"type"`
}
type Project struct {
Slug string `json:"slug"`
Name string `json:"name"`
Description string `json:"description"`
CreatedAt string `json:"created_at"`
}
type ProjectResponse struct {
Project Project `json:"project"`
}
type ProjectMemberRole struct {
Identifier string `json:"identifier"`
}
type ProjectMember struct {
Type string `json:"type"`
Slug string `json:"slug"`
Role ProjectMemberRole `json:"role"`
AccessAllEnvironments bool `json:"access_all_environment"`
Environments []string `json:"environments,omitempty"`
}
type ProjectMemberResponse struct {
Member ProjectMember `json:"member"`
}
func getProjectMemberId(project string, memberType string, memberSlug string) string {
return strings.Join([]string{project, memberType, memberSlug}, ".")
}
func parseProjectMemberId(id string) (project string, memberType string, memberSlug string, err error) {
tokens := strings.Split(id, ".")
if len(tokens) != 3 {
return "", "", "", errors.New("invalid project member ID")
}
return tokens[0], tokens[1], tokens[2], nil
}
type IntegrationMemberRole struct {
Identifier string `json:"identifier"`
}
type IntegrationMember struct {
Type string `json:"type"`
Slug string `json:"slug"`
Role IntegrationMemberRole `json:"role"`
}
type IntegrationMemberResponse struct {
Member IntegrationMember `json:"member"`
}
func getIntegrationMemberId(integration string, memberType string, memberSlug string) string {
return strings.Join([]string{integration, memberType, memberSlug}, ".")
}
func parseIntegrationMemberId(id string) (integration string, memberType string, memberSlug string, err error) {
tokens := strings.Split(id, ".")
if len(tokens) != 3 {
return "", "", "", errors.New("invalid integration member ID")
}
return tokens[0], tokens[1], tokens[2], nil
}
type IntegrationData = map[string]interface{}
type Integration struct {
Slug string `json:"slug"`
Name string `json:"name"`
Type string `json:"type"`
}
type IntegrationResponse struct {
Integration Integration `json:"integration"`
}
type SyncData = map[string]interface{}
type Sync struct {
Slug string `json:"slug"`
Project string `json:"project"`
Config string `json:"config"`
Integration string `json:"integration"`
}
type SyncResponse struct {
Sync Sync `json:"sync"`
}
type RotatedSecretParameters = map[string]interface{}
type RotatedSecretCredentials = []map[string]interface{}
type RotatedSecret struct {
Slug string `json:"slug"`
Project string `json:"project"`
Config string `json:"config"`
Integration Integration `json:"integration"`
RotationPeriodSec int `json:"rotation_period_sec"`
Name string `json:"name"`
}
type RotatedSecretResponse struct {
RotatedSecret RotatedSecret `json:"rotatedSecret"`
}
type ExternalIdResponse struct {
ExternalId string `json:"pendingExternalId"`
}
type Environment struct {
Slug string `json:"slug"`
Name string `json:"name"`
Project string `json:"project"`
CreatedAt string `json:"created_at"`
PersonalConfigs bool `json:"personal_configs"`
}
type EnvironmentResponse struct {
Environment Environment `json:"environment"`
}
type EnvironmentsResponse struct {
Environments []Environment `json:"environments"`
}
func (e Environment) getResourceId() string {
return strings.Join([]string{e.Project, e.Slug}, ".")
}
func parseEnvironmentResourceId(id string) (project string, name string, err error) {
tokens := strings.Split(id, ".")
if len(tokens) != 2 {
return "", "", errors.New("invalid environment ID")
}
return tokens[0], tokens[1], nil
}
type WebhookAuth struct {
Type string `json:"type"`
Token string `json:"token"`
Username string `json:"username"`
Password string `json:"password"`
}
type Webhook struct {
Slug string `json:"id"`
Name string `json:"name"`
Url string `json:"url"`
Enabled bool `json:"enabled"`
EnabledConfigs []string `json:"enabledConfigs"`
}
type WebhookResponse struct {
Webhook Webhook `json:"webhook"`
}
type Config struct {
Slug string `json:"slug"`
Name string `json:"name"`
Project string `json:"project"`
Environment string `json:"environment"`
Locked bool `json:"locked"`
Root bool `json:"root"`
CreatedAt string `json:"created_at"`
Inheritable bool `json:"inheritable"`
Inherits []ConfigDescriptor `json:"inherits"`
}
type ConfigDescriptor struct {
Project string `json:"project"`
Config string `json:"config"`
}
type ConfigResponse struct {
Config Config `json:"config"`
}
func (c Config) getResourceId() string {
return strings.Join([]string{c.Project, c.Environment, c.Name}, ".")
}
func parseConfigResourceId(id string) (project string, environment string, name string, err error) {
tokens := strings.Split(id, ".")
if len(tokens) != 3 {
return "", "", "", errors.New("invalid config ID")
}
return tokens[0], tokens[1], tokens[2], nil
}
type ServiceToken struct {
Slug string `json:"slug"`
Name string `json:"name"`
Project string `json:"project"`
Environment string `json:"environment"`
Config string `json:"config"`
Access string `json:"access"`
Key string `json:"key"`
CreatedAt string `json:"created_at"`
ExpiresAt string `json:"expires_at,omitempty"`
}
type ServiceTokenResponse struct {
ServiceToken ServiceToken `json:"token"`
}
type ServiceTokenListResponse struct {
ServiceTokens []ServiceToken `json:"tokens"`
}
func (t ServiceToken) getResourceId() string {
return strings.Join([]string{t.Project, t.Config, t.Slug}, ".")
}
func parseServiceTokenResourceId(id string) (project string, config string, slug string, err error) {
tokens := strings.Split(id, ".")
if len(tokens) != 3 {
return "", "", "", errors.New("invalid service token ID")
}
return tokens[0], tokens[1], tokens[2], nil
}
type ServiceAccountToken struct {
Name string `json:"name"`
ExpiresAt string `json:"expires_at"`
CreatedAt string `json:"created_at"`
Slug string `json:"slug"`
}
type ServiceAccountTokenResponse struct {
ServiceAccountToken ServiceAccountToken `json:"api_token"`
ApiKey string `json:"api_key"`
}
func (t ServiceAccountToken) getResourceId() string {
return t.Slug
}
type ServiceAccountIdentityConfigOidc struct {
DiscoveryUrl string `json:"discovery_url"`
ClaimsType string `json:"claims_type"`
Claims map[string][]string `json:"claims"`
}
type ServiceAccountIdentity struct {
Slug string `json:"slug"`
Name string `json:"name"`
TtlSeconds int `json:"ttl_seconds"`
Method string `json:"method"`
Config json.RawMessage `json:"config"`
ConfigOidc ServiceAccountIdentityConfigOidc
}
type ServiceAccountIdentityResponse struct {
Identity ServiceAccountIdentity `json:"identity"`
}
func (response *ServiceAccountIdentityResponse) unmarshal(data []byte) error {
if err := json.Unmarshal(data, response); err != nil {
return err
}
switch response.Identity.Method {
case "oidc":
response.Identity.ConfigOidc = ServiceAccountIdentityConfigOidc{}
if err := json.Unmarshal(response.Identity.Config, &response.Identity.ConfigOidc); err != nil {
return err
}
default:
return errors.New("Unknown auth method type")
}
return nil
}
func (id *ServiceAccountIdentity) marshal() ([]byte, error) {
payload := map[string]interface{}{
"name": id.Name,
"ttl_seconds": id.TtlSeconds,
"method": id.Method,
}
switch id.Method {
case "oidc":
payload["config"] = map[string]interface{}{
"discovery_url": id.ConfigOidc.DiscoveryUrl,
"claims_type": id.ConfigOidc.ClaimsType,
"claims": id.ConfigOidc.Claims,
}
default:
return nil, errors.New("Unknown auth method type")
}
return json.Marshal(payload)
}
type WorkplaceRole struct {
Name string `json:"name"`
Permissions []string `json:"permissions"`
Identifier string `json:"identifier,omitempty"`
IsCustomRole bool `json:"is_custom_role"`
IsInlineRole bool `json:"is_inline_role"`
CreatedAt string `json:"created_at"`
}
type ServiceAccount struct {
Slug string `json:"slug"`
Name string `json:"name"`
CreatedAt string `json:"created_at"`
WorkplaceRole WorkplaceRole `json:"workplace_role"`
}
type ServiceAccountResponse struct {
ServiceAccount ServiceAccount `json:"service_account"`
}
type SimpleProjectRole struct {
Identifier string `json:"identifier"`
}
type SimpleWorkplaceRole struct {
Identifier string `json:"identifier"`
}
type ProjectRole struct {
Identifier string `json:"identifier"`
Name string `json:"name"`
Permissions []string `json:"permissions"`
CreatedAt string `json:"created_at"`
IsCustomRole bool `json:"is_custom_role"`
}
type GetProjectRoleResponse struct {
Role ProjectRole `json:"role"`
}
type CreateProjectRoleResponse struct {
Role ProjectRole `json:"role"`
}
type UpdateProjectRoleResponse struct {
Role ProjectRole `json:"role"`
}
type Group struct {
Slug string `json:"slug"`
Name string `json:"name"`
CreatedAt string `json:"created_at"`
DefaultProjectRole SimpleProjectRole `json:"default_project_role"`
WorkplaceRole SimpleWorkplaceRole `json:"workplace_role"`
}
type GroupResponse struct {
Group Group `json:"group"`
}
type GroupsResponse struct {
Groups []Group `json:"groups"`
}
type GroupIsMemberResponse struct {
IsMember bool `json:"isMember"`
}
type GroupMember struct {
Type string `json:"type"`
Slug string `json:"slug"`
}
type GetGroupMembersResponse struct {
Members []GroupMember `json:"members"`
}
type WorkplaceUser struct {
Slug string `json:"id"`
}
type WorkplaceUsersListResponse struct {
WorkplaceUsers []WorkplaceUser `json:"workplace_users"`
}
func getGroupMemberId(group string, memberType string, memberSlug string) string {
return strings.Join([]string{group, memberType, memberSlug}, ".")
}
func parseGroupMemberId(id string) (group string, memberType string, memberSlug string, err error) {
tokens := strings.Split(id, ".")
if len(tokens) != 3 {
return "", "", "", errors.New("invalid group member ID")
}
return tokens[0], tokens[1], tokens[2], nil
}
type ChangeRequestPolicySubject struct {
Type string `json:"type"`
Slug string `json:"slug"`
}
type ChangeRequestPolicyRule struct {
Type string `json:"type"`
Count int `json:"count,omitempty"`
Subjects []ChangeRequestPolicySubject `json:"subjects,omitempty"`
Strategy string `json:"strategy,omitempty"`
}
type ChangeRequestPolicyTargetProject struct {
All bool `json:"all"`
EnvSlugs []string `json:"envSlugs,omitempty"`
ConfigNames []string `json:"configNames,omitempty"`
}
type ChangeRequestPolicyTargets struct {
AllProjects bool `json:"allProjects"`
Projects map[string]ChangeRequestPolicyTargetProject `json:"projects"`
}
type ChangeRequestPolicy struct {
Slug string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Rules []ChangeRequestPolicyRule `json:"rules"`
Targets ChangeRequestPolicyTargets `json:"targets"`
}
type ChangeRequestPolicyResponse struct {
Policy ChangeRequestPolicy `json:"policy"`
}
var NameTransformers = []string{"none", "camel", "upper-camel", "lower-snake", "tf-var", "dotnet", "dotnet-env", "lower-kebab"}
type GetWorkplaceRoleResponse struct {
Role WorkplaceRole `json:"role"`
}
type CreateWorkplaceRoleResponse struct {
Role WorkplaceRole `json:"role"`
}
type UpdateWorkplaceRoleResponse struct {
Role WorkplaceRole `json:"role"`
}
type TrustedIPsResponse struct {
IPs []string `json:"ips"`
}
func getTrustedIPsResourceId(project, config string) string {
return strings.Join([]string{project, config}, ".")
}
func parseTrustedIPsResourceId(id string) (project string, config string, err error) {
tokens := strings.Split(id, ".")
if len(tokens) != 2 {
return "", "", errors.New("invalid trusted IPs resource ID")
}
return tokens[0], tokens[1], nil
}