-
Notifications
You must be signed in to change notification settings - Fork 3
/
groups_generated.go
932 lines (878 loc) · 30.4 KB
/
groups_generated.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
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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
/* Copyright (c) Fortanix, Inc.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package sdkms
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/pkg/errors"
)
// AWS KMS resources are hosted in multiple locations world-wide and
// each AWS Region is a separate geographic area
// https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html
type AwskmsRegion string
// List of supported AwskmsRegion values
const (
AwskmsRegionUsEast1 AwskmsRegion = "us-east-1"
AwskmsRegionUsEast2 AwskmsRegion = "us-east-2"
AwskmsRegionUsWest1 AwskmsRegion = "us-west-1"
AwskmsRegionUsWest2 AwskmsRegion = "us-west-2"
AwskmsRegionAfSouth1 AwskmsRegion = "af-south-1"
AwskmsRegionApEast1 AwskmsRegion = "ap-east-1"
AwskmsRegionApSoutheast3 AwskmsRegion = "ap-southeast-3"
AwskmsRegionApSouth1 AwskmsRegion = "ap-south-1"
AwskmsRegionApNortheast3 AwskmsRegion = "ap-northeast-3"
AwskmsRegionApNortheast2 AwskmsRegion = "ap-northeast-2"
AwskmsRegionApSoutheast1 AwskmsRegion = "ap-southeast-1"
AwskmsRegionApSoutheast2 AwskmsRegion = "ap-southeast-2"
AwskmsRegionApNortheast1 AwskmsRegion = "ap-northeast-1"
AwskmsRegionCaCentral1 AwskmsRegion = "ca-central-1"
AwskmsRegionEuCentral1 AwskmsRegion = "eu-central-1"
AwskmsRegionEuWest1 AwskmsRegion = "eu-west-1"
AwskmsRegionEuWest2 AwskmsRegion = "eu-west-2"
AwskmsRegionEuSouth1 AwskmsRegion = "eu-south-1"
AwskmsRegionEuWest3 AwskmsRegion = "eu-west-3"
AwskmsRegionEuNorth1 AwskmsRegion = "eu-north-1"
AwskmsRegionMeSouth1 AwskmsRegion = "me-south-1"
AwskmsRegionSaEast1 AwskmsRegion = "sa-east-1"
AwskmsRegionUsGovEast1 AwskmsRegion = "us-gov-east-1"
AwskmsRegionUsGovWest1 AwskmsRegion = "us-gov-west-1"
)
// Specifies the AWS service. Only `kms` is supported for now.
type AwskmsService string
// List of supported AwskmsService values
const (
AwskmsServiceKms AwskmsService = "kms"
AwskmsServiceKmsFips AwskmsService = "kms-fips"
)
type AzureKeyVaultType string
// List of supported AzureKeyVaultType values
const (
AzureKeyVaultTypeStandard AzureKeyVaultType = "STANDARD"
AzureKeyVaultTypePremium AzureKeyVaultType = "PREMIUM"
AzureKeyVaultTypeManaged AzureKeyVaultType = "MANAGED"
)
// The set of endpoints to use when connecting with Azure cloud.
//
// Today, only Azure global and Azure Government cloud endpoints are supported,
// and they cannot be mixed together. The Azure global endpoints are
// - `management`: management.azure.com
// - `key_vault`: vault.azure.net
// - `key_vault_managed_hsm`: managedhsm.azure.net
// - `iam`: login.microsoftonline.com
//
// and the Azure Government endpoints are
// - `management`: management.usgovcloudapi.net
// - `key_vault`: vault.usgovcloudapi.net
// - `key_vault_managed_hsm`: managedhsm.usgovcloudapi.net
// - `iam`: login.microsoftonline.us
//
// (In the future, this restriction may be relaxed to support custom clouds.)
type AzureServiceEndpoints struct {
// The API endpoint for managing Azure APIs and resources.
Management string `json:"management"`
// The API endpoint for Azure Key Vault (for Standard and Premium SKUs).
KeyVault string `json:"key_vault"`
// The API endpoint for Azure Key Vault Managed HSM.
KeyVaultManagedHsm string `json:"key_vault_managed_hsm"`
// The API endpoint for Azure AD (and authentication).
Iam string `json:"iam"`
}
type CheckHmgRequest struct {
// The ID of the hmg configuration in the group.
ID *UUID `json:"id,omitempty"`
Config *HmgConfig `json:"config,omitempty"`
}
type GcpKeyRingConfig struct {
ServiceAccountEmail string `json:"service_account_email"`
ProjectID string `json:"project_id"`
Location string `json:"location"`
KeyRing *string `json:"key_ring,omitempty"`
PrivateKey *Blob `json:"private_key,omitempty"`
}
// Information about a group's recent scans.
type GetAllHmgScansResponse struct {
// List of all tracked scans, from newest to oldest.
Items []Scan `json:"items"`
}
type GetGroupsParams struct {
Limit *uint `json:"limit,omitempty"`
SortBy *GroupSort `json:"sort_by,omitempty"`
Filter *string `json:"filter,omitempty"`
}
func (x GetGroupsParams) urlEncode(v map[string][]string) error {
if x.Limit != nil {
v["limit"] = []string{fmt.Sprintf("%v", *x.Limit)}
}
if err := x.SortBy.urlEncode(v); err != nil {
return err
}
if x.Filter != nil {
v["filter"] = []string{fmt.Sprintf("%v", *x.Filter)}
}
return nil
}
type Group struct {
AcctID UUID `json:"acct_id"`
ApprovalPolicy *GroupApprovalPolicy `json:"approval_policy,omitempty"`
// Settings for automatic key scanning. For now, this is only available for DSM-backed groups.
AutoScan *HmgAutoScan `json:"auto_scan,omitempty"`
ClientConfigurations ClientConfigurations `json:"client_configurations"`
CreatedAt Time `json:"created_at"`
Creator Principal `json:"creator"`
CryptographicPolicy *CryptographicPolicy `json:"cryptographic_policy,omitempty"`
CustodianPolicy *QuorumPolicy `json:"custodian_policy,omitempty"`
CustomMetadata *map[string]string `json:"custom_metadata,omitempty"`
Description *string `json:"description,omitempty"`
// Key Access Justifications for GCP EKM.
// For more details: https://cloud.google.com/cloud-provider-access-management/key-access-justifications/docs/overview
GoogleAccessReasonPolicy *GoogleAccessReasonPolicy `json:"google_access_reason_policy,omitempty"`
GroupID UUID `json:"group_id"`
Hmg *map[UUID]HmgConfig `json:"hmg,omitempty"`
HmgRedundancy *HmgRedundancyScheme `json:"hmg_redundancy,omitempty"`
HmgSegregation *bool `json:"hmg_segregation,omitempty"`
HmgSync *bool `json:"hmg_sync,omitempty"`
KeyHistoryPolicy *KeyHistoryPolicy `json:"key_history_policy,omitempty"`
KeyMetadataPolicy *KeyMetadataPolicy `json:"key_metadata_policy,omitempty"`
Name string `json:"name"`
// Name of an AES key from another group. The key will be used to encrypt the key material of all keys in this group
WrappingKeyName *WrappingKeyName `json:"wrapping_key_name,omitempty"`
}
// Group approval policy.
type GroupApprovalPolicy struct {
Policy QuorumPolicy `json:"policy"`
// Deprecated, left this for backward compatibility.
// When this is true, manage operations on security objects require approval.
ProtectManageOperations *bool `json:"protect_manage_operations,omitempty"`
// Use QuorumGroupPermissions to represent operations that require approval.
ProtectPermissions *QuorumGroupPermissions `json:"protect_permissions,omitempty"`
// When this is true, cryptographic operations on security objects require approval.
ProtectCryptoOperations *bool `json:"protect_crypto_operations,omitempty"`
}
func (x GroupApprovalPolicy) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
{ // x.Policy is flattened
b, err := json.Marshal(&x.Policy)
if err != nil {
return nil, err
}
f := make(map[string]interface{})
if err := json.Unmarshal(b, &f); err != nil {
return nil, err
}
for k, v := range f {
m[k] = v
}
}
if x.ProtectManageOperations != nil {
m["protect_manage_operations"] = x.ProtectManageOperations
}
if x.ProtectPermissions != nil {
m["protect_permissions"] = x.ProtectPermissions
}
if x.ProtectCryptoOperations != nil {
m["protect_crypto_operations"] = x.ProtectCryptoOperations
}
return json.Marshal(&m)
}
func (x *GroupApprovalPolicy) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &x.Policy); err != nil {
return err
}
var r struct {
ProtectManageOperations *bool `json:"protect_manage_operations,omitempty"`
ProtectPermissions *QuorumGroupPermissions `json:"protect_permissions,omitempty"`
ProtectCryptoOperations *bool `json:"protect_crypto_operations,omitempty"`
}
if err := json.Unmarshal(data, &r); err != nil {
return err
}
x.ProtectManageOperations = r.ProtectManageOperations
x.ProtectPermissions = r.ProtectPermissions
x.ProtectCryptoOperations = r.ProtectCryptoOperations
return nil
}
type GroupRequest struct {
AddHmg *[]HmgConfig `json:"add_hmg,omitempty"`
ApprovalPolicy *GroupApprovalPolicy `json:"approval_policy,omitempty"`
// Settings for automatic key scanning. For now, this is only available for DSM-backed groups.
AutoScan *Removable[HmgAutoScan] `json:"auto_scan,omitempty"`
ClientConfigurations *ClientConfigurationsRequest `json:"client_configurations,omitempty"`
CryptographicPolicy *Removable[CryptographicPolicy] `json:"cryptographic_policy,omitempty"`
CustodianPolicy *QuorumPolicy `json:"custodian_policy,omitempty"`
CustomMetadata *map[string]string `json:"custom_metadata,omitempty"`
DelHmg *[]UUID `json:"del_hmg,omitempty"`
Description *string `json:"description,omitempty"`
// Key Access Justifications for GCP EKM.
// For more details: https://cloud.google.com/cloud-provider-access-management/key-access-justifications/docs/overview
GoogleAccessReasonPolicy *Removable[GoogleAccessReasonPolicy] `json:"google_access_reason_policy,omitempty"`
HmgRedundancy *HmgRedundancyScheme `json:"hmg_redundancy,omitempty"`
HmgSegregation *bool `json:"hmg_segregation,omitempty"`
HmgSync *bool `json:"hmg_sync,omitempty"`
KeyHistoryPolicy *Removable[KeyHistoryPolicy] `json:"key_history_policy,omitempty"`
KeyMetadataPolicy *Removable[KeyMetadataPolicy] `json:"key_metadata_policy,omitempty"`
ModHmg *map[UUID]HmgConfig `json:"mod_hmg,omitempty"`
Name *string `json:"name,omitempty"`
// Name of an AES key from another group. The key will be used to encrypt the key material of all keys in this group
WrappingKeyName *WrappingKeyName `json:"wrapping_key_name,omitempty"`
}
type GroupSort struct {
ByGroupID *GroupSortByGroupId
}
type GroupSortByGroupId struct {
Order Order `json:"order"`
Start *UUID `json:"start,omitempty"`
}
func (x GroupSort) urlEncode(v map[string][]string) error {
if x.ByGroupID != nil {
v["sort"] = []string{"group_id" + string(x.ByGroupID.Order)}
if x.ByGroupID.Start != nil {
v["start"] = []string{fmt.Sprintf("%v", *x.ByGroupID.Start)}
}
}
return nil
}
// Settings for automatic scanning in externally-backed groups. Today, this is only
// applicable for DSM-backed groups.
type HmgAutoScan struct {
// The number of hours between successive automatic scans. Must be greater than 0.
ScanIntervalHours uint8 `json:"scan_interval_hours"`
}
type HmgConfig struct {
Ncipher *HmgConfigNcipher
Safenet *HmgConfigSafenet
AwsCloudHsm *HmgConfigAwsCloudHsm
AwsKms *HmgConfigAwsKms
Fortanix *HmgConfigFortanix
FortanixFipsCluster *HmgConfigFortanixFipsCluster
AzureKeyVault *HmgConfigAzureKeyVault
GcpKeyRing *GcpKeyRingConfig
}
type HmgConfigNcipher struct {
URL string `json:"url"`
TLS TlsConfig `json:"tls"`
Slot uint `json:"slot"`
Pin *string `json:"pin,omitempty"`
HsmOrder *int32 `json:"hsm_order,omitempty"`
}
type HmgConfigSafenet struct {
URL string `json:"url"`
TLS TlsConfig `json:"tls"`
Slot uint `json:"slot"`
Pin *string `json:"pin,omitempty"`
HsmOrder *int32 `json:"hsm_order,omitempty"`
}
type HmgConfigAwsCloudHsm struct {
URL string `json:"url"`
TLS TlsConfig `json:"tls"`
Slot uint `json:"slot"`
Pin *string `json:"pin,omitempty"`
HsmOrder *int32 `json:"hsm_order,omitempty"`
}
type HmgConfigAwsKms struct {
URL string `json:"url"`
TLS TlsConfig `json:"tls"`
AccessKey *string `json:"access_key,omitempty"`
SecretKey *string `json:"secret_key,omitempty"`
Region *AwskmsRegion `json:"region,omitempty"`
Service *AwskmsService `json:"service,omitempty"`
}
type HmgConfigFortanix struct {
URL string `json:"url"`
TLS TlsConfig `json:"tls"`
Pin *string `json:"pin,omitempty"`
}
type HmgConfigFortanixFipsCluster struct {
URL string `json:"url"`
TLS TlsConfig `json:"tls"`
Pin *string `json:"pin,omitempty"`
Credentials *[]string `json:"credentials,omitempty"`
}
type HmgConfigAzureKeyVault struct {
URL string `json:"url"`
TLS TlsConfig `json:"tls"`
SecretKey *string `json:"secret_key,omitempty"`
TenantID UUID `json:"tenant_id"`
ClientID UUID `json:"client_id"`
SubscriptionID UUID `json:"subscription_id"`
KeyVaultType *AzureKeyVaultType `json:"key_vault_type,omitempty"`
// Which Azure endpoints to use. If not specified upon group creation or
// update, endpoints for (ordinary) Azure global cloud will be used.
Endpoints *AzureServiceEndpoints `json:"endpoints,omitempty"`
}
func (x HmgConfig) MarshalJSON() ([]byte, error) {
if err := checkEnumPointers(
"HmgConfig",
[]bool{x.Ncipher != nil,
x.Safenet != nil,
x.AwsCloudHsm != nil,
x.AwsKms != nil,
x.Fortanix != nil,
x.FortanixFipsCluster != nil,
x.AzureKeyVault != nil,
x.GcpKeyRing != nil}); err != nil {
return nil, err
}
m := make(map[string]interface{})
switch {
case x.Ncipher != nil:
b, err := json.Marshal(x.Ncipher)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &m); err != nil {
return nil, err
}
m["kind"] = "Ncipher"
case x.Safenet != nil:
b, err := json.Marshal(x.Safenet)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &m); err != nil {
return nil, err
}
m["kind"] = "Safenet"
case x.AwsCloudHsm != nil:
b, err := json.Marshal(x.AwsCloudHsm)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &m); err != nil {
return nil, err
}
m["kind"] = "AwsCloudHsm"
case x.AwsKms != nil:
b, err := json.Marshal(x.AwsKms)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &m); err != nil {
return nil, err
}
m["kind"] = "AwsKms"
case x.Fortanix != nil:
b, err := json.Marshal(x.Fortanix)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &m); err != nil {
return nil, err
}
m["kind"] = "Fortanix"
case x.FortanixFipsCluster != nil:
b, err := json.Marshal(x.FortanixFipsCluster)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &m); err != nil {
return nil, err
}
m["kind"] = "FortanixFipsCluster"
case x.AzureKeyVault != nil:
b, err := json.Marshal(x.AzureKeyVault)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &m); err != nil {
return nil, err
}
m["kind"] = "AzureKeyVault"
case x.GcpKeyRing != nil:
b, err := json.Marshal(x.GcpKeyRing)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &m); err != nil {
return nil, err
}
m["kind"] = "GcpKeyRing"
}
return json.Marshal(m)
}
func (x *HmgConfig) UnmarshalJSON(data []byte) error {
x.Ncipher = nil
x.Safenet = nil
x.AwsCloudHsm = nil
x.AwsKms = nil
x.Fortanix = nil
x.FortanixFipsCluster = nil
x.AzureKeyVault = nil
x.GcpKeyRing = nil
var h struct {
Tag string `json:"kind"`
}
if err := json.Unmarshal(data, &h); err != nil {
return errors.Errorf("not a valid HmgConfig")
}
switch h.Tag {
case "Ncipher":
var ncipher HmgConfigNcipher
if err := json.Unmarshal(data, &ncipher); err != nil {
return err
}
x.Ncipher = &ncipher
case "Safenet":
var safenet HmgConfigSafenet
if err := json.Unmarshal(data, &safenet); err != nil {
return err
}
x.Safenet = &safenet
case "AwsCloudHsm":
var awsCloudHsm HmgConfigAwsCloudHsm
if err := json.Unmarshal(data, &awsCloudHsm); err != nil {
return err
}
x.AwsCloudHsm = &awsCloudHsm
case "AwsKms":
var awsKms HmgConfigAwsKms
if err := json.Unmarshal(data, &awsKms); err != nil {
return err
}
x.AwsKms = &awsKms
case "Fortanix":
var fortanix HmgConfigFortanix
if err := json.Unmarshal(data, &fortanix); err != nil {
return err
}
x.Fortanix = &fortanix
case "FortanixFipsCluster":
var fortanixFipsCluster HmgConfigFortanixFipsCluster
if err := json.Unmarshal(data, &fortanixFipsCluster); err != nil {
return err
}
x.FortanixFipsCluster = &fortanixFipsCluster
case "AzureKeyVault":
var azureKeyVault HmgConfigAzureKeyVault
if err := json.Unmarshal(data, &azureKeyVault); err != nil {
return err
}
x.AzureKeyVault = &azureKeyVault
case "GcpKeyRing":
var gcpKeyRing GcpKeyRingConfig
if err := json.Unmarshal(data, &gcpKeyRing); err != nil {
return err
}
x.GcpKeyRing = &gcpKeyRing
default:
return errors.Errorf("invalid tag value: %v", h.Tag)
}
return nil
}
type HmgRedundancyScheme string
// List of supported HmgRedundancyScheme values
const (
HmgRedundancySchemePriorityFailover HmgRedundancyScheme = "PriorityFailover"
)
type KeyVault struct {
ID string `json:"id"`
Name string `json:"name"`
VaultType AzureKeyVaultType `json:"vault_type"`
Location string `json:"location"`
Tags *map[string]string `json:"tags,omitempty"`
Retention *uint32 `json:"retention,omitempty"`
URI string `json:"uri"`
}
// Subset of GroupPermissions to represent GroupPermissions flags in use
type QuorumGroupPermissions uint64
// List of supported QuorumGroupPermissions values
const (
QuorumGroupPermissionsGetSobjects QuorumGroupPermissions = 1 << iota
QuorumGroupPermissionsRotateSobjects
QuorumGroupPermissionsRevokeSobjects
QuorumGroupPermissionsRevertSobjects
QuorumGroupPermissionsDeleteKeyMaterial
QuorumGroupPermissionsDeleteSobjects
QuorumGroupPermissionsDestroySobjects
QuorumGroupPermissionsMoveSobjects
QuorumGroupPermissionsCreateSobjects
QuorumGroupPermissionsUpdateSobjectsProfile
QuorumGroupPermissionsUpdateSobjectsEnabledState
QuorumGroupPermissionsUpdateSobjectPolicies
QuorumGroupPermissionsActivateSobjects
QuorumGroupPermissionsUpdateKeyOps
)
// MarshalJSON converts QuorumGroupPermissions to an array of strings
func (x QuorumGroupPermissions) MarshalJSON() ([]byte, error) {
s := make([]string, 0)
if x&QuorumGroupPermissionsGetSobjects == QuorumGroupPermissionsGetSobjects {
s = append(s, "GET_SOBJECTS")
}
if x&QuorumGroupPermissionsRotateSobjects == QuorumGroupPermissionsRotateSobjects {
s = append(s, "ROTATE_SOBJECTS")
}
if x&QuorumGroupPermissionsRevokeSobjects == QuorumGroupPermissionsRevokeSobjects {
s = append(s, "REVOKE_SOBJECTS")
}
if x&QuorumGroupPermissionsRevertSobjects == QuorumGroupPermissionsRevertSobjects {
s = append(s, "REVERT_SOBJECTS")
}
if x&QuorumGroupPermissionsDeleteKeyMaterial == QuorumGroupPermissionsDeleteKeyMaterial {
s = append(s, "DELETE_KEY_MATERIAL")
}
if x&QuorumGroupPermissionsDeleteSobjects == QuorumGroupPermissionsDeleteSobjects {
s = append(s, "DELETE_SOBJECTS")
}
if x&QuorumGroupPermissionsDestroySobjects == QuorumGroupPermissionsDestroySobjects {
s = append(s, "DESTROY_SOBJECTS")
}
if x&QuorumGroupPermissionsMoveSobjects == QuorumGroupPermissionsMoveSobjects {
s = append(s, "MOVE_SOBJECTS")
}
if x&QuorumGroupPermissionsCreateSobjects == QuorumGroupPermissionsCreateSobjects {
s = append(s, "CREATE_SOBJECTS")
}
if x&QuorumGroupPermissionsUpdateSobjectsProfile == QuorumGroupPermissionsUpdateSobjectsProfile {
s = append(s, "UPDATE_SOBJECTS_PROFILE")
}
if x&QuorumGroupPermissionsUpdateSobjectsEnabledState == QuorumGroupPermissionsUpdateSobjectsEnabledState {
s = append(s, "UPDATE_SOBJECTS_ENABLED_STATE")
}
if x&QuorumGroupPermissionsUpdateSobjectPolicies == QuorumGroupPermissionsUpdateSobjectPolicies {
s = append(s, "UPDATE_SOBJECT_POLICIES")
}
if x&QuorumGroupPermissionsActivateSobjects == QuorumGroupPermissionsActivateSobjects {
s = append(s, "ACTIVATE_SOBJECTS")
}
if x&QuorumGroupPermissionsUpdateKeyOps == QuorumGroupPermissionsUpdateKeyOps {
s = append(s, "UPDATE_KEY_OPS")
}
return json.Marshal(s)
}
// UnmarshalJSON converts array of strings to QuorumGroupPermissions
func (x *QuorumGroupPermissions) UnmarshalJSON(data []byte) error {
*x = 0
var s []string
if err := json.Unmarshal(data, &s); err != nil {
return err
}
for _, v := range s {
switch v {
case "GET_SOBJECTS":
*x = *x | QuorumGroupPermissionsGetSobjects
case "ROTATE_SOBJECTS":
*x = *x | QuorumGroupPermissionsRotateSobjects
case "REVOKE_SOBJECTS":
*x = *x | QuorumGroupPermissionsRevokeSobjects
case "REVERT_SOBJECTS":
*x = *x | QuorumGroupPermissionsRevertSobjects
case "DELETE_KEY_MATERIAL":
*x = *x | QuorumGroupPermissionsDeleteKeyMaterial
case "DELETE_SOBJECTS":
*x = *x | QuorumGroupPermissionsDeleteSobjects
case "DESTROY_SOBJECTS":
*x = *x | QuorumGroupPermissionsDestroySobjects
case "MOVE_SOBJECTS":
*x = *x | QuorumGroupPermissionsMoveSobjects
case "CREATE_SOBJECTS":
*x = *x | QuorumGroupPermissionsCreateSobjects
case "UPDATE_SOBJECTS_PROFILE":
*x = *x | QuorumGroupPermissionsUpdateSobjectsProfile
case "UPDATE_SOBJECTS_ENABLED_STATE":
*x = *x | QuorumGroupPermissionsUpdateSobjectsEnabledState
case "UPDATE_SOBJECT_POLICIES":
*x = *x | QuorumGroupPermissionsUpdateSobjectPolicies
case "ACTIVATE_SOBJECTS":
*x = *x | QuorumGroupPermissionsActivateSobjects
case "UPDATE_KEY_OPS":
*x = *x | QuorumGroupPermissionsUpdateKeyOps
}
}
return nil
}
// An object for representing a scan of objects from a source HSM,
// DSM cluster, or cloud KMS.
type Scan struct {
// The ID of the scan.
ScanID UUID `json:"scan_id"`
// Whether the scan is async or not.
IsAsync bool `json:"is_async"`
// The time the scan began.
StartedAt Time `json:"started_at"`
// The time the scan finished.
FinishedAt *Time `json:"finished_at,omitempty"`
// The "return status" of the scan.
ScanResult *ScanResult `json:"scan_result,omitempty"`
// Any warnings thrown during the scan.
Warnings *[]ScanWarning `json:"warnings,omitempty"`
}
type ScanHmgRequest struct {
}
// The result of a scan.
type ScanResult struct {
// Indicates that a scan completed successfully.
Success *struct{}
// Indicates that a scan has failed. The most recent error is included
// (taken from the last retry).
Failed *ScanResultFailed
}
// Indicates that a scan has failed. The most recent error is included
// (taken from the last retry).
type ScanResultFailed struct {
Message string `json:"message"`
}
func (x ScanResult) MarshalJSON() ([]byte, error) {
if err := checkEnumPointers(
"ScanResult",
[]bool{x.Success != nil,
x.Failed != nil}); err != nil {
return nil, err
}
m := make(map[string]interface{})
switch {
case x.Success != nil:
m["$type"] = "Success"
case x.Failed != nil:
b, err := json.Marshal(x.Failed)
if err != nil {
return nil, err
}
if err := json.Unmarshal(b, &m); err != nil {
return nil, err
}
m["$type"] = "Failed"
}
return json.Marshal(m)
}
func (x *ScanResult) UnmarshalJSON(data []byte) error {
x.Success = nil
x.Failed = nil
var h struct {
Tag string `json:"$type"`
}
if err := json.Unmarshal(data, &h); err != nil {
return errors.Errorf("not a valid ScanResult")
}
switch h.Tag {
case "Success":
x.Success = &struct{}{}
case "Failed":
var failed ScanResultFailed
if err := json.Unmarshal(data, &failed); err != nil {
return err
}
x.Failed = &failed
default:
return errors.Errorf("invalid tag value: %v", h.Tag)
}
return nil
}
// A warning "thrown" by a scan.
type ScanWarning struct {
// The ID of the source key for which the warning applies to.
SourceKeyID *UUID `json:"source_key_id,omitempty"`
// The ID of the virtual key for which the warning applies to.
VirtualKeyID *UUID `json:"virtual_key_id,omitempty"`
// The warning message associated with the warning.
Message string `json:"message"`
}
type WrappingKeyName struct {
Null *struct{}
Value *string
}
func (x WrappingKeyName) MarshalJSON() ([]byte, error) {
if err := checkEnumPointers(
"WrappingKeyName",
[]bool{x.Null != nil,
x.Value != nil}); err != nil {
return nil, err
}
if x.Null != nil {
return json.Marshal(x.Null)
}
if x.Value != nil {
return json.Marshal(x.Value)
}
panic("unreachable")
}
func (x *WrappingKeyName) UnmarshalJSON(data []byte) error {
x.Null = nil
x.Value = nil
var null struct{}
if err := json.Unmarshal(data, &null); err == nil {
x.Null = &null
return nil
}
var value string
if err := json.Unmarshal(data, &value); err == nil {
x.Value = &value
return nil
}
return errors.Errorf("not a valid WrappingKeyName")
}
// Scan external objects asynchronously.
//
// Scan external objects asynchronously and create corresponding
// virtual sobjects in the group as needed. If there is already a virtual
// sobject corresponding to a scanned object, no sobject is created.
// This is only supported for DSM-backed groups currently.
func (c *Client) AsyncScanHmg(ctx context.Context, id string) (*Scan, error) {
u := "/sys/v1/groups/:id/hmg/scans"
u = strings.NewReplacer(":id", id).Replace(u)
var r Scan
if err := c.fetch(ctx, http.MethodPost, u, nil, &r); err != nil {
return nil, err
}
return &r, nil
}
// Check that the HMG configuration for a particular group is
// valid and reachable.
func (c *Client) CheckHmg(ctx context.Context, id string, body CheckHmgRequest) error {
u := "/sys/v1/groups/:id/hmg/check"
u = strings.NewReplacer(":id", id).Replace(u)
if err := c.fetch(ctx, http.MethodPost, u, &body, nil); err != nil {
return err
}
return nil
}
// Check that the HMG configuration provided is valid and reachable.
func (c *Client) CheckHmgConfig(ctx context.Context, body HmgConfig) error {
u := "/sys/v1/groups/hmg/check"
if err := c.fetch(ctx, http.MethodPost, u, &body, nil); err != nil {
return err
}
return nil
}
// Create a new group with the specified properties.
func (c *Client) CreateGroup(ctx context.Context, body GroupRequest) (*Group, error) {
u := "/sys/v1/groups"
var r Group
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
func (c *Client) RequestApprovalToCreateGroup(
ctx context.Context,
body GroupRequest,
description *string) (*ApprovalRequest, error) {
u := "/sys/v1/groups"
req := ApprovalRequestRequest{
Method: someString(http.MethodPost),
Operation: &u,
Body: &body,
Description: description,
}
return c.CreateApprovalRequest(ctx, req)
}
// Delete the group.
func (c *Client) DeleteGroup(ctx context.Context, id string) error {
u := "/sys/v1/groups/:id"
u = strings.NewReplacer(":id", id).Replace(u)
if err := c.fetch(ctx, http.MethodDelete, u, nil, nil); err != nil {
return err
}
return nil
}
// Retrieve the scan status of an external group.
func (c *Client) GetAllHmgScans(ctx context.Context, id string) (*GetAllHmgScansResponse, error) {
u := "/sys/v1/groups/:id/hmg/scans"
u = strings.NewReplacer(":id", id).Replace(u)
var r GetAllHmgScansResponse
if err := c.fetch(ctx, http.MethodGet, u, nil, &r); err != nil {
return nil, err
}
return &r, nil
}
// Given an GCP configuration, fetch a list of available
// GCP key rings which can be used to back a group.
func (c *Client) GetGcpKeyRings(ctx context.Context, body GcpKeyRingConfig) ([]string, error) {
u := "/sys/v1/groups/hmg/gcp_key_rings"
var r []string
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return r, nil
}
// Lookup a specific group.
func (c *Client) GetGroup(ctx context.Context, id string) (*Group, error) {
u := "/sys/v1/groups/:id"
u = strings.NewReplacer(":id", id).Replace(u)
var r Group
if err := c.fetch(ctx, http.MethodGet, u, nil, &r); err != nil {
return nil, err
}
return &r, nil
}
// Query the status of a particular scan. Only the last five completed
// scans,as well as any in-progress scan, is queryable.
func (c *Client) GetScan(ctx context.Context, group_id string, scan_id string) (*Scan, error) {
u := "/sys/v1/groups/:group_id/hmg/scans/:scan_id"
u = strings.NewReplacer(":group_id", group_id, ":scan_id", scan_id).Replace(u)
var r Scan
if err := c.fetch(ctx, http.MethodGet, u, nil, &r); err != nil {
return nil, err
}
return &r, nil
}
// Given an Azure configuration, fetch a list of available
// Azure key vaults which can be used to back a group.
func (c *Client) GetVaults(ctx context.Context, body HmgConfig) ([]KeyVault, error) {
u := "/sys/v1/groups/hmg/azure_vaults"
var r []KeyVault
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return r, nil
}
// Get all groups accessible to the requester.
func (c *Client) ListGroups(ctx context.Context, queryParameters *GetGroupsParams) ([]Group, error) {
u := "/sys/v1/groups"
if queryParameters != nil {
q, err := encodeURLParams(queryParameters)
if err != nil {
return nil, err
}
u = fmt.Sprintf("%v?%v", u, q)
}
var r []Group
if err := c.fetch(ctx, http.MethodGet, u, nil, &r); err != nil {
return nil, err
}
return r, nil
}
// Scan external objects.
//
// Scan external objects synchronously and create corresponding
// virtual sobjects in the group as needed. If there is already a
// virtual sobject corresponding to a scanned object, no sobject
// is created.
func (c *Client) ScanHmg(ctx context.Context, id string, body ScanHmgRequest) ([]Sobject, error) {
u := "/sys/v1/groups/:id/hmg/scan"
u = strings.NewReplacer(":id", id).Replace(u)
var r []Sobject
if err := c.fetch(ctx, http.MethodPost, u, &body, &r); err != nil {
return nil, err
}
return r, nil
}
// Change a group's properties.
func (c *Client) UpdateGroup(ctx context.Context, id string, body GroupRequest) (*Group, error) {
u := "/sys/v1/groups/:id"
u = strings.NewReplacer(":id", id).Replace(u)
var r Group
if err := c.fetch(ctx, http.MethodPatch, u, &body, &r); err != nil {
return nil, err
}
return &r, nil
}
func (c *Client) RequestApprovalToUpdateGroup(
ctx context.Context,
id string,
body GroupRequest,
description *string) (*ApprovalRequest, error) {
u := "/sys/v1/groups/:id"
u = strings.NewReplacer(":id", id).Replace(u)
req := ApprovalRequestRequest{
Method: someString(http.MethodPatch),
Operation: &u,
Body: &body,
Description: description,
}
return c.CreateApprovalRequest(ctx, req)
}