-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_property.go
840 lines (768 loc) · 20.9 KB
/
command_property.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
package main
import (
"encoding/json"
"fmt"
"os"
"github.com/1and1/soma/internal/adm"
"github.com/1and1/soma/internal/cmpl"
"github.com/1and1/soma/lib/proto"
"github.com/codegangsta/cli"
)
func registerProperty(app cli.App) *cli.App {
app.Commands = append(app.Commands,
[]cli.Command{
// property
{
Name: "property",
Usage: "SUBCOMMANDS for property",
Subcommands: []cli.Command{
{
Name: "create",
Usage: "SUBCOMMANDS for property create",
Subcommands: []cli.Command{
{
Name: "service",
Usage: "Create a new per-team service property",
Action: runtime(cmdPropertyServiceCreate),
BashComplete: comptime(bashCompSvcCreate),
},
{
Name: "system",
Usage: "Create a new global system property",
Action: runtime(cmdPropertySystemCreate),
},
{
Name: "native",
Usage: "Create a new global native property",
Action: runtime(cmdPropertyNativeCreate),
},
{
Name: "custom",
Usage: "Create a new per-repo custom property",
Action: runtime(cmdPropertyCustomCreate),
BashComplete: cmpl.Repository,
},
{
Name: "template",
Usage: "Create a new global service template",
Action: runtime(cmdPropertyServiceCreate),
},
},
}, // end property create
{
Name: "delete",
Usage: "SUBCOMMANDS for property delete",
Subcommands: []cli.Command{
{
Name: "service",
Usage: "Delete a team service property",
Action: runtime(cmdPropertyServiceDelete),
BashComplete: cmpl.Team,
},
{
Name: "system",
Usage: "Delete a system property",
Action: runtime(cmdPropertySystemDelete),
},
{
Name: "native",
Usage: "Delete a native property",
Action: runtime(cmdPropertyNativeDelete),
},
{
Name: "custom",
Usage: "Delete a repository custom property",
Action: runtime(cmdPropertyCustomDelete),
BashComplete: cmpl.Repository,
},
{
Name: "template",
Usage: "Delete a global service property template",
Action: runtime(cmdPropertyTemplateDelete),
},
},
}, // end property delete
/* XXX NOT IMPLEMENTED YET
{
Name: "edit",
Usage: "SUBCOMMANDS for property edit",
Subcommands: []cli.Command{
{
Name: "service",
Usage: "Edit a service property",
Action: cmdPropertyServiceEdit,
},
{
Name: "template",
Usage: "Edit a service property template",
Action: cmdPropertyTemplateEdit,
},
},
}, // end property edit
*/
/* XXX NOT IMPLEMENTED YET
{
Name: "rename",
Usage: "SUBCOMMANDS for property rename",
Subcommands: []cli.Command{
{
Name: "service",
Usage: "Rename a service property",
Action: cmdPropertyServiceRename,
},
{
Name: "custom",
Usage: "Rename a custom property",
Action: cmdPropertyCustomRename,
},
{
Name: "system",
Usage: "Rename a system property",
Action: cmdPropertySystemRename,
},
{
Name: "template",
Usage: "Rename a service property template",
Action: cmdPropertyTemplateRename,
},
},
}, // end property rename
*/
{
Name: "show",
Usage: "SUBCOMMANDS for property show",
Subcommands: []cli.Command{
{
Name: "service",
Usage: "Show a service property",
Action: runtime(cmdPropertyServiceShow),
BashComplete: cmpl.Team,
},
{
Name: "custom",
Usage: "Show a custom property",
Action: runtime(cmdPropertyCustomShow),
BashComplete: cmpl.Repository,
},
{
Name: "system",
Usage: "Show a system property",
Action: runtime(cmdPropertySystemShow),
},
{
Name: "native",
Usage: "Show a native property",
Action: runtime(cmdPropertyNativeShow),
},
{
Name: "template",
Usage: "Show a service property template",
Action: runtime(cmdPropertyTemplateShow),
},
},
}, // end property show
{
Name: "list",
Usage: "SUBCOMMANDS for property list",
Subcommands: []cli.Command{
{
Name: "service",
Usage: "List service properties",
Action: runtime(cmdPropertyServiceList),
BashComplete: cmpl.Team,
},
{
Name: "custom",
Usage: "List custom properties",
Action: runtime(cmdPropertyCustomList),
BashComplete: cmpl.Repository,
},
{
Name: "system",
Usage: "List system properties",
Action: runtime(cmdPropertySystemList),
},
{
Name: "native",
Usage: "List native properties",
Action: runtime(cmdPropertyNativeList),
},
{
Name: "template",
Usage: "List service property templates",
Action: runtime(cmdPropertyTemplateList),
},
},
}, // end property list
},
}, // end property
}...,
)
return &app
}
/* CREATE
*/
func cmdPropertyCustomCreate(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 3)
multiple := []string{}
unique := []string{"repository"}
required := []string{"repository"}
opts := utl.ParseVariadicArguments(
multiple,
unique,
required,
c.Args().Tail())
repoId := utl.TryGetRepositoryByUUIDOrName(Client, opts["repository"][0])
req := proto.Request{}
req.Property = &proto.Property{}
req.Property.Type = "custom"
req.Property.Custom = &proto.PropertyCustom{}
req.Property.Custom.Name = c.Args().First()
req.Property.Custom.RepositoryId = repoId
path := fmt.Sprintf("/property/custom/%s/", repoId)
if resp, err := adm.PostReqBody(req, path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertySystemCreate(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 1)
req := proto.Request{}
req.Property = &proto.Property{}
req.Property.Type = "system"
req.Property.System = &proto.PropertySystem{}
req.Property.System.Name = c.Args().First()
if resp, err := adm.PostReqBody(req, "/property/system/"); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyNativeCreate(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 1)
req := proto.Request{}
req.Property = &proto.Property{}
req.Property.Type = "native"
req.Property.Native = &proto.PropertyNative{}
req.Property.Native.Name = c.Args().First()
if resp, err := adm.PostReqBody(req, "/property/native/"); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyServiceCreate(c *cli.Context) error {
utl.ValidateCliMinArgumentCount(c, 5)
// fetch list of possible service attributes from SOMA
attrResponse := utl.GetRequest(Client, "/attributes/")
attrs := proto.Result{}
err := json.Unmarshal(attrResponse.Body(), &attrs)
if err != nil {
utl.Abort("Failed to unmarshal Service Attribute data")
}
// sort attributes based on their cardinality so we can use them
// for command line parsing
multiple := []string{}
unique := []string{}
for _, attr := range *attrs.Attributes {
switch attr.Cardinality {
case "once":
unique = append(unique, attr.Name)
case "multi":
multiple = append(multiple, attr.Name)
default:
utl.Abort()
}
}
required := []string{}
switch c.Command.Name {
case "service":
// services are per team; add this as required as well
required = append(required, "team")
unique = append(unique, "team")
case "template":
default:
utl.Abort(
fmt.Sprintf("cmdPropertyServiceCreate called from unknown action %s",
c.Command.Name),
)
}
// parse command line
opts := utl.ParseVariadicArguments(
multiple,
unique,
required,
c.Args().Tail())
// team lookup only for service
var teamId string
if c.Command.Name == "service" {
teamId = utl.TryGetTeamByUUIDOrName(Client, opts["team"][0])
}
// construct request body
req := proto.Request{}
req.Property = &proto.Property{}
req.Property.Service = &proto.PropertyService{}
req.Property.Service.Name = c.Args().First()
utl.ValidateRuneCount(req.Property.Service.Name, 128)
req.Property.Service.Attributes = make([]proto.ServiceAttribute, 0, 16)
if c.Command.Name == "service" {
req.Property.Type = `service`
req.Property.Service.TeamId = teamId
} else {
req.Property.Type = `template`
}
// fill attributes into request body
attrConversionLoop:
for oName, _ := range opts {
// the team that registers this service is not a service
// attribute
if c.Command.Name == `service` && oName == `team` {
continue attrConversionLoop
}
for _, oVal := range opts[oName] {
utl.ValidateRuneCount(oName, 128)
utl.ValidateRuneCount(oVal, 512)
req.Property.Service.Attributes = append(req.Property.Service.Attributes,
proto.ServiceAttribute{
Name: oName,
Value: oVal,
},
)
}
}
// send request
var path string
switch c.Command.Name {
case `service`:
path = fmt.Sprintf("/property/service/team/%s/", teamId)
case `template`:
path = `/property/service/global/`
}
if resp, err := adm.PostReqBody(req, path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
// in main and not the cmpl lib because the full runtime is required
// to provide the completion options. This means we need access to
// globals that do not fit the function signature
func bashCompSvcCreate(c *cli.Context) {
// fetch list of possible service attributes from SOMA
attrResponse := utl.GetRequest(Client, "/attributes/")
attrs := proto.Result{}
err := json.Unmarshal(attrResponse.Body(), &attrs)
if err != nil {
utl.Abort("Failed to unmarshal Service Attribute data")
}
// sort attributes based on their cardinality so we can use them
// for command line parsing
multiple := []string{}
unique := []string{}
for _, attr := range *attrs.Attributes {
switch attr.Cardinality {
case "once":
unique = append(unique, attr.Name)
case "multi":
multiple = append(multiple, attr.Name)
default:
utl.Abort()
}
}
cmpl.GenericMulti(c, unique, multiple)
}
/* DELETE
*/
func cmdPropertyCustomDelete(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 3)
multiple := []string{}
unique := []string{"repository"}
required := []string{"repository"}
opts := utl.ParseVariadicArguments(
multiple,
unique,
required,
c.Args().Tail())
repoId := utl.TryGetRepositoryByUUIDOrName(Client, opts["repository"][0])
propId := utl.TryGetCustomPropertyByUUIDOrName(Client, c.Args().First(),
repoId)
path := fmt.Sprintf("/property/custom/%s/%s", repoId, propId)
if resp, err := adm.DeleteReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertySystemDelete(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 1)
path := fmt.Sprintf("/property/system/%s", c.Args().First())
if resp, err := adm.DeleteReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyNativeDelete(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 1)
path := fmt.Sprintf("/property/native/%s", c.Args().First())
if resp, err := adm.DeleteReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyServiceDelete(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 3)
utl.ValidateCliArgument(c, 2, "team")
teamId := utl.TryGetTeamByUUIDOrName(Client, c.Args().Get(2))
propId := utl.TryGetServicePropertyByUUIDOrName(Client, c.Args().Get(0), teamId)
path := fmt.Sprintf("/property/service/team/%s/%s", teamId, propId)
if resp, err := adm.DeleteReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyTemplateDelete(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 1)
propId := utl.TryGetTemplatePropertyByUUIDOrName(Client, c.Args().Get(0))
path := fmt.Sprintf("/property/service/global/%s", propId)
if resp, err := adm.DeleteReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
/*
func cmdPropertyServiceEdit(c *cli.Context) {
utl.NotImplemented()
}
func cmdPropertyTemplateEdit(c *cli.Context) {
utl.NotImplemented()
}
func cmdPropertyCustomRename(c *cli.Context) {
utl.NotImplemented()
}
func cmdPropertySystemRename(c *cli.Context) {
utl.NotImplemented()
}
func cmdPropertyServiceRename(c *cli.Context) {
utl.NotImplemented()
}
func cmdPropertyTemplateRename(c *cli.Context) {
utl.NotImplemented()
}
*/
/* SHOW
*/
func cmdPropertyCustomShow(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 3)
utl.ValidateCliArgument(c, 2, "repository")
repoId := utl.TryGetRepositoryByUUIDOrName(Client, c.Args().Get(2))
propId := utl.TryGetCustomPropertyByUUIDOrName(Client, c.Args().Get(0),
repoId)
path := fmt.Sprintf("/property/custom/%s/", repoId,
propId)
if resp, err := adm.GetReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertySystemShow(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 1)
path := fmt.Sprintf("/property/system/%s", c.Args().First())
if resp, err := adm.GetReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyNativeShow(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 1)
path := fmt.Sprintf("/property/native/%s", c.Args().First())
if resp, err := adm.GetReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyServiceShow(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 3)
utl.ValidateCliArgument(c, 2, "team")
teamId := utl.TryGetTeamByUUIDOrName(Client, c.Args().Get(2))
propId := utl.TryGetServicePropertyByUUIDOrName(Client, c.Args().Get(0), teamId)
path := fmt.Sprintf("/property/service/team/%s/%s", teamId, propId)
if resp, err := adm.GetReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyTemplateShow(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 1)
propId := utl.TryGetTemplatePropertyByUUIDOrName(Client, c.Args().Get(0))
path := fmt.Sprintf("/property/service/global/%s", propId)
if resp, err := adm.GetReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
/* LIST
*/
func cmdPropertyCustomList(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 2)
utl.ValidateCliArgument(c, 1, "repository")
repoId := utl.TryGetRepositoryByUUIDOrName(Client, c.Args().Get(1))
path := fmt.Sprintf("/property/custom/%s/", repoId)
if resp, err := adm.GetReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertySystemList(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 0)
if resp, err := adm.GetReq("/property/system/"); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyNativeList(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 0)
if resp, err := adm.GetReq("/property/native/"); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyServiceList(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 2)
utl.ValidateCliArgument(c, 1, "team")
teamId := utl.TryGetTeamByUUIDOrName(Client, c.Args().Get(1))
path := fmt.Sprintf("/property/service/team/%s/", teamId)
if resp, err := adm.GetReq(path); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
func cmdPropertyTemplateList(c *cli.Context) error {
utl.ValidateCliArgumentCount(c, 0)
if resp, err := adm.GetReq("/property/service/global/"); err != nil {
return err
} else {
fmt.Println(resp)
}
return nil
}
/* ADD
*/
func cmdPropertyAdd(c *cli.Context, pType, oType string) error {
switch oType {
case `node`, `bucket`, `repository`:
switch pType {
case `system`:
fallthrough
case `custom`:
utl.ValidateCliMinArgumentCount(c, 7)
case `service`:
fallthrough
case `oncall`:
utl.ValidateCliMinArgumentCount(c, 5)
default:
utl.Abort(`Unknown property type`)
}
case `group`, `cluster`:
switch pType {
case `system`:
fallthrough
case `custom`:
utl.ValidateCliMinArgumentCount(c, 9)
case `service`:
fallthrough
case `oncall`:
utl.ValidateCliMinArgumentCount(c, 7)
default:
utl.Abort(`Unknown property type`)
}
default:
utl.Abort(`Unknown object type`)
}
// argument parsing
multiple := []string{}
required := []string{`to`, `view`}
unique := []string{`to`, `in`, `view`, `inheritance`, `childrenonly`}
switch pType {
case `system`:
utl.CheckStringIsSystemProperty(Client, c.Args().First())
fallthrough
case `custom`:
required = append(required, `value`)
unique = append(unique, `value`)
}
switch oType {
case `group`, `cluster`:
required = append(required, `in`)
}
opts := utl.ParseVariadicArguments(multiple, unique, required,
c.Args().Tail())
// deprecation warning
switch oType {
case `repository`, `bucket`, `node`:
if _, ok := opts[`in`]; ok {
fmt.Fprintf(
os.Stderr,
"Hint: Keyword `in` is DEPRECATED for %s objects, since they are global objects. Ignoring.",
oType,
)
}
}
var (
objectId, object, repoId, bucketId string
config *proto.NodeConfig
req proto.Request
)
// id lookup
switch oType {
case `node`:
objectId = utl.TryGetNodeByUUIDOrName(Client, opts[`to`][0])
config = utl.GetNodeConfigById(Client, objectId)
repoId = config.RepositoryId
bucketId = config.BucketId
case `cluster`:
bucketId = utl.BucketByUUIDOrName(Client, opts[`in`][0])
objectId = utl.TryGetClusterByUUIDOrName(Client, opts[`to`][0],
bucketId)
repoId = utl.GetRepositoryIdForBucket(Client, bucketId)
case `group`:
bucketId = utl.BucketByUUIDOrName(Client, opts[`in`][0])
objectId = utl.TryGetGroupByUUIDOrName(Client, opts[`to`][0],
bucketId)
repoId = utl.GetRepositoryIdForBucket(Client, bucketId)
case `bucket`:
bucketId = utl.BucketByUUIDOrName(Client, opts[`to`][0])
objectId = bucketId
repoId = utl.GetRepositoryIdForBucket(Client, bucketId)
case `repository`:
repoId = utl.TryGetRepositoryByUUIDOrName(Client, opts[`to`][0])
objectId = repoId
}
// property assembly
prop := proto.Property{
Type: pType,
View: opts[`view`][0],
}
// property assembly, optional arguments
if _, ok := opts[`childrenonly`]; ok {
prop.ChildrenOnly = utl.GetValidatedBool(opts[`childrenonly`][0])
} else {
prop.ChildrenOnly = false
}
if _, ok := opts[`inheritance`]; ok {
prop.Inheritance = utl.GetValidatedBool(opts[`inheritance`][0])
} else {
prop.Inheritance = true
}
switch pType {
case `system`:
prop.System = &proto.PropertySystem{
Name: c.Args().First(),
Value: opts[`value`][0],
}
case `service`:
var teamId string
switch oType {
case `repository`:
teamId = utl.GetTeamIdByRepositoryId(Client, repoId)
default:
teamId = utl.TeamIdForBucket(Client, bucketId)
}
// no reason to fill out the attributes, client-provided
// attributes are discarded by the server
prop.Service = &proto.PropertyService{
Name: c.Args().First(),
TeamId: teamId,
Attributes: []proto.ServiceAttribute{},
}
case `oncall`:
oncallId := utl.TryGetOncallByUUIDOrName(Client, c.Args().First())
prop.Oncall = &proto.PropertyOncall{
Id: oncallId,
}
prop.Oncall.Name, prop.Oncall.Number = utl.GetOncallDetailsById(
Client,
oncallId,
)
case `custom`:
customId := utl.TryGetCustomPropertyByUUIDOrName(
Client, c.Args().First(), repoId)
prop.Custom = &proto.PropertyCustom{
Id: customId,
Name: c.Args().First(),
RepositoryId: repoId,
Value: opts[`value`][0],
}
}
// request assembly
switch oType {
case `node`:
req = proto.NewNodeRequest()
req.Node.Id = objectId
req.Node.Config = config
req.Node.Properties = &[]proto.Property{prop}
case `cluster`:
req = proto.NewClusterRequest()
req.Cluster.Id = objectId
req.Cluster.BucketId = bucketId
req.Cluster.Properties = &[]proto.Property{prop}
case `group`:
req = proto.NewGroupRequest()
req.Group.Id = objectId
req.Group.BucketId = bucketId
req.Group.Properties = &[]proto.Property{prop}
case `bucket`:
req = proto.NewBucketRequest()
req.Bucket.Id = objectId
req.Bucket.Properties = &[]proto.Property{prop}
case `repository`:
req = proto.NewRepositoryRequest()
req.Repository.Id = repoId
req.Repository.Properties = &[]proto.Property{prop}
}
// request dispatch
switch oType {
case `repository`:
object = oType
default:
object = oType + `s`
}
path := fmt.Sprintf("/%s/%s/property/%s/", object, objectId, pType)
if resp, err := adm.PostReqBody(req, path); err != nil {
return err
} else {
return adm.FormatOut(c, resp, ``)
}
}
// vim: ts=4 sw=4 sts=4 noet fenc=utf-8 ffs=unix