-
Notifications
You must be signed in to change notification settings - Fork 6
/
types.go
912 lines (776 loc) · 30.2 KB
/
types.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
package cbmgr
import (
"encoding/json"
"fmt"
"net/url"
"sort"
"strconv"
"strings"
)
type RebalanceStatus string
const (
RebalanceStatusNotRunning RebalanceStatus = "notRunning"
RebalanceStatusRunning RebalanceStatus = "running"
RebalanceStatusUnknown RebalanceStatus = "unknown"
RebalanceStatusNone RebalanceStatus = "none"
)
type IndexStorageMode string
const (
IndexStorageNone IndexStorageMode = ""
IndexStoragePlasma IndexStorageMode = "plasma"
IndexStorageMOI IndexStorageMode = "memory_optimized"
)
type AvailableStorageType string
const (
StorageTypeHDD AvailableStorageType = "hdd"
StorageTypeSSD AvailableStorageType = "ssd"
)
type IndexLogLevel string
const (
IndexLogLevelDebug IndexLogLevel = "debug"
IndexLogLevelError IndexLogLevel = "error"
IndexLogLevelFatal IndexLogLevel = "fatal"
IndexLogLevelInfo IndexLogLevel = "info"
IndexLogLevelSilent IndexLogLevel = "silent"
IndexLogLevelTiming IndexLogLevel = "timing"
IndexLogLevelTrace IndexLogLevel = "trace"
IndexLogLevelVerbose IndexLogLevel = "verbose"
IndexLogLevelWarn IndexLogLevel = "warn"
)
type ServiceName string
const (
DataService ServiceName = "kv"
IndexService ServiceName = "index"
QueryService ServiceName = "n1ql"
SearchService ServiceName = "fts"
EventingService ServiceName = "eventing"
AnalyticsService ServiceName = "cbas"
)
type ServiceList []ServiceName
func ServiceListFromStringArray(arr []string) (ServiceList, error) {
list := []ServiceName{}
for _, svc := range arr {
if svc == "kv" || svc == "data" {
list = append(list, DataService)
} else if svc == "index" {
list = append(list, IndexService)
} else if svc == "n1ql" || svc == "query" {
list = append(list, QueryService)
} else if svc == "fts" || svc == "search" {
list = append(list, SearchService)
} else if svc == "eventing" {
list = append(list, EventingService)
} else if svc == "cbas" || svc == "analytics" {
list = append(list, AnalyticsService)
} else {
return list, fmt.Errorf("invalid service name: %s", svc)
}
}
return list, nil
}
func (s ServiceList) String() string {
strs := []string{}
for _, svc := range s {
strs = append(strs, (string)(svc))
}
return strings.Join(strs, ",")
}
type RecoveryType string
const (
RecoveryTypeDelta RecoveryType = "delta"
RecoveryTypeFull RecoveryType = "full"
)
type ClusterInfo struct {
SearchMemoryQuotaMB int64 `json:"ftsMemoryQuota"`
IndexMemoryQuotaMB int64 `json:"indexMemoryQuota"`
DataMemoryQuotaMB int64 `json:"memoryQuota"`
EventingMemoryQuotaMB int64 `json:"eventingMemoryQuota"`
AnalyticsMemoryQuotaMB int64 `json:"cbasMemoryQuota"`
Nodes []NodeInfo `json:"nodes"`
RebalanceStatus string `json:"rebalanceStatus"`
ClusterName string `json:"clusterName"`
Balanced bool `json:"balanced"`
}
// PoolsDefaults returns a struct which could be used with the /pools/default API
func (c *ClusterInfo) PoolsDefaults() *PoolsDefaults {
return &PoolsDefaults{
ClusterName: c.ClusterName,
DataMemoryQuota: c.DataMemoryQuotaMB,
IndexMemoryQuota: c.IndexMemoryQuotaMB,
SearchMemoryQuota: c.SearchMemoryQuotaMB,
EventingMemoryQuota: c.EventingMemoryQuotaMB,
AnalyticsMemoryQuota: c.AnalyticsMemoryQuotaMB,
}
}
type IndexSettings struct {
StorageMode IndexStorageMode `json:"storageMode"`
Threads int `json:"indexerThreads"`
MemSnapInterval int `json:"memorySnapshotInterval"`
StableSnapInterval int `json:"stableSnapshotInterval"`
MaxRollbackPoints int `json:"maxRollbackPoints"`
LogLevel IndexLogLevel `json:"logLevel"`
}
type FailoverOnDiskFailureSettings struct {
Enabled bool `url:"failoverOnDataDiskIssues[enabled]" json:"enabled"`
TimePeriod int64 `url:"failoverOnDataDiskIssues[timePeriod]" json:"timePeriod"`
}
type AutoFailoverSettings struct {
Enabled bool `url:"enabled" json:"enabled"`
Timeout int64 `url:"timeout" json:"timeout"`
Count uint8 `json:"count"`
FailoverOnDataDiskIssues FailoverOnDiskFailureSettings `url:"" json:"failoverOnDataDiskIssues"`
FailoverServerGroup bool `url:"failoverServerGroup" json:"failoverServerGroup"`
MaxCount uint64 `url:"maxCount" json:"maxCount"`
}
type AlternateAddressesExternalPorts struct {
// AdminPort is the admin service K8S node port (mapped to 8091)
AdminServicePort int32 `url:"mgmt,omitempty" json:"mgmt"`
// AdminPortSSL is the admin service K8S node port (mapped to 18091)
AdminServicePortTLS int32 `url:"mgmtSSL,omitempty" json:"mgmtSSL"`
// IndexServicePort is the view service K8S node port (mapped to 8092)
IndexServicePort int32 `url:"capi,omitempty" json:"capi"`
// IndexServicePortSSL is the view service K8S node port (mapped to 8092)
IndexServicePortTLS int32 `url:"capiSSL,omitempty" json:"capiSSL"`
// QueryServicePort is the query service K8S node port (mapped to 8093)
QueryServicePort int32 `url:"n1ql,omitempty" json:"n1ql"`
// QueryServicePortTLS is the query service K8S node port (mapped to 18093)
QueryServicePortTLS int32 `url:"n1qlSSL,omitempty" json:"n1qlSSL"`
// SearchServicePort is the full text search service K8S node port (mapped to 8094)
SearchServicePort int32 `url:"fts,omitempty" json:"fts"`
// SearchServicePortTLS is the full text search service K8S node port (mapped to 18094)
SearchServicePortTLS int32 `url:"ftsSSL,omitempty" json:"ftsSSL"`
// AnalyticsServicePort is the analytics service K8S node port (mapped to 8095)
AnalyticsServicePort int32 `url:"cbas,omitempty" json:"cbas"`
// AnalyticsServicePortTLS is the analytics service K8S node port (mapped to 18095)
AnalyticsServicePortTLS int32 `url:"cbasSSL,omitempty" json:"cbasSSL"`
// EventingServicePort is the eventing service K8S node port (mapped to 8096)
EventingServicePort int32 `url:"eventingAdminPort,omitempty" json:"eventingAdminPort"`
// EventingServicePortTLS is the eventing service K8S node port (mapped to 18096)
EventingServicePortTLS int32 `url:"eventingSSL,omitempty" json:"eventingSSL"`
// DataServicePort is the data service K8S node port (mapped to 11210)
DataServicePort int32 `url:"kv,omitempty" json:"kv"`
// DataServicePortTLS is the data service K8S node port (mapped to 11207)
DataServicePortTLS int32 `url:"kvSSL,omitempty" json:"kvSSL"`
}
// AlternateAddresses defines a K8S node address and port mapping for
// use by clients outside of the pod network. Hostname must be set,
// ports are ignored if zero.
type AlternateAddressesExternal struct {
// Hostname is the host name to connect to (typically a L3 address)
Hostname string `url:"hostname" json:"hostname"`
// Ports is the map of service to external ports
Ports *AlternateAddressesExternalPorts `url:"" json:"ports,omitempty"`
}
type AlternateAddresses struct {
External *AlternateAddressesExternal `json:"external,omitempty"`
}
type NodeService struct {
ThisNode bool `json:"thisNode"`
AlternateAddresses *AlternateAddresses `json:"alternateAddresses,omitempty"`
}
// NodeServices is returned by the /pools/default/nodeServices API
type NodeServices struct {
NodesExt []NodeService `json:"nodesExt"`
}
type NodeInfo struct {
ThisNode bool `json:"thisNode"`
Uptime string `json:"uptime"`
Membership string `json:"clusterMembership"`
RecoveryType string `json:"recoveryType"`
Status string `json:"status"`
OTPNode string `json:"otpNode"`
HostName string `json:"hostname"`
Services []string `json:"services"`
AvailableStorage AvailableStorageInfo `json:"storage"`
AlternateAddresses *AlternateAddresses `json:"alternateAddresses,omitempty"`
NodeEncryption bool `json:"nodeEncryption"`
ClusterCompatibility int `json:"clusterCompatibility"`
}
type AvailableStorageInfo map[AvailableStorageType][]StorageInfo
type StorageInfo struct {
Path string `json:"path"`
IndexPath string `json:"index_path"`
}
type PoolsInfo struct {
Enterprise bool `json:"isEnterprise"`
UUID interface{} `json:"uuid"`
}
// Task is a base object to describe the very unfriendly polymorphic
// task struct.
type Task struct {
// Common attributes.
Type string `json:"type"`
Status string `json:"status"`
// Rebalance attributes.
Progress float64 `json:"progress"`
Stale bool `json:"statusIsStale"`
Timeout bool `json:"masterRequestTimedOut"`
// Replication attributes.
Source string `json:"source"`
Target string `json:"target"`
ReplicationType string `url:"replicationType"`
FilterExpression string `url:"filterExpression"`
}
// PoolsDefaults is the data that may be posted via the /pools/default API
type PoolsDefaults struct {
ClusterName string `url:"clusterName,omitempty"`
DataMemoryQuota int64 `url:"memoryQuota,omitempty"`
IndexMemoryQuota int64 `url:"indexMemoryQuota,omitempty"`
SearchMemoryQuota int64 `url:"ftsMemoryQuota,omitempty"`
EventingMemoryQuota int64 `url:"eventingMemoryQuota,omitempty"`
AnalyticsMemoryQuota int64 `url:"cbasMemoryQuota,omitempty"`
}
type IoPriorityType string
type IoPriorityThreadCount int
const (
IoPriorityTypeLow IoPriorityType = "low"
IoPriorityTypeHigh IoPriorityType = "high"
IoPriorityThreadCountLow IoPriorityThreadCount = 3
IoPriorityThreadCountHigh IoPriorityThreadCount = 8
)
type CompressionMode string
const (
CompressionModeOff CompressionMode = "off"
CompressionModePassive CompressionMode = "passive"
CompressionModeActive CompressionMode = "active"
)
type Bucket struct {
BucketName string `json:"name"`
BucketType string `json:"type"`
BucketMemoryQuota int64 `json:"memoryQuota"`
BucketReplicas int `json:"replicas"`
IoPriority IoPriorityType `json:"ioPriority"`
EvictionPolicy string `json:"evictionPolicy"`
ConflictResolution string `json:"conflictResolution"`
EnableFlush bool `json:"enableFlush"`
EnableIndexReplica bool `json:"enableIndexReplica"`
BucketPassword string `json:"password"`
CompressionMode CompressionMode `json:"compressionMode"`
}
type BucketBasicStats struct {
DataUsed int `json:"dataUsed"`
DiskFetches float64 `json:"diskFetches"`
DiskUsed int `json:"diskUsed"`
ItemCount int `json:"itemCount"`
MemUsed int `json:"memUsed"`
OpsPerSec float64 `json:"opsPerSec"`
QuotaPercentUsed float64 `json:"quotaPercentUsed"`
}
type BucketStatus struct {
Nodes []NodeInfo `json:"nodes"`
BucketName string `json:"name"`
BucketType string `json:"bucketType"`
EvictionPolicy string `json:"evictionPolicy"`
ConflictResolution string `json:"conflictResolutionType"`
EnableIndexReplica bool `json:"replicaIndex"`
AutoCompactionSettings interface{} `json:"autoCompactionSettings"`
ReplicaNumber int `json:"replicaNumber"`
ThreadsNumber IoPriorityThreadCount `json:"threadsNumber"`
Controllers map[string]string `json:"controllers"`
Quota map[string]int64 `json:"quota"`
Stats map[string]string `json:"stats"`
VBServerMap VBucketServerMap `json:"vBucketServerMap"`
CompressionMode CompressionMode `json:"compressionMode"`
BasicStats BucketBasicStats `json:"basicStats"`
}
type VBucketServerMap struct {
ServerList []string `json:"serverList"`
VBMap VBucketMap `json:"vBucketMap"`
}
type VBucketMap [][]int
type AuthDomain string
const (
InternalAuthDomain AuthDomain = "local"
LDAPAuthDomain AuthDomain = "external"
)
type User struct {
Name string `json:"name"`
Password string `json:"password"`
Domain AuthDomain `json:"domain"`
ID string `json:"id"`
Roles []UserRole `json:"roles"`
Groups []string `json:"groups"`
}
type Group struct {
ID string `json:"id"`
Roles []UserRole `json:"roles"`
Description string `json:"description"`
LDAPGroupRef string `json:"ldap_group_ref"`
}
type LDAPEncryption string
const (
LDAPEncryptionNone LDAPEncryption = "None"
LDAPEncryptionStartTLS = "StartTLSExtension"
LDAPEncryptionTLS = "TLS"
)
type LDAPSettings struct {
// Enables using LDAP to authenticate users.
AuthenticationEnabled bool `json:"authenticationEnabled"`
// Enables use of LDAP groups for authorization.
AuthorizationEnabled bool `json:"authorizationEnabled"`
// List of LDAP hosts.
Hosts []string `json:"hosts"`
// LDAP port
Port int `json:"port"`
// Encryption method to communicate with LDAP servers.
// Can be StartTLSExtension, TLS, or false.
Encryption LDAPEncryption `json:"encryption,omitempty"`
// Whether server certificate validation be enabled
EnableCertValidation bool `json:"serverCertValidation"`
// Certificate in PEM format to be used in LDAP server certificate validation
CACert string `json:"cacert"`
// LDAP query, to get the users' groups by username in RFC4516 format.
GroupsQuery string `json:"groupsQuery,omitempty"`
// DN to use for searching users and groups synchronization.
BindDN string `json:"bindDN,omitempty"`
// Password for query_dn user.
BindPass string `json:"bindPass,omitempty"`
// User to distinguished name (DN) mapping. If none is specified,
// the username is used as the user’s distinguished name.
UserDNMapping LDAPUserDNMapping `json:"userDNMapping,omitempty"`
// If enabled Couchbase server will try to recursively search for groups
// for every discovered ldap group. groupsQuery will be user for the search.
NestedGroupsEnabled bool `json:"nestedGroupsEnabled,omitempty"`
// Maximum number of recursive groups requests the server is allowed to perform.
// Requires NestedGroupsEnabled. Values between 1 and 100: the default is 10.
NestedGroupsMaxDepth uint64 `json:"nestedGroupsMaxDepth,omitempty"`
// Lifetime of values in cache in milliseconds. Default 300000 ms.
CacheValueLifetime uint64 `json:"cacheValueLifetime,omitempty"`
}
type LDAPUserDNMapping struct {
Template string `json:"template"`
}
type LDAPStatusResult string
const (
LDAPStatusResultSuccess LDAPStatusResult = "success"
LDAPStatusResultError LDAPStatusResult = "error"
)
type LDAPStatus struct {
Result LDAPStatusResult `json:result`
Reason string `json:reason`
}
type UserRole struct {
Role string `json:"role"`
BucketName string `json:"bucket_name"`
}
type LogMessage struct {
Node string `json:"node"`
Type string `json:"type"`
Code uint8 `json:"code"`
Module string `json:"module"`
Tstamp uint64 `json:"tstamp"`
ShortText string `json:"shortText"`
Text string `json:"text"`
ServerTime string `json:"serverTime"`
}
type LogList []*LogMessage
func (li LogList) Len() int {
return len(li)
}
func (li LogList) Less(i, j int) bool {
return li[i].Tstamp < li[j].Tstamp
}
func (li LogList) Swap(i, j int) {
li[i], li[j] = li[j], li[i]
}
func (s *BucketStatus) GetIoPriority() IoPriorityType {
threadCount := s.ThreadsNumber
if threadCount <= IoPriorityThreadCountLow {
return IoPriorityTypeLow
}
return IoPriorityTypeHigh
}
// Unmarshall from json representation of
// type Bucket or BucketStatus
func (b *Bucket) UnmarshalJSON(data []byte) error {
// unmarshal as generic json
var jsonData map[string]interface{}
if err := json.Unmarshal(data, &jsonData); err != nil {
return err
}
// unmarshal as BucketStatus if nodes key exists
if _, ok := jsonData["nodes"]; ok {
return b.unmarshalFromStatus(data)
} else {
// unmarshal as standard bucket type
type BucketAlias Bucket
bucket := BucketAlias{}
if err := json.Unmarshal(data, &bucket); err != nil {
return err
}
*b = Bucket(bucket)
return nil
}
}
func (b *Bucket) unmarshalFromStatus(data []byte) error {
// unmarshalling data as bucket status
status := BucketStatus{}
if err := json.Unmarshal(data, &status); err != nil {
return err
}
// Generic things across all bucket types
b.BucketName = status.BucketName
b.BucketType = status.BucketType
if b.BucketType == "membase" {
b.BucketType = "couchbase"
}
if ramQuotaBytes, ok := status.Quota["rawRAM"]; ok {
b.BucketMemoryQuota = ramQuotaBytes >> 20
}
b.EnableFlush = false
if _, ok := status.Controllers["flush"]; ok {
b.EnableFlush = ok
}
if b.BucketType == "memcached" {
return nil
}
// Generic things across couchbase/ephemeral
b.EvictionPolicy = status.EvictionPolicy
b.ConflictResolution = status.ConflictResolution
b.BucketReplicas = status.ReplicaNumber
b.CompressionMode = status.CompressionMode
b.IoPriority = status.GetIoPriority()
if b.BucketType == "ephemeral" {
return nil
}
// Couchbase only things
b.EnableIndexReplica = status.EnableIndexReplica
return nil
}
func (b *Bucket) FormEncode() []byte {
data := url.Values{}
data.Set("name", b.BucketName)
data.Set("bucketType", b.BucketType)
data.Set("ramQuotaMB", strconv.Itoa(int(b.BucketMemoryQuota)))
if b.BucketType != "memcached" {
data.Set("replicaNumber", strconv.Itoa(b.BucketReplicas))
}
data.Set("authType", "sasl")
data.Set("compressionMode", string(b.CompressionMode))
data.Set("flushEnabled", BoolToStr(b.EnableFlush))
if b.EvictionPolicy != "" {
data.Set("evictionPolicy", b.EvictionPolicy)
}
if b.IoPriority == IoPriorityTypeLow {
data.Set("threadsNumber", strconv.Itoa(int(IoPriorityThreadCountLow)))
}
if b.IoPriority == IoPriorityTypeHigh {
data.Set("threadsNumber", strconv.Itoa(int(IoPriorityThreadCountHigh)))
}
if b.ConflictResolution != "" {
data.Set("conflictResolutionType", b.ConflictResolution)
}
if b.BucketType == "couchbase" {
data.Set("replicaIndex", BoolToStr(b.EnableIndexReplica))
}
return []byte(data.Encode())
}
// SettingsStats is the data structure returned by /settings/stats
type SettingsStats struct {
// SendStats actually indicates whether to perform software update checks
SendStats bool `json:"sendStats"`
}
// ServerGroup is a map from name to a list of nodes
type ServerGroup struct {
// Name is the human readable server group name
Name string `json:"name"`
// Nodes is a list of nodes who are members of the server group
Nodes []NodeInfo `json:"nodes"`
// URI is used to refer to a server group
URI string `json:"uri"`
}
// ServerGroups is returned by /nodes/default/serverGroups
type ServerGroups struct {
// Groups is a list of ServerGroup objects
Groups []ServerGroup `json:"groups"`
// URI is the URI used to update server groups
URI string `json:"uri"`
}
// GetRevision returns the server group revision ID (for CAS)
func (groups ServerGroups) GetRevision() string {
// Expected to be /pools/default/serverGroups?rev=13585112
return strings.Split(groups.URI, "=")[1]
}
// GetServerGroup looks up a server group by name
func (groups ServerGroups) GetServerGroup(name string) *ServerGroup {
for _, group := range groups.Groups {
if group.Name == name {
return &group
}
}
return nil
}
// ServerGroupUpdateOTPNode defines a single node is OTP notation
type ServerGroupUpdateOTPNode struct {
OTPNode string `json:"otpNode"`
}
// ServerGroupUpdate defines a server group and its nodes
type ServerGroupUpdate struct {
// Name is the group name and must match the existing one
Name string `json:"name,omitempty"`
// URI is the same as returned in ServerGroup
URI string `json:"uri"`
// Nodes is a list of OTP nodes
Nodes []ServerGroupUpdateOTPNode `json:"nodes"`
}
// ServerGroupsUpdate is used to move nodes between server groups
type ServerGroupsUpdate struct {
Groups []ServerGroupUpdate `json:"groups"`
}
// AutoCompactionDatabaseFragmentationThreshold indicates the percentage or size before a bucket
// compaction is triggered.
type AutoCompactionDatabaseFragmentationThreshold struct {
Percentage int `json:"percentage" url:"databaseFragmentationThreshold[percentage],omitempty"`
Size int64 `json:"size" url:"databaseFragmentationThreshold[size],omitempty"`
}
// UnmarshalJSON handles some *&$^ing moron's decision to have size as either an
// integer or "undefined". Way to go!
func (r *AutoCompactionDatabaseFragmentationThreshold) UnmarshalJSON(b []byte) error {
type t AutoCompactionDatabaseFragmentationThreshold
var s struct {
t
Percentage interface{} `json:"percentage"`
Size interface{} `json:"size"`
}
if err := json.Unmarshal(b, &s); err != nil {
return err
}
*r = AutoCompactionDatabaseFragmentationThreshold(s.t)
if i, ok := s.Size.(float64); ok {
r.Size = int64(i)
}
if i, ok := s.Percentage.(float64); ok {
r.Percentage = int(i)
}
return nil
}
// AutoCompactionViewFragmentationThreshold indicates the percentage or size before a view
// compaction is triggered.
type AutoCompactionViewFragmentationThreshold struct {
Percentage int `json:"percentage" url:"viewFragmentationThreshold[percentage],omitempty"`
Size int64 `json:"size" url:"viewFragmentationThreshold[size],omitempty"`
}
// UnmarshalJSON handles some *&$^ing moron's decision to have size as either an
// integer or "undefined". Way to go!
func (r *AutoCompactionViewFragmentationThreshold) UnmarshalJSON(b []byte) error {
type t AutoCompactionViewFragmentationThreshold
var s struct {
t
Percentage interface{} `json:"percentage"`
Size interface{} `json:"size"`
}
if err := json.Unmarshal(b, &s); err != nil {
return err
}
*r = AutoCompactionViewFragmentationThreshold(s.t)
if i, ok := s.Size.(float64); ok {
r.Size = int64(i)
}
if i, ok := s.Percentage.(float64); ok {
r.Percentage = int(i)
}
return nil
}
type AutoCompactionInterval struct {
FromHour int `json:"fromHour" url:"indexCircularCompaction[interval][fromHour]"`
FromMinute int `json:"fromMinute" url:"indexCircularCompaction[interval][fromMinute]"`
ToHour int `json:"toHour" url:"indexCircularCompaction[interval][toHour]"`
ToMinute int `json:"toMinute" url:"indexCircularCompaction[interval][toMinute]"`
AbortOutside bool `json:"abortOutside" url:"indexCircularCompaction[interval][abortOutside]"`
}
type AutoCompactionIndexCircularCompaction struct {
DaysOfWeek string `json:"daysOfWeek" url:"indexCircularCompaction[daysOfWeek]"`
Interval AutoCompactionInterval `json:"interval" url:""`
}
type AutoCompactionAutoCompactionSettings struct {
DatabaseFragmentationThreshold AutoCompactionDatabaseFragmentationThreshold `json:"databaseFragmentationThreshold" url:""`
ViewFragmentationThreshold AutoCompactionViewFragmentationThreshold `json:"viewFragmentationThreshold" url:""`
ParallelDBAndViewCompaction bool `json:"parallelDBAndViewCompaction" url:"parallelDBAndViewCompaction"`
IndexCompactionMode string `json:"indexCompactionMode" url:"indexCompactionMode"`
IndexCircularCompaction AutoCompactionIndexCircularCompaction `json:"indexCircularCompaction" url:""`
}
// AutoCompactionSettings is the cluster wide auto-compaction settings for a
// Couchbase cluster.
type AutoCompactionSettings struct {
AutoCompactionSettings AutoCompactionAutoCompactionSettings `json:"autoCompactionSettings" url:""`
PurgeInterval float64 `json:"purgeInterval" url:"purgeInterval"`
}
// RemoteClusters is returned by
//
// GET /pools/default/remoteClusters
type RemoteClusters []RemoteCluster
// RemoteCluster describes an XDCR remote cluster.
type RemoteCluster struct {
Name string `json:"name" url:"name"`
Hostname string `json:"hostname" url:"hostname"`
Username string `json:"username" url:"username"`
Password string `json:"password" url:"password"`
UUID string `json:"uuid" url:"uuid"`
Deleted bool `json:"deleted"`
SecureType string `json:"secureType" url:"secureType,omitempty"`
// These are here for convenience and should only be populated
// after comparison as they are not supplied by the API.
CA string `json:"-" url:"certificate,omitempty"`
Certificate string `json:"-" url:"clientCertificate,omitempty"`
Key string `json:"-" url:"clientKey,omitempty"`
}
// Replication describes an XDCR replication as set with
//
// POST /controller/createReplication
type Replication struct {
FromBucket string `url:"fromBucket"`
ToCluster string `url:"toCluster"`
ToBucket string `url:"toBucket"`
Type string `url:"type"`
ReplicationType string `url:"replicationType"`
CompressionType string `url:"compressionType,omitempty"`
FilterExpression string `url:"filterExpression,omitempty"`
PauseRequested bool `url:"pauseRequested"`
}
// ReplicationSettings describes an XDCR replication settings as returned by
//
// GET /settings/replications/<remote UUID>/<local bucket>/<remote bucket>
type ReplicationSettings struct {
CompressionType string `json:"compressionType" url:"compressionType,omitempty"`
PauseRequested bool `json:"pauseRequested" url:"pauseRequested"`
}
// FormEncode represents user type in api compatible form
func (u *User) FormEncode() []byte {
data := url.Values{}
if u.Password != "" {
data.Set("password", u.Password)
}
roles := RolesToStr(u.Roles)
data.Set("name", u.Name)
data.Set("roles", strings.Join(roles, ","))
data.Set("groups", strings.Join(u.Groups, ","))
return []byte(data.Encode())
}
// RoleToStr translates roles to string array
func RolesToStr(userRoles []UserRole) []string {
roles := []string{}
for _, role := range userRoles {
if role.BucketName != "" {
// bucket roles are enclosed in brackets
roles = append(roles, fmt.Sprintf("%s[%s]", role.Role, role.BucketName))
} else {
roles = append(roles, role.Role)
}
}
sort.Strings(roles)
return roles
}
// Normal unmarshlling doesn't work because
// LDAP DN Mapping returns a string when unset
func (s *LDAPSettings) UnmarshalJSON(data []byte) error {
var jsonData map[string]interface{}
err := json.Unmarshal(data, &jsonData)
if err != nil {
return err
}
// Remove dnMapping if it cannot be properly cast
if dnMap, ok := jsonData["userDNMapping"]; ok {
if _, ok := dnMap.(LDAPUserDNMapping); !ok {
delete(jsonData, "userDNMapping")
data, err = json.Marshal(jsonData)
if err != nil {
return err
}
}
}
type LDAPSettingsAlias LDAPSettings
settings := LDAPSettingsAlias{}
if err := json.Unmarshal(data, &settings); err != nil {
return err
}
*s = LDAPSettings(settings)
return nil
}
func (s *LDAPSettings) FormEncode() ([]byte, error) {
data := url.Values{}
data.Set("hosts", strings.Join(s.Hosts, ","))
data.Set("port", strconv.Itoa(s.Port))
data.Set("bindDN", s.BindDN)
data.Set("bindPass", s.BindPass)
data.Set("authenticationEnabled", strconv.FormatBool(s.AuthenticationEnabled))
data.Set("authorizationEnabled", strconv.FormatBool(s.AuthorizationEnabled))
data.Set("encryption", string(s.Encryption))
data.Set("serverCertValidation", strconv.FormatBool(s.EnableCertValidation))
if s.EnableCertValidation {
data.Set("cacert", string(s.CACert))
}
if s.AuthenticationEnabled {
dnData, err := json.Marshal(s.UserDNMapping)
if err != nil {
return []byte{}, err
}
data.Set("userDNMapping", string(dnData))
}
if s.AuthorizationEnabled {
data.Set("groupsQuery", s.GroupsQuery)
}
if s.NestedGroupsEnabled {
data.Set("nestedGroupsEnabled", BoolToStr(s.NestedGroupsEnabled))
data.Set("nestedGroupsMaxDepth", strconv.FormatUint(s.NestedGroupsMaxDepth, 10))
}
if s.CacheValueLifetime > 0 {
data.Set("cacheValueLifetime", strconv.FormatUint(s.CacheValueLifetime, 10))
}
return []byte(data.Encode()), nil
}
// TLSVersion is a TLS version, as understood by the security API.
type TLSVersion string
const (
// Insecure, do not use.
TLS10 TLSVersion = "tls1"
// Insecure, do not use.
TLS11 TLSVersion = "tls1.1"
// Obsolete, use 1.3... which isn't supported :D
TLS12 TLSVersion = "tls1.2"
)
// ClusterEncryptionLevel is used to fully encrypt everything.
type ClusterEncryptionLevel string
const (
// Encrypt all traffic.
ClusterEncryptionAll ClusterEncryptionLevel = "all"
// Encrypt only the control plane, allowing all your data to be evesdropped.
// The implication here is performance sucks, so use with caution!
ClusterEncryptionControl ClusterEncryptionLevel = "control"
)
// Security settings for the cluster.
type SecuritySettings struct {
// Disallow access to web APIs over 8091.
DisableUIOverHTTP bool `json:"disableUIOverHttp" url:"disableUIOverHttp,omitempty"`
// Disallow access to web APIs over 18091.
DisableUIOverHTTPS bool `json:"disableUIOverHttps" url:"disableUIOverHttps,omitempty"`
// Set the minimum TLS version, should always be 1.2.
TLSMinVersion TLSVersion `json:"tlsMinVersion" url:"tlsMinVersion,omitempty"`
// Cipher suites is a list of OpenSSL suites (openssl ciphers -v)
CipherSuites []string `json:"cipherSuites" url:"cipherSuites"`
// Choose the first suite that the client accepts. This goes against
// standard security practice in that you should always use the most
// secure. When in the hands of users this isn't the case...
HonorCipherOrder bool `json:"honorCipherOrder" url:"honorCipherOrder,omitempty"`
// Enable cluster level encryption.
ClusterEncryptionLevel ClusterEncryptionLevel `json:"clusterEncryptionLevel" url:"clusterEncryptionLevel,omitempty"`
}
// I'm not even going to comment on this...
type OnOrOff string
const (
On OnOrOff = "on"
Off OnOrOff = "off"
)
// AddressFamily The address family to apply the settings.
type AddressFamily string
const (
AddressFamilyIPV4 AddressFamily = "ipv4"
AddressFamilyIPV6 AddressFamily = "ipv6"
)
// NodeNetworkConfiguration allows configuration of node networking for a specific address family.
// I can only guess this default to IPv4, which is fine.
type NodeNetworkConfiguration struct {
// AddressFamily is the family of addresses to affect (IPv4 or IPv6 presumably).
AddressFamily AddressFamily `json:"afamiliy" url:"afamily,omitempty"`
// NodeEncryption is whether encyryption is enabled for a node.
NodeEncryption OnOrOff `json:"nodeEncryption" url:"nodeEncryption"`
}