This repository has been archived by the owner on Sep 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
service_provider_config_gen.go
816 lines (757 loc) · 23.6 KB
/
service_provider_config_gen.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
// Generated by "sketch" utility. DO NOT EDIT
package resource
import (
"bytes"
"encoding/json"
"fmt"
"sort"
"sync"
"github.com/lestrrat-go/blackmagic"
)
const ServiceProviderConfigSchemaURI = "urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"
func init() {
Register("ServiceProviderConfig", ServiceProviderConfigSchemaURI, ServiceProviderConfig{})
RegisterBuilder("ServiceProviderConfig", ServiceProviderConfigSchemaURI, ServiceProviderConfigBuilder{})
}
type ServiceProviderConfig struct {
mu sync.RWMutex
authenticationSchemes []*AuthenticationScheme
bulk *BulkSupport
changePassword *GenericSupport
documentationURI *string
etag *GenericSupport
filter *FilterSupport
patch *GenericSupport
schemas *schemas
sort *GenericSupport
extra map[string]interface{}
}
// These constants are used when the JSON field name is used.
// Their use is not strictly required, but certain linters
// complain about repeated constants, and therefore internally
// this used throughout
const (
ServiceProviderConfigAuthenticationSchemesKey = "authenticationSchemes"
ServiceProviderConfigBulkKey = "bulk"
ServiceProviderConfigChangePasswordKey = "changePassword"
ServiceProviderConfigDocumentationURIKey = "documentationUri"
ServiceProviderConfigETagKey = "etag"
ServiceProviderConfigFilterKey = "filter"
ServiceProviderConfigPatchKey = "patch"
ServiceProviderConfigSchemasKey = "schemas"
ServiceProviderConfigSortKey = "sort"
)
// Get retrieves the value associated with a key
func (v *ServiceProviderConfig) Get(key string, dst interface{}) error {
v.mu.RLock()
defer v.mu.RUnlock()
return v.getNoLock(key, dst, false)
}
// getNoLock is a utility method that is called from Get, MarshalJSON, etc, but
// it can be used from user-supplied code. Unlike Get, it avoids locking for
// each call, so the user needs to explicitly lock the object before using,
// but otherwise should be faster than sing Get directly
func (v *ServiceProviderConfig) getNoLock(key string, dst interface{}, raw bool) error {
switch key {
case ServiceProviderConfigAuthenticationSchemesKey:
if val := v.authenticationSchemes; val != nil {
return blackmagic.AssignIfCompatible(dst, val)
}
case ServiceProviderConfigBulkKey:
if val := v.bulk; val != nil {
return blackmagic.AssignIfCompatible(dst, val)
}
case ServiceProviderConfigChangePasswordKey:
if val := v.changePassword; val != nil {
return blackmagic.AssignIfCompatible(dst, val)
}
case ServiceProviderConfigDocumentationURIKey:
if val := v.documentationURI; val != nil {
return blackmagic.AssignIfCompatible(dst, *val)
}
case ServiceProviderConfigETagKey:
if val := v.etag; val != nil {
return blackmagic.AssignIfCompatible(dst, val)
}
case ServiceProviderConfigFilterKey:
if val := v.filter; val != nil {
return blackmagic.AssignIfCompatible(dst, val)
}
case ServiceProviderConfigPatchKey:
if val := v.patch; val != nil {
return blackmagic.AssignIfCompatible(dst, val)
}
case ServiceProviderConfigSchemasKey:
if val := v.schemas; val != nil {
if raw {
return blackmagic.AssignIfCompatible(dst, val)
}
return blackmagic.AssignIfCompatible(dst, val.GetValue())
}
case ServiceProviderConfigSortKey:
if val := v.sort; val != nil {
return blackmagic.AssignIfCompatible(dst, val)
}
default:
if v.extra != nil {
val, ok := v.extra[key]
if ok {
return blackmagic.AssignIfCompatible(dst, val)
}
}
}
return fmt.Errorf(`no such key %q`, key)
}
// Set sets the value of the specified field. The name must be a JSON
// field name, not the Go name
func (v *ServiceProviderConfig) Set(key string, value interface{}) error {
v.mu.Lock()
defer v.mu.Unlock()
switch key {
case ServiceProviderConfigAuthenticationSchemesKey:
converted, ok := value.([]*AuthenticationScheme)
if !ok {
return fmt.Errorf(`expected value of type []*AuthenticationScheme for field authenticationSchemes, got %T`, value)
}
v.authenticationSchemes = converted
case ServiceProviderConfigBulkKey:
converted, ok := value.(*BulkSupport)
if !ok {
return fmt.Errorf(`expected value of type *BulkSupport for field bulk, got %T`, value)
}
v.bulk = converted
case ServiceProviderConfigChangePasswordKey:
converted, ok := value.(*GenericSupport)
if !ok {
return fmt.Errorf(`expected value of type *GenericSupport for field changePassword, got %T`, value)
}
v.changePassword = converted
case ServiceProviderConfigDocumentationURIKey:
converted, ok := value.(string)
if !ok {
return fmt.Errorf(`expected value of type string for field documentationUri, got %T`, value)
}
v.documentationURI = &converted
case ServiceProviderConfigETagKey:
converted, ok := value.(*GenericSupport)
if !ok {
return fmt.Errorf(`expected value of type *GenericSupport for field etag, got %T`, value)
}
v.etag = converted
case ServiceProviderConfigFilterKey:
converted, ok := value.(*FilterSupport)
if !ok {
return fmt.Errorf(`expected value of type *FilterSupport for field filter, got %T`, value)
}
v.filter = converted
case ServiceProviderConfigPatchKey:
converted, ok := value.(*GenericSupport)
if !ok {
return fmt.Errorf(`expected value of type *GenericSupport for field patch, got %T`, value)
}
v.patch = converted
case ServiceProviderConfigSchemasKey:
var object schemas
if err := object.AcceptValue(value); err != nil {
return fmt.Errorf(`failed to accept value: %w`, err)
}
v.schemas = &object
case ServiceProviderConfigSortKey:
converted, ok := value.(*GenericSupport)
if !ok {
return fmt.Errorf(`expected value of type *GenericSupport for field sort, got %T`, value)
}
v.sort = converted
default:
if v.extra == nil {
v.extra = make(map[string]interface{})
}
v.extra[key] = value
}
return nil
}
// Has returns true if the field specified by the argument has been populated.
// The field name must be the JSON field name, not the Go-structure's field name.
func (v *ServiceProviderConfig) Has(name string) bool {
switch name {
case ServiceProviderConfigAuthenticationSchemesKey:
return v.authenticationSchemes != nil
case ServiceProviderConfigBulkKey:
return v.bulk != nil
case ServiceProviderConfigChangePasswordKey:
return v.changePassword != nil
case ServiceProviderConfigDocumentationURIKey:
return v.documentationURI != nil
case ServiceProviderConfigETagKey:
return v.etag != nil
case ServiceProviderConfigFilterKey:
return v.filter != nil
case ServiceProviderConfigPatchKey:
return v.patch != nil
case ServiceProviderConfigSchemasKey:
return v.schemas != nil
case ServiceProviderConfigSortKey:
return v.sort != nil
default:
if v.extra != nil {
if _, ok := v.extra[name]; ok {
return true
}
}
return false
}
}
// Keys returns a slice of string comprising of JSON field names whose values
// are present in the object.
func (v *ServiceProviderConfig) Keys() []string {
keys := make([]string, 0, 9)
if v.authenticationSchemes != nil {
keys = append(keys, ServiceProviderConfigAuthenticationSchemesKey)
}
if v.bulk != nil {
keys = append(keys, ServiceProviderConfigBulkKey)
}
if v.changePassword != nil {
keys = append(keys, ServiceProviderConfigChangePasswordKey)
}
if v.documentationURI != nil {
keys = append(keys, ServiceProviderConfigDocumentationURIKey)
}
if v.etag != nil {
keys = append(keys, ServiceProviderConfigETagKey)
}
if v.filter != nil {
keys = append(keys, ServiceProviderConfigFilterKey)
}
if v.patch != nil {
keys = append(keys, ServiceProviderConfigPatchKey)
}
if v.schemas != nil {
keys = append(keys, ServiceProviderConfigSchemasKey)
}
if v.sort != nil {
keys = append(keys, ServiceProviderConfigSortKey)
}
if len(v.extra) > 0 {
for k := range v.extra {
keys = append(keys, k)
}
}
sort.Strings(keys)
return keys
}
// HasAuthenticationSchemes returns true if the field `authenticationSchemes` has been populated
func (v *ServiceProviderConfig) HasAuthenticationSchemes() bool {
v.mu.RLock()
defer v.mu.RUnlock()
return v.authenticationSchemes != nil
}
// HasBulk returns true if the field `bulk` has been populated
func (v *ServiceProviderConfig) HasBulk() bool {
v.mu.RLock()
defer v.mu.RUnlock()
return v.bulk != nil
}
// HasChangePassword returns true if the field `changePassword` has been populated
func (v *ServiceProviderConfig) HasChangePassword() bool {
v.mu.RLock()
defer v.mu.RUnlock()
return v.changePassword != nil
}
// HasDocumentationURI returns true if the field `documentationUri` has been populated
func (v *ServiceProviderConfig) HasDocumentationURI() bool {
v.mu.RLock()
defer v.mu.RUnlock()
return v.documentationURI != nil
}
// HasETag returns true if the field `etag` has been populated
func (v *ServiceProviderConfig) HasETag() bool {
v.mu.RLock()
defer v.mu.RUnlock()
return v.etag != nil
}
// HasFilter returns true if the field `filter` has been populated
func (v *ServiceProviderConfig) HasFilter() bool {
v.mu.RLock()
defer v.mu.RUnlock()
return v.filter != nil
}
// HasPatch returns true if the field `patch` has been populated
func (v *ServiceProviderConfig) HasPatch() bool {
v.mu.RLock()
defer v.mu.RUnlock()
return v.patch != nil
}
// HasSchemas returns true if the field `schemas` has been populated
func (v *ServiceProviderConfig) HasSchemas() bool {
v.mu.RLock()
defer v.mu.RUnlock()
return v.schemas != nil
}
// HasSort returns true if the field `sort` has been populated
func (v *ServiceProviderConfig) HasSort() bool {
v.mu.RLock()
defer v.mu.RUnlock()
return v.sort != nil
}
func (v *ServiceProviderConfig) AuthenticationSchemes() []*AuthenticationScheme {
v.mu.RLock()
defer v.mu.RUnlock()
if val := v.authenticationSchemes; val != nil {
return val
}
return nil
}
func (v *ServiceProviderConfig) Bulk() *BulkSupport {
v.mu.RLock()
defer v.mu.RUnlock()
if val := v.bulk; val != nil {
return val
}
return nil
}
func (v *ServiceProviderConfig) ChangePassword() *GenericSupport {
v.mu.RLock()
defer v.mu.RUnlock()
if val := v.changePassword; val != nil {
return val
}
return nil
}
func (v *ServiceProviderConfig) DocumentationURI() string {
v.mu.RLock()
defer v.mu.RUnlock()
if val := v.documentationURI; val != nil {
return *val
}
return ""
}
func (v *ServiceProviderConfig) ETag() *GenericSupport {
v.mu.RLock()
defer v.mu.RUnlock()
if val := v.etag; val != nil {
return val
}
return nil
}
func (v *ServiceProviderConfig) Filter() *FilterSupport {
v.mu.RLock()
defer v.mu.RUnlock()
if val := v.filter; val != nil {
return val
}
return nil
}
func (v *ServiceProviderConfig) Patch() *GenericSupport {
v.mu.RLock()
defer v.mu.RUnlock()
if val := v.patch; val != nil {
return val
}
return nil
}
func (v *ServiceProviderConfig) Schemas() []string {
v.mu.RLock()
defer v.mu.RUnlock()
if val := v.schemas; val != nil {
return val.GetValue()
}
return nil
}
func (v *ServiceProviderConfig) Sort() *GenericSupport {
v.mu.RLock()
defer v.mu.RUnlock()
if val := v.sort; val != nil {
return val
}
return nil
}
// Remove removes the value associated with a key
func (v *ServiceProviderConfig) Remove(key string) error {
v.mu.Lock()
defer v.mu.Unlock()
switch key {
case ServiceProviderConfigAuthenticationSchemesKey:
v.authenticationSchemes = nil
case ServiceProviderConfigBulkKey:
v.bulk = nil
case ServiceProviderConfigChangePasswordKey:
v.changePassword = nil
case ServiceProviderConfigDocumentationURIKey:
v.documentationURI = nil
case ServiceProviderConfigETagKey:
v.etag = nil
case ServiceProviderConfigFilterKey:
v.filter = nil
case ServiceProviderConfigPatchKey:
v.patch = nil
case ServiceProviderConfigSchemasKey:
v.schemas = nil
case ServiceProviderConfigSortKey:
v.sort = nil
default:
delete(v.extra, key)
}
return nil
}
func (v *ServiceProviderConfig) Clone(dst interface{}) error {
v.mu.RLock()
defer v.mu.RUnlock()
var extra map[string]interface{}
if len(v.extra) > 0 {
extra = make(map[string]interface{})
for key, val := range v.extra {
extra[key] = val
}
}
return blackmagic.AssignIfCompatible(dst, &ServiceProviderConfig{
authenticationSchemes: v.authenticationSchemes,
bulk: v.bulk,
changePassword: v.changePassword,
documentationURI: v.documentationURI,
etag: v.etag,
filter: v.filter,
patch: v.patch,
schemas: v.schemas,
sort: v.sort,
extra: extra,
})
}
// MarshalJSON serializes ServiceProviderConfig into JSON.
// All pre-declared fields are included as long as a value is
// assigned to them, as well as all extra fields. All of these
// fields are sorted in alphabetical order.
func (v *ServiceProviderConfig) MarshalJSON() ([]byte, error) {
v.mu.RLock()
defer v.mu.RUnlock()
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
buf.WriteByte('{')
for i, k := range v.Keys() {
var val interface{}
if err := v.getNoLock(k, &val, true); err != nil {
return nil, fmt.Errorf(`failed to retrieve value for field %q: %w`, k, err)
}
if i > 0 {
buf.WriteByte(',')
}
if err := enc.Encode(k); err != nil {
return nil, fmt.Errorf(`failed to encode map key name: %w`, err)
}
buf.WriteByte(':')
if err := enc.Encode(val); err != nil {
return nil, fmt.Errorf(`failed to encode map value for %q: %w`, k, err)
}
}
buf.WriteByte('}')
return buf.Bytes(), nil
}
// UnmarshalJSON deserializes a piece of JSON data into ServiceProviderConfig.
//
// Pre-defined fields must be deserializable via "encoding/json" to their
// respective Go types, otherwise an error is returned.
//
// Extra fields are stored in a special "extra" storage, which can only
// be accessed via `Get()` and `Set()` methods.
func (v *ServiceProviderConfig) UnmarshalJSON(data []byte) error {
v.mu.Lock()
defer v.mu.Unlock()
v.authenticationSchemes = nil
v.bulk = nil
v.changePassword = nil
v.documentationURI = nil
v.etag = nil
v.filter = nil
v.patch = nil
v.schemas = nil
v.sort = nil
dec := json.NewDecoder(bytes.NewReader(data))
var extra map[string]interface{}
LOOP:
for {
tok, err := dec.Token()
if err != nil {
return fmt.Errorf(`error reading JSON token: %w`, err)
}
switch tok := tok.(type) {
case json.Delim:
if tok == '}' { // end of object
break LOOP
}
// we should only get into this clause at the very beginning, and just once
if tok != '{' {
return fmt.Errorf(`expected '{', but got '%c'`, tok)
}
case string:
switch tok {
case ServiceProviderConfigAuthenticationSchemesKey:
var val []*AuthenticationScheme
if err := dec.Decode(&val); err != nil {
return fmt.Errorf(`failed to decode value for %q: %w`, ServiceProviderConfigAuthenticationSchemesKey, err)
}
v.authenticationSchemes = val
case ServiceProviderConfigBulkKey:
var val BulkSupport
if err := dec.Decode(&val); err != nil {
return fmt.Errorf(`failed to decode value for %q: %w`, ServiceProviderConfigBulkKey, err)
}
v.bulk = &val
case ServiceProviderConfigChangePasswordKey:
var val GenericSupport
if err := dec.Decode(&val); err != nil {
return fmt.Errorf(`failed to decode value for %q: %w`, ServiceProviderConfigChangePasswordKey, err)
}
v.changePassword = &val
case ServiceProviderConfigDocumentationURIKey:
var val string
if err := dec.Decode(&val); err != nil {
return fmt.Errorf(`failed to decode value for %q: %w`, ServiceProviderConfigDocumentationURIKey, err)
}
v.documentationURI = &val
case ServiceProviderConfigETagKey:
var val GenericSupport
if err := dec.Decode(&val); err != nil {
return fmt.Errorf(`failed to decode value for %q: %w`, ServiceProviderConfigETagKey, err)
}
v.etag = &val
case ServiceProviderConfigFilterKey:
var val FilterSupport
if err := dec.Decode(&val); err != nil {
return fmt.Errorf(`failed to decode value for %q: %w`, ServiceProviderConfigFilterKey, err)
}
v.filter = &val
case ServiceProviderConfigPatchKey:
var val GenericSupport
if err := dec.Decode(&val); err != nil {
return fmt.Errorf(`failed to decode value for %q: %w`, ServiceProviderConfigPatchKey, err)
}
v.patch = &val
case ServiceProviderConfigSchemasKey:
var acceptValue interface{}
if err := dec.Decode(&acceptValue); err != nil {
return fmt.Errorf(`failed to decode vlaue for %q: %w`, ServiceProviderConfigSchemasKey, err)
}
var val schemas
err = val.AcceptValue(acceptValue)
if err != nil {
return fmt.Errorf(`failed to accept value for %q: %w`, ServiceProviderConfigSchemasKey, err)
}
v.schemas = &val
case ServiceProviderConfigSortKey:
var val GenericSupport
if err := dec.Decode(&val); err != nil {
return fmt.Errorf(`failed to decode value for %q: %w`, ServiceProviderConfigSortKey, err)
}
v.sort = &val
default:
var val interface{}
if err := v.decodeExtraField(tok, dec, &val); err != nil {
return fmt.Errorf(`failed to decode value for %q: %w`, tok, err)
}
if extra == nil {
extra = make(map[string]interface{})
}
extra[tok] = val
}
}
}
if v.authenticationSchemes == nil {
return fmt.Errorf(`required field authenticationSchemes is missing for object ServiceProviderConfig`)
}
if v.bulk == nil {
return fmt.Errorf(`required field bulk is missing for object ServiceProviderConfig`)
}
if v.changePassword == nil {
return fmt.Errorf(`required field changePassword is missing for object ServiceProviderConfig`)
}
if v.filter == nil {
return fmt.Errorf(`required field filter is missing for object ServiceProviderConfig`)
}
if v.patch == nil {
return fmt.Errorf(`required field patch is missing for object ServiceProviderConfig`)
}
if v.sort == nil {
return fmt.Errorf(`required field sort is missing for object ServiceProviderConfig`)
}
if extra != nil {
v.extra = extra
}
return nil
}
type ServiceProviderConfigBuilder struct {
mu sync.Mutex
err error
once sync.Once
object *ServiceProviderConfig
}
// NewServiceProviderConfigBuilder creates a new ServiceProviderConfigBuilder instance.
// ServiceProviderConfigBuilder is safe to be used uninitialized as well.
func NewServiceProviderConfigBuilder() *ServiceProviderConfigBuilder {
return &ServiceProviderConfigBuilder{}
}
func (b *ServiceProviderConfigBuilder) initialize() {
b.err = nil
b.object = &ServiceProviderConfig{}
b.object.schemas = &schemas{}
b.object.schemas.Add(ServiceProviderConfigSchemaURI)
}
func (b *ServiceProviderConfigBuilder) AuthenticationSchemes(in ...*AuthenticationScheme) *ServiceProviderConfigBuilder {
return b.SetField(ServiceProviderConfigAuthenticationSchemesKey, in)
}
func (b *ServiceProviderConfigBuilder) Bulk(in *BulkSupport) *ServiceProviderConfigBuilder {
return b.SetField(ServiceProviderConfigBulkKey, in)
}
func (b *ServiceProviderConfigBuilder) ChangePassword(in *GenericSupport) *ServiceProviderConfigBuilder {
return b.SetField(ServiceProviderConfigChangePasswordKey, in)
}
func (b *ServiceProviderConfigBuilder) DocumentationURI(in string) *ServiceProviderConfigBuilder {
return b.SetField(ServiceProviderConfigDocumentationURIKey, in)
}
func (b *ServiceProviderConfigBuilder) ETag(in *GenericSupport) *ServiceProviderConfigBuilder {
return b.SetField(ServiceProviderConfigETagKey, in)
}
func (b *ServiceProviderConfigBuilder) Filter(in *FilterSupport) *ServiceProviderConfigBuilder {
return b.SetField(ServiceProviderConfigFilterKey, in)
}
func (b *ServiceProviderConfigBuilder) Patch(in *GenericSupport) *ServiceProviderConfigBuilder {
return b.SetField(ServiceProviderConfigPatchKey, in)
}
func (b *ServiceProviderConfigBuilder) Schemas(in ...string) *ServiceProviderConfigBuilder {
return b.SetField(ServiceProviderConfigSchemasKey, in)
}
func (b *ServiceProviderConfigBuilder) Sort(in *GenericSupport) *ServiceProviderConfigBuilder {
return b.SetField(ServiceProviderConfigSortKey, in)
}
// SetField sets the value of any field. The name should be the JSON field name.
// Type check will only be performed for pre-defined types
func (b *ServiceProviderConfigBuilder) SetField(name string, value interface{}) *ServiceProviderConfigBuilder {
b.mu.Lock()
defer b.mu.Unlock()
b.once.Do(b.initialize)
if b.err != nil {
return b
}
if err := b.object.Set(name, value); err != nil {
b.err = err
}
return b
}
func (b *ServiceProviderConfigBuilder) Build() (*ServiceProviderConfig, error) {
b.mu.Lock()
defer b.mu.Unlock()
b.once.Do(b.initialize)
if b.err != nil {
return nil, b.err
}
if b.object.authenticationSchemes == nil {
return nil, fmt.Errorf("required field 'AuthenticationSchemes' not initialized")
}
if b.object.bulk == nil {
return nil, fmt.Errorf("required field 'Bulk' not initialized")
}
if b.object.changePassword == nil {
return nil, fmt.Errorf("required field 'ChangePassword' not initialized")
}
if b.object.filter == nil {
return nil, fmt.Errorf("required field 'Filter' not initialized")
}
if b.object.patch == nil {
return nil, fmt.Errorf("required field 'Patch' not initialized")
}
if b.object.sort == nil {
return nil, fmt.Errorf("required field 'Sort' not initialized")
}
obj := b.object
b.once = sync.Once{}
b.once.Do(b.initialize)
return obj, nil
}
func (b *ServiceProviderConfigBuilder) MustBuild() *ServiceProviderConfig {
object, err := b.Build()
if err != nil {
panic(err)
}
return object
}
func (b *ServiceProviderConfigBuilder) From(in *ServiceProviderConfig) *ServiceProviderConfigBuilder {
b.mu.Lock()
defer b.mu.Unlock()
b.once.Do(b.initialize)
if b.err != nil {
return b
}
var cloned ServiceProviderConfig
if err := in.Clone(&cloned); err != nil {
b.err = err
return b
}
b.object = &cloned
return b
}
func (b *ServiceProviderConfigBuilder) Extension(uri string, value interface{}) *ServiceProviderConfigBuilder {
b.mu.Lock()
defer b.mu.Unlock()
b.once.Do(b.initialize)
if b.err != nil {
return b
}
if b.object.schemas == nil {
b.object.schemas = &schemas{}
b.object.schemas.Add(ServiceProviderConfigSchemaURI)
}
b.object.schemas.Add(uri)
if err := b.object.Set(uri, value); err != nil {
b.err = err
}
return b
}
// AsMap returns the resource as a Go map
func (v *ServiceProviderConfig) AsMap(m map[string]interface{}) error {
v.mu.RLock()
defer v.mu.RUnlock()
for _, key := range v.Keys() {
var val interface{}
if err := v.getNoLock(key, &val, false); err != nil {
return fmt.Errorf(`failed to retrieve value for key %q: %w`, key, err)
}
m[key] = val
}
return nil
}
// GetExtension takes into account extension uri, and fetches
// the specified attribute from the extension object
func (v *ServiceProviderConfig) GetExtension(name, uri string, dst interface{}) error {
if uri == "" {
return v.Get(name, dst)
}
var ext interface{}
if err := v.Get(uri, &ext); err != nil {
return fmt.Errorf(`failed to fetch extension %q: %w`, uri, err)
}
getter, ok := ext.(interface {
Get(string, interface{}) error
})
if !ok {
return fmt.Errorf(`extension does not implement Get(string, interface{}) error`)
}
return getter.Get(name, dst)
}
func (*ServiceProviderConfig) decodeExtraField(name string, dec *json.Decoder, dst interface{}) error {
// we can get an instance of the resource object
if rx, ok := registry.LookupByURI(name); ok {
if err := dec.Decode(&rx); err != nil {
return fmt.Errorf(`failed to decode value for key %q: %w`, name, err)
}
if err := blackmagic.AssignIfCompatible(dst, rx); err != nil {
return err
}
} else {
if err := dec.Decode(dst); err != nil {
return fmt.Errorf(`failed to decode value for key %q: %w`, name, err)
}
}
return nil
}
func (b *Builder) ServiceProviderConfig() *ServiceProviderConfigBuilder {
return &ServiceProviderConfigBuilder{}
}