-
Notifications
You must be signed in to change notification settings - Fork 276
/
model.go
3897 lines (3449 loc) · 85.8 KB
/
model.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
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//
// This file generated by rdl 1.4.12
//
package zms
import (
"encoding/json"
"fmt"
rdl "github.com/ardielle/ardielle-go/rdl"
)
var _ = rdl.Version
var _ = json.Marshal
var _ = fmt.Printf
//
// SimpleName - Copyright 2016 Yahoo Inc. Licensed under the terms of the
// Apache version 2.0 license. See LICENSE file for terms. Common name types
// used by several API definitions A simple identifier, an element of compound
// name.
//
type SimpleName string
//
// CompoundName - A compound name. Most names in this API are compound names.
//
type CompoundName string
//
// DomainName - A domain name is the general qualifier prefix, as its
// uniqueness is managed.
//
type DomainName string
//
// EntityName - An entity name is a short form of a resource name, including
// only the domain and entity.
//
type EntityName string
//
// ServiceName - A service name will generally be a unique subdomain.
//
type ServiceName string
//
// LocationName - A location name is not yet defined, but will be a dotted name
// like everything else.
//
type LocationName string
//
// ActionName - An action (operation) name.
//
type ActionName string
//
// ResourceName - A resource name Note that the EntityName part is optional,
// that is, a domain name followed by a colon is valid resource name.
//
type ResourceName string
//
// YBase64 - The Y-specific URL-safe Base64 variant.
//
type YBase64 string
//
// YEncoded - YEncoded includes ybase64 chars, as well as = and %. This can
// represent a user cookie and URL-encoded values.
//
type YEncoded string
//
// AuthorityName - Used as the prefix in a signed assertion. This uniquely
// identifies a signing authority. i.e. "user"
//
type AuthorityName string
//
// SignedToken - A signed assertion if identity. i.e. the user cookie value.
// This token will only make sense to the authority that generated it, so it is
// beneficial to have something in the value that is cheaply recognized to
// quickly reject if it belongs to another authority. In addition to the
// YEncoded set our token includes ; to separate components and , to separate
// roles and : for IPv6 addresses
//
type SignedToken string
//
// MemberName - Role Member name - could be one of three values, either *,
// DomainName.* or ResourceName
//
type MemberName string
//
// Domain - A domain is an independent partition of users, roles, and
// resources. Its name represents the definition of a namespace; the only way a
// new namespace can be created, from the top, is by creating Domains.
// Administration of a domain is governed by the parent domain (using
// reverse-DNS namespaces). The top level domains are governed by the special
// "sys.auth" domain.
//
type Domain struct {
//
// the common name to be referred to, the symbolic id. It is immutable
//
Name DomainName `json:"name"`
//
// the last modification timestamp of any object or attribute in this domain
//
Modified *rdl.Timestamp `json:"modified,omitempty" rdl:"optional"`
//
// unique identifier of the domain. generated on create, never reused
//
Id *rdl.UUID `json:"id,omitempty" rdl:"optional"`
//
// description of the domain
//
Description string `json:"description,omitempty" rdl:"optional"`
//
// a reference to an Organization
//
Org ResourceName `json:"org,omitempty" rdl:"optional"`
//
// Future use only, currently not used
//
Enabled *bool `json:"enabled,omitempty" rdl:"optional"`
//
// Flag indicates whether or not domain modifications should be logged for
// SOX+Auditing. If true, the auditRef parameter must be supplied(not empty) for
// any API defining it.
//
AuditEnabled *bool `json:"auditEnabled,omitempty" rdl:"optional"`
//
// associated cloud (i.e. aws) account id
//
Account string `json:"account,omitempty" rdl:"optional"`
//
// associated product id
//
YpmId *int32 `json:"ypmId,omitempty" rdl:"optional"`
}
//
// NewDomain - creates an initialized Domain instance, returns a pointer to it
//
func NewDomain(init ...*Domain) *Domain {
var o *Domain
if len(init) == 1 {
o = init[0]
} else {
o = new(Domain)
}
return o.Init()
}
//
// Init - sets up the instance according to its default field values, if any
//
func (self *Domain) Init() *Domain {
if self.Enabled == nil {
d := true
self.Enabled = &d
}
if self.AuditEnabled == nil {
d := false
self.AuditEnabled = &d
}
return self
}
type rawDomain Domain
//
// UnmarshalJSON is defined for proper JSON decoding of a Domain
//
func (self *Domain) UnmarshalJSON(b []byte) error {
var r rawDomain
err := json.Unmarshal(b, &r)
if err == nil {
o := Domain(r)
*self = *((&o).Init())
err = self.Validate()
}
return err
}
//
// Validate - checks for missing required fields, etc
//
func (self *Domain) Validate() error {
if self.Name == "" {
return fmt.Errorf("Domain.name is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "DomainName", self.Name)
if !val.Valid {
return fmt.Errorf("Domain.name does not contain a valid DomainName (%v)", val.Error)
}
}
return nil
}
//
// RoleList - The representation for an enumeration of roles in the namespace,
// with pagination.
//
type RoleList struct {
//
// list of role names
//
Names []EntityName `json:"names"`
//
// if the response is a paginated list, this attribute specifies the value to
// be used in the next role list request as the value for the skip query
// parameter.
//
Next string `json:"next,omitempty" rdl:"optional"`
}
//
// NewRoleList - creates an initialized RoleList instance, returns a pointer to it
//
func NewRoleList(init ...*RoleList) *RoleList {
var o *RoleList
if len(init) == 1 {
o = init[0]
} else {
o = new(RoleList)
}
return o.Init()
}
//
// Init - sets up the instance according to its default field values, if any
//
func (self *RoleList) Init() *RoleList {
if self.Names == nil {
self.Names = make([]EntityName, 0)
}
return self
}
type rawRoleList RoleList
//
// UnmarshalJSON is defined for proper JSON decoding of a RoleList
//
func (self *RoleList) UnmarshalJSON(b []byte) error {
var r rawRoleList
err := json.Unmarshal(b, &r)
if err == nil {
o := RoleList(r)
*self = *((&o).Init())
err = self.Validate()
}
return err
}
//
// Validate - checks for missing required fields, etc
//
func (self *RoleList) Validate() error {
if self.Names == nil {
return fmt.Errorf("RoleList: Missing required field: names")
}
return nil
}
//
// RoleAuditLog - An audit log entry for role membership change.
//
type RoleAuditLog struct {
//
// name of the role member
//
Member MemberName `json:"member"`
//
// name of the principal executing the change
//
Admin ResourceName `json:"admin"`
//
// timestamp of the entry
//
Created rdl.Timestamp `json:"created"`
//
// log action - either add or delete
//
Action string `json:"action"`
//
// audit reference string for the change as supplied by admin
//
AuditRef string `json:"auditRef,omitempty" rdl:"optional"`
}
//
// NewRoleAuditLog - creates an initialized RoleAuditLog instance, returns a pointer to it
//
func NewRoleAuditLog(init ...*RoleAuditLog) *RoleAuditLog {
var o *RoleAuditLog
if len(init) == 1 {
o = init[0]
} else {
o = new(RoleAuditLog)
}
return o
}
type rawRoleAuditLog RoleAuditLog
//
// UnmarshalJSON is defined for proper JSON decoding of a RoleAuditLog
//
func (self *RoleAuditLog) UnmarshalJSON(b []byte) error {
var r rawRoleAuditLog
err := json.Unmarshal(b, &r)
if err == nil {
o := RoleAuditLog(r)
*self = o
err = self.Validate()
}
return err
}
//
// Validate - checks for missing required fields, etc
//
func (self *RoleAuditLog) Validate() error {
if self.Member == "" {
return fmt.Errorf("RoleAuditLog.member is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "MemberName", self.Member)
if !val.Valid {
return fmt.Errorf("RoleAuditLog.member does not contain a valid MemberName (%v)", val.Error)
}
}
if self.Admin == "" {
return fmt.Errorf("RoleAuditLog.admin is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "ResourceName", self.Admin)
if !val.Valid {
return fmt.Errorf("RoleAuditLog.admin does not contain a valid ResourceName (%v)", val.Error)
}
}
if self.Created.IsZero() {
return fmt.Errorf("RoleAuditLog: Missing required field: created")
}
if self.Action == "" {
return fmt.Errorf("RoleAuditLog.action is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "String", self.Action)
if !val.Valid {
return fmt.Errorf("RoleAuditLog.action does not contain a valid String (%v)", val.Error)
}
}
return nil
}
//
// RoleMember -
//
type RoleMember struct {
//
// name of the member
//
MemberName MemberName `json:"memberName"`
//
// the expiration timestamp
//
Expiration *rdl.Timestamp `json:"expiration,omitempty" rdl:"optional"`
}
//
// NewRoleMember - creates an initialized RoleMember instance, returns a pointer to it
//
func NewRoleMember(init ...*RoleMember) *RoleMember {
var o *RoleMember
if len(init) == 1 {
o = init[0]
} else {
o = new(RoleMember)
}
return o
}
type rawRoleMember RoleMember
//
// UnmarshalJSON is defined for proper JSON decoding of a RoleMember
//
func (self *RoleMember) UnmarshalJSON(b []byte) error {
var r rawRoleMember
err := json.Unmarshal(b, &r)
if err == nil {
o := RoleMember(r)
*self = o
err = self.Validate()
}
return err
}
//
// Validate - checks for missing required fields, etc
//
func (self *RoleMember) Validate() error {
if self.MemberName == "" {
return fmt.Errorf("RoleMember.memberName is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "MemberName", self.MemberName)
if !val.Valid {
return fmt.Errorf("RoleMember.memberName does not contain a valid MemberName (%v)", val.Error)
}
}
return nil
}
//
// Role - The representation for a Role with set of members.
//
type Role struct {
//
// name of the role
//
Name ResourceName `json:"name"`
//
// last modification timestamp of the role
//
Modified *rdl.Timestamp `json:"modified,omitempty" rdl:"optional"`
//
// an explicit list of members. Might be empty or null, if trust is set
//
Members []MemberName `json:"members,omitempty" rdl:"optional"`
//
// members with expiration
//
RoleMembers []*RoleMember `json:"roleMembers,omitempty" rdl:"optional"`
//
// a trusted domain to delegate membership decisions to
//
Trust DomainName `json:"trust,omitempty" rdl:"optional"`
//
// an audit log for role membership changes
//
AuditLog []*RoleAuditLog `json:"auditLog,omitempty" rdl:"optional"`
}
//
// NewRole - creates an initialized Role instance, returns a pointer to it
//
func NewRole(init ...*Role) *Role {
var o *Role
if len(init) == 1 {
o = init[0]
} else {
o = new(Role)
}
return o
}
type rawRole Role
//
// UnmarshalJSON is defined for proper JSON decoding of a Role
//
func (self *Role) UnmarshalJSON(b []byte) error {
var r rawRole
err := json.Unmarshal(b, &r)
if err == nil {
o := Role(r)
*self = o
err = self.Validate()
}
return err
}
//
// Validate - checks for missing required fields, etc
//
func (self *Role) Validate() error {
if self.Name == "" {
return fmt.Errorf("Role.name is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "ResourceName", self.Name)
if !val.Valid {
return fmt.Errorf("Role.name does not contain a valid ResourceName (%v)", val.Error)
}
}
return nil
}
//
// Roles - The representation for a list of roles with full details
//
type Roles struct {
//
// list of role objects
//
List []*Role `json:"list"`
}
//
// NewRoles - creates an initialized Roles instance, returns a pointer to it
//
func NewRoles(init ...*Roles) *Roles {
var o *Roles
if len(init) == 1 {
o = init[0]
} else {
o = new(Roles)
}
return o.Init()
}
//
// Init - sets up the instance according to its default field values, if any
//
func (self *Roles) Init() *Roles {
if self.List == nil {
self.List = make([]*Role, 0)
}
return self
}
type rawRoles Roles
//
// UnmarshalJSON is defined for proper JSON decoding of a Roles
//
func (self *Roles) UnmarshalJSON(b []byte) error {
var r rawRoles
err := json.Unmarshal(b, &r)
if err == nil {
o := Roles(r)
*self = *((&o).Init())
err = self.Validate()
}
return err
}
//
// Validate - checks for missing required fields, etc
//
func (self *Roles) Validate() error {
if self.List == nil {
return fmt.Errorf("Roles: Missing required field: list")
}
return nil
}
//
// Membership - The representation for a role membership.
//
type Membership struct {
//
// name of the member
//
MemberName MemberName `json:"memberName"`
//
// flag to indicate whether or the user is a member or not
//
IsMember *bool `json:"isMember,omitempty" rdl:"optional"`
//
// name of the role
//
RoleName ResourceName `json:"roleName,omitempty" rdl:"optional"`
//
// the expiration timestamp
//
Expiration *rdl.Timestamp `json:"expiration,omitempty" rdl:"optional"`
}
//
// NewMembership - creates an initialized Membership instance, returns a pointer to it
//
func NewMembership(init ...*Membership) *Membership {
var o *Membership
if len(init) == 1 {
o = init[0]
} else {
o = new(Membership)
}
return o.Init()
}
//
// Init - sets up the instance according to its default field values, if any
//
func (self *Membership) Init() *Membership {
if self.IsMember == nil {
d := true
self.IsMember = &d
}
return self
}
type rawMembership Membership
//
// UnmarshalJSON is defined for proper JSON decoding of a Membership
//
func (self *Membership) UnmarshalJSON(b []byte) error {
var r rawMembership
err := json.Unmarshal(b, &r)
if err == nil {
o := Membership(r)
*self = *((&o).Init())
err = self.Validate()
}
return err
}
//
// Validate - checks for missing required fields, etc
//
func (self *Membership) Validate() error {
if self.MemberName == "" {
return fmt.Errorf("Membership.memberName is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "MemberName", self.MemberName)
if !val.Valid {
return fmt.Errorf("Membership.memberName does not contain a valid MemberName (%v)", val.Error)
}
}
return nil
}
//
// DefaultAdmins - The list of domain administrators.
//
type DefaultAdmins struct {
//
// list of domain administrators
//
Admins []ResourceName `json:"admins"`
}
//
// NewDefaultAdmins - creates an initialized DefaultAdmins instance, returns a pointer to it
//
func NewDefaultAdmins(init ...*DefaultAdmins) *DefaultAdmins {
var o *DefaultAdmins
if len(init) == 1 {
o = init[0]
} else {
o = new(DefaultAdmins)
}
return o.Init()
}
//
// Init - sets up the instance according to its default field values, if any
//
func (self *DefaultAdmins) Init() *DefaultAdmins {
if self.Admins == nil {
self.Admins = make([]ResourceName, 0)
}
return self
}
type rawDefaultAdmins DefaultAdmins
//
// UnmarshalJSON is defined for proper JSON decoding of a DefaultAdmins
//
func (self *DefaultAdmins) UnmarshalJSON(b []byte) error {
var r rawDefaultAdmins
err := json.Unmarshal(b, &r)
if err == nil {
o := DefaultAdmins(r)
*self = *((&o).Init())
err = self.Validate()
}
return err
}
//
// Validate - checks for missing required fields, etc
//
func (self *DefaultAdmins) Validate() error {
if self.Admins == nil {
return fmt.Errorf("DefaultAdmins: Missing required field: admins")
}
return nil
}
//
// AssertionEffect - Every assertion can have the effect of ALLOW or DENY.
//
type AssertionEffect int
//
// AssertionEffect constants
//
const (
_ AssertionEffect = iota
ALLOW
DENY
)
var namesAssertionEffect = []string{
ALLOW: "ALLOW",
DENY: "DENY",
}
//
// NewAssertionEffect - return a string representation of the enum
//
func NewAssertionEffect(init ...interface{}) AssertionEffect {
if len(init) == 1 {
switch v := init[0].(type) {
case AssertionEffect:
return v
case int:
return AssertionEffect(v)
case int32:
return AssertionEffect(v)
case string:
for i, s := range namesAssertionEffect {
if s == v {
return AssertionEffect(i)
}
}
default:
panic("Bad init value for AssertionEffect enum")
}
}
return AssertionEffect(0) //default to the first enum value
}
//
// String - return a string representation of the enum
//
func (e AssertionEffect) String() string {
return namesAssertionEffect[e]
}
//
// SymbolSet - return an array of all valid string representations (symbols) of the enum
//
func (e AssertionEffect) SymbolSet() []string {
return namesAssertionEffect
}
//
// MarshalJSON is defined for proper JSON encoding of a AssertionEffect
//
func (e AssertionEffect) MarshalJSON() ([]byte, error) {
return json.Marshal(e.String())
}
//
// UnmarshalJSON is defined for proper JSON decoding of a AssertionEffect
//
func (e *AssertionEffect) UnmarshalJSON(b []byte) error {
var j string
err := json.Unmarshal(b, &j)
if err == nil {
s := string(j)
for v, s2 := range namesAssertionEffect {
if s == s2 {
*e = AssertionEffect(v)
return nil
}
}
err = fmt.Errorf("Bad enum symbol for type AssertionEffect: %s", s)
}
return err
}
//
// Assertion - A representation for the encapsulation of an action to be
// performed on a resource by a principal.
//
type Assertion struct {
//
// the subject of the assertion - a role
//
Role string `json:"role"`
//
// the object of the assertion. Must be in the local namespace. Can contain
// wildcards
//
Resource string `json:"resource"`
//
// the predicate of the assertion. Can contain wildcards
//
Action string `json:"action"`
//
// the effect of the assertion in the policy language
//
Effect *AssertionEffect `json:"effect,omitempty" rdl:"optional"`
//
// assertion id - auto generated by server. Not required during put
// operations.
//
Id *int64 `json:"id,omitempty" rdl:"optional"`
}
//
// NewAssertion - creates an initialized Assertion instance, returns a pointer to it
//
func NewAssertion(init ...*Assertion) *Assertion {
var o *Assertion
if len(init) == 1 {
o = init[0]
} else {
o = new(Assertion)
}
return o
}
type rawAssertion Assertion
//
// UnmarshalJSON is defined for proper JSON decoding of a Assertion
//
func (self *Assertion) UnmarshalJSON(b []byte) error {
var r rawAssertion
err := json.Unmarshal(b, &r)
if err == nil {
o := Assertion(r)
*self = o
err = self.Validate()
}
return err
}
//
// Validate - checks for missing required fields, etc
//
func (self *Assertion) Validate() error {
if self.Role == "" {
return fmt.Errorf("Assertion.role is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "String", self.Role)
if !val.Valid {
return fmt.Errorf("Assertion.role does not contain a valid String (%v)", val.Error)
}
}
if self.Resource == "" {
return fmt.Errorf("Assertion.resource is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "String", self.Resource)
if !val.Valid {
return fmt.Errorf("Assertion.resource does not contain a valid String (%v)", val.Error)
}
}
if self.Action == "" {
return fmt.Errorf("Assertion.action is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "String", self.Action)
if !val.Valid {
return fmt.Errorf("Assertion.action does not contain a valid String (%v)", val.Error)
}
}
return nil
}
//
// Policy - The representation for a Policy with set of assertions.
//
type Policy struct {
//
// name of the policy
//
Name ResourceName `json:"name"`
//
// last modification timestamp of this policy
//
Modified *rdl.Timestamp `json:"modified,omitempty" rdl:"optional"`
//
// list of defined assertions for this policy
//
Assertions []*Assertion `json:"assertions"`
}
//
// NewPolicy - creates an initialized Policy instance, returns a pointer to it
//
func NewPolicy(init ...*Policy) *Policy {
var o *Policy
if len(init) == 1 {
o = init[0]
} else {
o = new(Policy)
}
return o.Init()
}
//
// Init - sets up the instance according to its default field values, if any
//
func (self *Policy) Init() *Policy {
if self.Assertions == nil {
self.Assertions = make([]*Assertion, 0)
}
return self
}
type rawPolicy Policy
//
// UnmarshalJSON is defined for proper JSON decoding of a Policy
//
func (self *Policy) UnmarshalJSON(b []byte) error {
var r rawPolicy
err := json.Unmarshal(b, &r)
if err == nil {
o := Policy(r)
*self = *((&o).Init())
err = self.Validate()
}
return err
}
//
// Validate - checks for missing required fields, etc
//
func (self *Policy) Validate() error {
if self.Name == "" {
return fmt.Errorf("Policy.name is missing but is a required field")
} else {
val := rdl.Validate(ZMSSchema(), "ResourceName", self.Name)
if !val.Valid {
return fmt.Errorf("Policy.name does not contain a valid ResourceName (%v)", val.Error)
}
}
if self.Assertions == nil {
return fmt.Errorf("Policy: Missing required field: assertions")
}
return nil
}
//
// Policies - The representation of list of policy objects
//
type Policies struct {
//
// list of policy objects
//
List []*Policy `json:"list"`
}
//
// NewPolicies - creates an initialized Policies instance, returns a pointer to it
//
func NewPolicies(init ...*Policies) *Policies {
var o *Policies
if len(init) == 1 {
o = init[0]
} else {
o = new(Policies)
}
return o.Init()
}
//
// Init - sets up the instance according to its default field values, if any
//
func (self *Policies) Init() *Policies {