forked from hashicorp/vault
-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity_store_entities.go
757 lines (644 loc) · 21.4 KB
/
identity_store_entities.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
package vault
import (
"context"
"errors"
"fmt"
"strings"
"github.com/golang/protobuf/ptypes"
"github.com/hashicorp/errwrap"
memdb "github.com/hashicorp/go-memdb"
"github.com/hashicorp/vault/helper/identity"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/helper/storagepacker"
"github.com/hashicorp/vault/helper/strutil"
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
func entityPathFields() map[string]*framework.FieldSchema {
return map[string]*framework.FieldSchema{
"id": {
Type: framework.TypeString,
Description: "ID of the entity. If set, updates the corresponding existing entity.",
},
"name": {
Type: framework.TypeString,
Description: "Name of the entity",
},
"metadata": {
Type: framework.TypeKVPairs,
Description: `Metadata to be associated with the entity.
In CLI, this parameter can be repeated multiple times, and it all gets merged together.
For example:
vault <command> <path> metadata=key1=value1 metadata=key2=value2
`,
},
"policies": {
Type: framework.TypeCommaStringSlice,
Description: "Policies to be tied to the entity.",
},
"disabled": {
Type: framework.TypeBool,
Description: "If set true, tokens tied to this identity will not be able to be used (but will not be revoked).",
},
}
}
// entityPaths returns the API endpoints supported to operate on entities.
// Following are the paths supported:
// entity - To register a new entity
// entity/id - To lookup, modify, delete and list entities based on ID
// entity/merge - To merge entities based on ID
func entityPaths(i *IdentityStore) []*framework.Path {
return []*framework.Path{
{
Pattern: "entity$",
Fields: entityPathFields(),
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: i.handleEntityUpdateCommon(),
},
HelpSynopsis: strings.TrimSpace(entityHelp["entity"][0]),
HelpDescription: strings.TrimSpace(entityHelp["entity"][1]),
},
{
Pattern: "entity/name/" + framework.GenericNameRegex("name"),
Fields: entityPathFields(),
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: i.handleEntityUpdateCommon(),
logical.ReadOperation: i.pathEntityNameRead(),
logical.DeleteOperation: i.pathEntityNameDelete(),
},
HelpSynopsis: strings.TrimSpace(entityHelp["entity-name"][0]),
HelpDescription: strings.TrimSpace(entityHelp["entity-name"][1]),
},
{
Pattern: "entity/id/" + framework.GenericNameRegex("id"),
Fields: entityPathFields(),
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: i.handleEntityUpdateCommon(),
logical.ReadOperation: i.pathEntityIDRead(),
logical.DeleteOperation: i.pathEntityIDDelete(),
},
HelpSynopsis: strings.TrimSpace(entityHelp["entity-id"][0]),
HelpDescription: strings.TrimSpace(entityHelp["entity-id"][1]),
},
{
Pattern: "entity/name/?$",
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ListOperation: i.pathEntityNameList(),
},
HelpSynopsis: strings.TrimSpace(entityHelp["entity-name-list"][0]),
HelpDescription: strings.TrimSpace(entityHelp["entity-name-list"][1]),
},
{
Pattern: "entity/id/?$",
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ListOperation: i.pathEntityIDList(),
},
HelpSynopsis: strings.TrimSpace(entityHelp["entity-id-list"][0]),
HelpDescription: strings.TrimSpace(entityHelp["entity-id-list"][1]),
},
{
Pattern: "entity/merge/?$",
Fields: map[string]*framework.FieldSchema{
"from_entity_ids": {
Type: framework.TypeCommaStringSlice,
Description: "Entity IDs which needs to get merged",
},
"to_entity_id": {
Type: framework.TypeString,
Description: "Entity ID into which all the other entities need to get merged",
},
"force": {
Type: framework.TypeBool,
Description: "Setting this will follow the 'mine' strategy for merging MFA secrets. If there are secrets of the same type both in entities that are merged from and in entity into which all others are getting merged, secrets in the destination will be unaltered. If not set, this API will throw an error containing all the conflicts.",
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: i.pathEntityMergeID(),
},
HelpSynopsis: strings.TrimSpace(entityHelp["entity-merge-id"][0]),
HelpDescription: strings.TrimSpace(entityHelp["entity-merge-id"][1]),
},
}
}
// pathEntityMergeID merges two or more entities into a single entity
func (i *IdentityStore) pathEntityMergeID() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
toEntityID := d.Get("to_entity_id").(string)
if toEntityID == "" {
return logical.ErrorResponse("missing entity id to merge to"), nil
}
fromEntityIDs := d.Get("from_entity_ids").([]string)
if len(fromEntityIDs) == 0 {
return logical.ErrorResponse("missing entity ids to merge from"), nil
}
force := d.Get("force").(bool)
// Create a MemDB transaction to merge entities
txn := i.db.Txn(true)
defer txn.Abort()
toEntity, err := i.MemDBEntityByID(toEntityID, true)
if err != nil {
return nil, err
}
userErr, intErr := i.mergeEntity(ctx, txn, toEntity, fromEntityIDs, force, true, false)
if userErr != nil {
return logical.ErrorResponse(userErr.Error()), nil
}
if intErr != nil {
return nil, intErr
}
// Committing the transaction *after* successfully performing storage
// persistence
txn.Commit()
return nil, nil
}
}
// handleEntityUpdateCommon is used to update an entity
func (i *IdentityStore) handleEntityUpdateCommon() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
i.lock.Lock()
defer i.lock.Unlock()
entity := new(identity.Entity)
var err error
entityID := d.Get("id").(string)
if entityID != "" {
entity, err = i.MemDBEntityByID(entityID, true)
if err != nil {
return nil, err
}
if entity == nil {
return logical.ErrorResponse("entity not found from id"), nil
}
}
// Get the name
entityName := d.Get("name").(string)
if entityName != "" {
entityByName, err := i.MemDBEntityByName(ctx, entityName, false)
if err != nil {
return nil, err
}
switch {
case entityByName == nil:
// Not found, safe to use this name with an existing or new entity
case entity.ID == "":
// Entity by ID was not found, but and entity for the supplied
// name was found. Continue updating the entity.
entity = entityByName
case entity.ID == entityByName.ID:
// Same exact entity, carry on (this is basically a noop then)
default:
return logical.ErrorResponse("entity name is already in use"), nil
}
}
if entityName != "" {
entity.Name = entityName
}
// Update the policies if supplied
entityPoliciesRaw, ok := d.GetOk("policies")
if ok {
entity.Policies = entityPoliciesRaw.([]string)
}
if strutil.StrListContains(entity.Policies, "root") {
return logical.ErrorResponse("policies cannot contain root"), nil
}
disabledRaw, ok := d.GetOk("disabled")
if ok {
entity.Disabled = disabledRaw.(bool)
}
// Get entity metadata
metadata, ok, err := d.GetOkErr("metadata")
if err != nil {
return logical.ErrorResponse(fmt.Sprintf("failed to parse metadata: %v", err)), nil
}
if ok {
entity.Metadata = metadata.(map[string]string)
}
// At this point, if entity.ID is empty, it indicates that a new entity
// is being created. Using this to respond data in the response.
newEntity := entity.ID == ""
// ID creation and some validations
err = i.sanitizeEntity(ctx, entity)
if err != nil {
return nil, err
}
if err := i.upsertEntity(ctx, entity, nil, true); err != nil {
return nil, err
}
// If this operation was an update to an existing entity, return 204
if !newEntity {
return nil, nil
}
// Prepare the response
respData := map[string]interface{}{
"id": entity.ID,
}
var aliasIDs []string
for _, alias := range entity.Aliases {
aliasIDs = append(aliasIDs, alias.ID)
}
respData["aliases"] = aliasIDs
// Return ID of the entity that was either created or updated along with
// its aliases
return &logical.Response{
Data: respData,
}, nil
}
}
// pathEntityNameRead returns the properties of an entity for a given entity ID
func (i *IdentityStore) pathEntityNameRead() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
entityName := d.Get("name").(string)
if entityName == "" {
return logical.ErrorResponse("missing entity name"), nil
}
entity, err := i.MemDBEntityByName(ctx, entityName, false)
if err != nil {
return nil, err
}
if entity == nil {
return nil, nil
}
return i.handleEntityReadCommon(ctx, entity)
}
}
// pathEntityIDRead returns the properties of an entity for a given entity ID
func (i *IdentityStore) pathEntityIDRead() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
entityID := d.Get("id").(string)
if entityID == "" {
return logical.ErrorResponse("missing entity id"), nil
}
entity, err := i.MemDBEntityByID(entityID, false)
if err != nil {
return nil, err
}
if entity == nil {
return nil, nil
}
return i.handleEntityReadCommon(ctx, entity)
}
}
func (i *IdentityStore) handleEntityReadCommon(ctx context.Context, entity *identity.Entity) (*logical.Response, error) {
ns, err := namespace.FromContext(ctx)
if err != nil {
return nil, err
}
if ns.ID != entity.NamespaceID {
return nil, nil
}
respData := map[string]interface{}{}
respData["id"] = entity.ID
respData["name"] = entity.Name
respData["metadata"] = entity.Metadata
respData["merged_entity_ids"] = entity.MergedEntityIDs
respData["policies"] = entity.Policies
respData["disabled"] = entity.Disabled
// Convert protobuf timestamp into RFC3339 format
respData["creation_time"] = ptypes.TimestampString(entity.CreationTime)
respData["last_update_time"] = ptypes.TimestampString(entity.LastUpdateTime)
// Convert each alias into a map and replace the time format in each
aliasesToReturn := make([]interface{}, len(entity.Aliases))
for aliasIdx, alias := range entity.Aliases {
aliasMap := map[string]interface{}{}
aliasMap["id"] = alias.ID
aliasMap["canonical_id"] = alias.CanonicalID
aliasMap["mount_accessor"] = alias.MountAccessor
aliasMap["metadata"] = alias.Metadata
aliasMap["name"] = alias.Name
aliasMap["merged_from_canonical_ids"] = alias.MergedFromCanonicalIDs
aliasMap["creation_time"] = ptypes.TimestampString(alias.CreationTime)
aliasMap["last_update_time"] = ptypes.TimestampString(alias.LastUpdateTime)
if mountValidationResp := i.core.router.validateMountByAccessor(alias.MountAccessor); mountValidationResp != nil {
aliasMap["mount_type"] = mountValidationResp.MountType
aliasMap["mount_path"] = mountValidationResp.MountPath
}
aliasesToReturn[aliasIdx] = aliasMap
}
// Add the aliases information to the response which has the correct time
// formats
respData["aliases"] = aliasesToReturn
addExtraEntityDataToResponse(entity, respData)
// Fetch the groups this entity belongs to and return their identifiers
groups, inheritedGroups, err := i.groupsByEntityID(entity.ID)
if err != nil {
return nil, err
}
groupIDs := make([]string, len(groups))
for i, group := range groups {
groupIDs[i] = group.ID
}
respData["direct_group_ids"] = groupIDs
inheritedGroupIDs := make([]string, len(inheritedGroups))
for i, group := range inheritedGroups {
inheritedGroupIDs[i] = group.ID
}
respData["inherited_group_ids"] = inheritedGroupIDs
respData["group_ids"] = append(groupIDs, inheritedGroupIDs...)
return &logical.Response{
Data: respData,
}, nil
}
// pathEntityIDDelete deletes the entity for a given entity ID
func (i *IdentityStore) pathEntityIDDelete() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
entityID := d.Get("id").(string)
if entityID == "" {
return logical.ErrorResponse("missing entity id"), nil
}
i.lock.Lock()
defer i.lock.Unlock()
// Create a MemDB transaction to delete entity
txn := i.db.Txn(true)
defer txn.Abort()
// Fetch the entity using its ID
entity, err := i.MemDBEntityByIDInTxn(txn, entityID, true)
if err != nil {
return nil, err
}
// If there is no entity for the ID, do nothing
if entity == nil {
return nil, nil
}
ns, err := namespace.FromContext(ctx)
if err != nil {
return nil, err
}
if entity.NamespaceID != ns.ID {
return nil, nil
}
// Delete all the aliases in the entity. This function will also remove
// the corresponding alias indexes too.
err = i.deleteAliasesInEntityInTxn(txn, entity, entity.Aliases)
if err != nil {
return nil, err
}
// Delete the entity using the same transaction
err = i.MemDBDeleteEntityByIDInTxn(txn, entity.ID)
if err != nil {
return nil, err
}
// Delete the entity from storage
err = i.entityPacker.DeleteItem(entity.ID)
if err != nil {
return nil, err
}
// Committing the transaction *after* successfully deleting entity
txn.Commit()
return nil, nil
}
}
// pathEntityNameDelete deletes the entity for a given entity ID
func (i *IdentityStore) pathEntityNameDelete() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
entityName := d.Get("name").(string)
if entityName == "" {
return logical.ErrorResponse("missing entity name"), nil
}
i.lock.Lock()
defer i.lock.Unlock()
// Create a MemDB transaction to delete entity
txn := i.db.Txn(true)
defer txn.Abort()
// Fetch the entity using its name
entity, err := i.MemDBEntityByNameInTxn(ctx, txn, entityName, true)
if err != nil {
return nil, err
}
// If there is no entity for the ID, do nothing
if entity == nil {
return nil, nil
}
ns, err := namespace.FromContext(ctx)
if err != nil {
return nil, err
}
if entity.NamespaceID != ns.ID {
return nil, nil
}
// Delete all the aliases in the entity. This function will also remove
// the corresponding alias indexes too.
err = i.deleteAliasesInEntityInTxn(txn, entity, entity.Aliases)
if err != nil {
return nil, err
}
// Delete the entity using the same transaction
err = i.MemDBDeleteEntityByIDInTxn(txn, entity.ID)
if err != nil {
return nil, err
}
// Delete the entity from storage
err = i.entityPacker.DeleteItem(entity.ID)
if err != nil {
return nil, err
}
// Committing the transaction *after* successfully deleting entity
txn.Commit()
return nil, nil
}
}
func (i *IdentityStore) pathEntityIDList() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
return i.handlePathEntityListCommon(ctx, req, d, true)
}
}
func (i *IdentityStore) pathEntityNameList() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
return i.handlePathEntityListCommon(ctx, req, d, false)
}
}
// handlePathEntityListCommon lists the IDs or names of all the valid entities
// in the identity store
func (i *IdentityStore) handlePathEntityListCommon(ctx context.Context, req *logical.Request, d *framework.FieldData, byID bool) (*logical.Response, error) {
ns, err := namespace.FromContext(ctx)
if err != nil {
return nil, err
}
ws := memdb.NewWatchSet()
txn := i.db.Txn(false)
iter, err := txn.Get(entitiesTable, "namespace_id", ns.ID)
if err != nil {
return nil, errwrap.Wrapf("failed to fetch iterator for entities in memdb: {{err}}", err)
}
ws.Add(iter.WatchCh())
var keys []string
entityInfo := map[string]interface{}{}
type mountInfo struct {
MountType string
MountPath string
}
mountAccessorMap := map[string]mountInfo{}
for {
raw := iter.Next()
if raw == nil {
break
}
entity := raw.(*identity.Entity)
if byID {
keys = append(keys, entity.ID)
} else {
keys = append(keys, entity.Name)
}
entityInfoEntry := map[string]interface{}{
"name": entity.Name,
}
if len(entity.Aliases) > 0 {
aliasList := make([]interface{}, 0, len(entity.Aliases))
for _, alias := range entity.Aliases {
entry := map[string]interface{}{
"id": alias.ID,
"name": alias.Name,
"mount_accessor": alias.MountAccessor,
}
mi, ok := mountAccessorMap[alias.MountAccessor]
if ok {
entry["mount_type"] = mi.MountType
entry["mount_path"] = mi.MountPath
} else {
mi = mountInfo{}
if mountValidationResp := i.core.router.validateMountByAccessor(alias.MountAccessor); mountValidationResp != nil {
mi.MountType = mountValidationResp.MountType
mi.MountPath = mountValidationResp.MountPath
entry["mount_type"] = mi.MountType
entry["mount_path"] = mi.MountPath
}
mountAccessorMap[alias.MountAccessor] = mi
}
aliasList = append(aliasList, entry)
}
entityInfoEntry["aliases"] = aliasList
}
entityInfo[entity.ID] = entityInfoEntry
}
return logical.ListResponseWithInfo(keys, entityInfo), nil
}
func (i *IdentityStore) mergeEntity(ctx context.Context, txn *memdb.Txn, toEntity *identity.Entity, fromEntityIDs []string, force, grabLock, mergePolicies bool) (error, error) {
if grabLock {
i.lock.Lock()
defer i.lock.Unlock()
}
if toEntity == nil {
return errors.New("entity id to merge to is invalid"), nil
}
ns, err := namespace.FromContext(ctx)
if err != nil {
return nil, err
}
if toEntity.NamespaceID != ns.ID {
return errors.New("entity id to merge into does not belong to the request's namespace"), nil
}
// Merge the MFA secrets
for _, fromEntityID := range fromEntityIDs {
if fromEntityID == toEntity.ID {
return errors.New("to_entity_id should not be present in from_entity_ids"), nil
}
fromEntity, err := i.MemDBEntityByID(fromEntityID, false)
if err != nil {
return nil, err
}
if fromEntity == nil {
return errors.New("entity id to merge from is invalid"), nil
}
if fromEntity.NamespaceID != toEntity.NamespaceID {
return errors.New("entity id to merge from does not belong to this namespace"), nil
}
for configID, configSecret := range fromEntity.MFASecrets {
_, ok := toEntity.MFASecrets[configID]
if ok && !force {
return nil, fmt.Errorf("conflicting MFA config ID %q in entity ID %q", configID, fromEntity.ID)
} else {
toEntity.MFASecrets[configID] = configSecret
}
}
}
for _, fromEntityID := range fromEntityIDs {
if fromEntityID == toEntity.ID {
return errors.New("to_entity_id should not be present in from_entity_ids"), nil
}
fromEntity, err := i.MemDBEntityByID(fromEntityID, false)
if err != nil {
return nil, err
}
if fromEntity == nil {
return errors.New("entity id to merge from is invalid"), nil
}
if fromEntity.NamespaceID != toEntity.NamespaceID {
return errors.New("entity id to merge from does not belong to this namespace"), nil
}
for _, alias := range fromEntity.Aliases {
// Set the desired canonical ID
alias.CanonicalID = toEntity.ID
alias.MergedFromCanonicalIDs = append(alias.MergedFromCanonicalIDs, fromEntity.ID)
err = i.MemDBUpsertAliasInTxn(txn, alias, false)
if err != nil {
return nil, errwrap.Wrapf("failed to update alias during merge: {{err}}", err)
}
// Add the alias to the desired entity
toEntity.Aliases = append(toEntity.Aliases, alias)
}
// If told to, merge policies
if mergePolicies {
toEntity.Policies = strutil.MergeSlices(toEntity.Policies, fromEntity.Policies)
}
// If the entity from which we are merging from was already a merged
// entity, transfer over the Merged set to the entity we are
// merging into.
toEntity.MergedEntityIDs = append(toEntity.MergedEntityIDs, fromEntity.MergedEntityIDs...)
// Add the entity from which we are merging from to the list of entities
// the entity we are merging into is composed of.
toEntity.MergedEntityIDs = append(toEntity.MergedEntityIDs, fromEntity.ID)
// Delete the entity which we are merging from in MemDB using the same transaction
err = i.MemDBDeleteEntityByIDInTxn(txn, fromEntity.ID)
if err != nil {
return nil, err
}
// Delete the entity which we are merging from in storage
err = i.entityPacker.DeleteItem(fromEntity.ID)
if err != nil {
return nil, err
}
}
// Update MemDB with changes to the entity we are merging to
err = i.MemDBUpsertEntityInTxn(txn, toEntity)
if err != nil {
return nil, err
}
// Persist the entity which we are merging to
toEntityAsAny, err := ptypes.MarshalAny(toEntity)
if err != nil {
return nil, err
}
item := &storagepacker.Item{
ID: toEntity.ID,
Message: toEntityAsAny,
}
err = i.entityPacker.PutItem(item)
if err != nil {
return nil, err
}
return nil, nil
}
var entityHelp = map[string][2]string{
"entity": {
"Create a new entity",
"",
},
"entity-id": {
"Update, read or delete an entity using entity ID",
"",
},
"entity-name": {
"Update, read or delete an entity using entity name",
"",
},
"entity-id-list": {
"List all the entity IDs",
"",
},
"entity-name-list": {
"List all the entity names",
"",
},
"entity-merge-id": {
"Merge two or more entities together",
"",
},
}