2017-10-11 17:21:20 +00:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
2018-01-08 18:31:38 +00:00
|
|
|
"context"
|
2017-10-11 17:21:20 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/golang/protobuf/ptypes"
|
|
|
|
"github.com/hashicorp/vault/helper/identity"
|
2018-09-18 03:03:00 +00:00
|
|
|
"github.com/hashicorp/vault/helper/namespace"
|
2018-06-24 11:45:53 +00:00
|
|
|
"github.com/hashicorp/vault/helper/storagepacker"
|
2017-10-11 17:21:20 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
|
|
|
// aliasPaths returns the API endpoints to operate on aliases.
|
|
|
|
// Following are the paths supported:
|
2017-11-14 01:59:42 +00:00
|
|
|
// entity-alias - To register/modify an alias
|
|
|
|
// entity-alias/id - To read, modify, delete and list aliases based on their ID
|
2017-10-11 17:21:20 +00:00
|
|
|
func aliasPaths(i *IdentityStore) []*framework.Path {
|
|
|
|
return []*framework.Path{
|
2017-11-02 20:05:48 +00:00
|
|
|
{
|
|
|
|
Pattern: "entity-alias$",
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
|
|
|
"id": {
|
|
|
|
Type: framework.TypeString,
|
2017-11-14 01:59:42 +00:00
|
|
|
Description: "ID of the entity alias. If set, updates the corresponding entity alias.",
|
2017-11-02 20:05:48 +00:00
|
|
|
},
|
2017-11-14 01:59:42 +00:00
|
|
|
// entity_id is deprecated in favor of canonical_id
|
2017-11-02 20:05:48 +00:00
|
|
|
"entity_id": {
|
2018-07-25 02:01:58 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: `Entity ID to which this alias belongs.
|
|
|
|
This field is deprecated, use canonical_id.`,
|
2017-11-02 20:05:48 +00:00
|
|
|
},
|
|
|
|
"canonical_id": {
|
|
|
|
Type: framework.TypeString,
|
2018-07-25 02:01:58 +00:00
|
|
|
Description: "Entity ID to which this alias belongs",
|
2017-11-02 20:05:48 +00:00
|
|
|
},
|
|
|
|
"mount_accessor": {
|
|
|
|
Type: framework.TypeString,
|
2018-07-25 02:01:58 +00:00
|
|
|
Description: "Mount accessor to which this alias belongs to; unused for a modify",
|
2017-11-02 20:05:48 +00:00
|
|
|
},
|
|
|
|
"name": {
|
|
|
|
Type: framework.TypeString,
|
2018-07-25 02:01:58 +00:00
|
|
|
Description: "Name of the alias; unused for a modify",
|
2017-11-02 20:05:48 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
2018-07-25 02:01:58 +00:00
|
|
|
logical.UpdateOperation: i.handleAliasUpdateCommon(),
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: strings.TrimSpace(aliasHelp["alias"][0]),
|
|
|
|
HelpDescription: strings.TrimSpace(aliasHelp["alias"][1]),
|
|
|
|
},
|
2017-11-02 20:05:48 +00:00
|
|
|
{
|
|
|
|
Pattern: "entity-alias/id/" + framework.GenericNameRegex("id"),
|
|
|
|
Fields: map[string]*framework.FieldSchema{
|
|
|
|
"id": {
|
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: "ID of the alias",
|
|
|
|
},
|
|
|
|
// entity_id is deprecated
|
|
|
|
"entity_id": {
|
2018-07-25 02:01:58 +00:00
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: `Entity ID to which this alias belongs to.
|
|
|
|
This field is deprecated, use canonical_id.`,
|
2017-11-02 20:05:48 +00:00
|
|
|
},
|
|
|
|
"canonical_id": {
|
|
|
|
Type: framework.TypeString,
|
|
|
|
Description: "Entity ID to which this alias should be tied to",
|
|
|
|
},
|
|
|
|
"mount_accessor": {
|
|
|
|
Type: framework.TypeString,
|
2018-07-25 02:01:58 +00:00
|
|
|
Description: "(Unused)",
|
2017-11-02 20:05:48 +00:00
|
|
|
},
|
|
|
|
"name": {
|
|
|
|
Type: framework.TypeString,
|
2018-07-25 02:01:58 +00:00
|
|
|
Description: "(Unused)",
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
2018-07-25 02:01:58 +00:00
|
|
|
logical.UpdateOperation: i.handleAliasUpdateCommon(),
|
2018-01-08 18:31:38 +00:00
|
|
|
logical.ReadOperation: i.pathAliasIDRead(),
|
|
|
|
logical.DeleteOperation: i.pathAliasIDDelete(),
|
2017-10-11 17:21:20 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
HelpSynopsis: strings.TrimSpace(aliasHelp["alias-id"][0]),
|
|
|
|
HelpDescription: strings.TrimSpace(aliasHelp["alias-id"][1]),
|
|
|
|
},
|
2017-11-02 20:05:48 +00:00
|
|
|
{
|
|
|
|
Pattern: "entity-alias/id/?$",
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
2018-01-08 18:31:38 +00:00
|
|
|
logical.ListOperation: i.pathAliasIDList(),
|
2017-11-02 20:05:48 +00:00
|
|
|
},
|
|
|
|
|
2017-10-11 17:21:20 +00:00
|
|
|
HelpSynopsis: strings.TrimSpace(aliasHelp["alias-id-list"][0]),
|
|
|
|
HelpDescription: strings.TrimSpace(aliasHelp["alias-id-list"][1]),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// handleAliasUpdateCommon is used to update an alias
|
|
|
|
func (i *IdentityStore) handleAliasUpdateCommon() framework.OperationFunc {
|
2018-01-08 18:31:38 +00:00
|
|
|
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
2018-07-25 02:01:58 +00:00
|
|
|
var err error
|
|
|
|
var alias *identity.Alias
|
|
|
|
var entity *identity.Entity
|
|
|
|
var previousEntity *identity.Entity
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
i.lock.Lock()
|
|
|
|
defer i.lock.Unlock()
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Check for update or create
|
2018-01-08 18:31:38 +00:00
|
|
|
aliasID := d.Get("id").(string)
|
2018-07-25 02:01:58 +00:00
|
|
|
if aliasID != "" {
|
|
|
|
alias, err = i.MemDBAliasByID(aliasID, true, false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if alias == nil {
|
|
|
|
return logical.ErrorResponse("invalid alias id"), nil
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
alias = &identity.Alias{}
|
2018-01-08 18:31:38 +00:00
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Get entity id
|
|
|
|
canonicalID := d.Get("canonical_id").(string)
|
|
|
|
if canonicalID == "" {
|
|
|
|
// For backwards compatibility
|
|
|
|
canonicalID = d.Get("entity_id").(string)
|
2018-01-08 18:31:38 +00:00
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Get alias name
|
|
|
|
if aliasName := d.Get("name").(string); aliasName == "" {
|
|
|
|
if alias.Name == "" {
|
|
|
|
return logical.ErrorResponse("missing alias name"), nil
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
alias.Name = aliasName
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Get mount accessor
|
|
|
|
if mountAccessor := d.Get("mount_accessor").(string); mountAccessor == "" {
|
|
|
|
if alias.MountAccessor == "" {
|
|
|
|
return logical.ErrorResponse("missing mount_accessor"), nil
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
alias.MountAccessor = mountAccessor
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
mountValidationResp := i.core.router.validateMountByAccessor(alias.MountAccessor)
|
|
|
|
if mountValidationResp == nil {
|
|
|
|
return logical.ErrorResponse(fmt.Sprintf("invalid mount accessor %q", alias.MountAccessor)), nil
|
|
|
|
}
|
|
|
|
if mountValidationResp.MountLocal {
|
|
|
|
return logical.ErrorResponse(fmt.Sprintf("mount_accessor %q is of a local mount", alias.MountAccessor)), nil
|
|
|
|
}
|
2017-11-02 20:05:48 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Verify that the combination of alias name and mount is not
|
|
|
|
// already tied to a different alias
|
|
|
|
aliasByFactors, err := i.MemDBAliasByFactors(mountValidationResp.MountAccessor, alias.Name, false, false)
|
2017-10-11 17:21:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if aliasByFactors != nil {
|
2018-07-25 02:01:58 +00:00
|
|
|
// If it's a create we won't have an alias ID so this will correctly
|
|
|
|
// bail. If it's an update alias will be the same as aliasbyfactors so
|
|
|
|
// we don't need to transfer any info over
|
|
|
|
if aliasByFactors.ID != alias.ID {
|
|
|
|
return logical.ErrorResponse("combination of mount and alias name is already in use"), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fetch the entity to which the alias is tied. We don't need to append
|
|
|
|
// here, so the only further checking is whether the canonical ID is
|
|
|
|
// different
|
|
|
|
entity, err = i.MemDBEntityByAliasID(alias.ID, true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if entity == nil {
|
|
|
|
return nil, fmt.Errorf("existing alias is not associated with an entity")
|
|
|
|
}
|
2018-11-08 18:04:24 +00:00
|
|
|
} else if alias.ID != "" {
|
|
|
|
// This is an update, not a create; if we have an associated entity
|
|
|
|
// already, load it
|
|
|
|
entity, err = i.MemDBEntityByAliasID(alias.ID, true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
resp := &logical.Response{}
|
|
|
|
|
|
|
|
// If we found an exisitng alias we won't hit this condition because
|
|
|
|
// canonicalID being empty will result in nil being returned in the block
|
|
|
|
// above, so in this case we know that creating a new entity is the right
|
|
|
|
// thing.
|
|
|
|
if canonicalID == "" {
|
2017-10-11 17:21:20 +00:00
|
|
|
entity = &identity.Entity{
|
|
|
|
Aliases: []*identity.Alias{
|
|
|
|
alias,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else {
|
2018-07-25 02:01:58 +00:00
|
|
|
// If we can look up by the given canonical ID, see if this is a
|
|
|
|
// transfer; otherwise if we found no previous entity but we find one
|
|
|
|
// here, use it.
|
|
|
|
canonicalEntity, err := i.MemDBEntityByID(canonicalID, true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
2018-07-25 02:01:58 +00:00
|
|
|
if canonicalEntity == nil {
|
|
|
|
return logical.ErrorResponse("invalid canonical ID"), nil
|
2018-06-24 11:45:53 +00:00
|
|
|
}
|
2018-07-25 02:01:58 +00:00
|
|
|
if entity == nil {
|
|
|
|
// If entity is nil, we didn't find a previous alias from factors,
|
|
|
|
// so append to this entity
|
|
|
|
entity = canonicalEntity
|
|
|
|
entity.Aliases = append(entity.Aliases, alias)
|
|
|
|
} else if entity.ID != canonicalEntity.ID {
|
2018-11-08 18:04:24 +00:00
|
|
|
// In this case we found an entity from alias factors or given
|
|
|
|
// alias ID but it's not the same, so it's a migration
|
2018-07-25 02:01:58 +00:00
|
|
|
previousEntity = entity
|
|
|
|
entity = canonicalEntity
|
|
|
|
|
|
|
|
for aliasIndex, item := range previousEntity.Aliases {
|
|
|
|
if item.ID == alias.ID {
|
|
|
|
previousEntity.Aliases = append(previousEntity.Aliases[:aliasIndex], previousEntity.Aliases[aliasIndex+1:]...)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2018-06-24 11:45:53 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
entity.Aliases = append(entity.Aliases, alias)
|
|
|
|
resp.AddWarning(fmt.Sprintf("alias is being transferred from entity %q to %q", previousEntity.ID, entity.ID))
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// ID creation and other validations; This is more useful for new entities
|
|
|
|
// and may not perform anything for the existing entities. Placing the
|
|
|
|
// check here to make the flow common for both new and existing entities.
|
2018-09-18 03:03:00 +00:00
|
|
|
err = i.sanitizeEntity(ctx, entity)
|
2018-07-25 02:01:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Explicitly set to empty as in the past we incorrectly saved it
|
|
|
|
alias.MountPath = ""
|
|
|
|
alias.MountType = ""
|
2018-05-25 18:34:24 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Set the canonical ID in the alias index. This should be done after
|
|
|
|
// sanitizing entity.
|
|
|
|
alias.CanonicalID = entity.ID
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// ID creation and other validations
|
2018-09-18 03:03:00 +00:00
|
|
|
err = i.sanitizeAlias(ctx, alias)
|
2018-07-25 02:01:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-10-19 19:47:26 +00:00
|
|
|
for index, item := range entity.Aliases {
|
|
|
|
if item.ID == alias.ID {
|
|
|
|
entity.Aliases[index] = alias
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Index entity and its aliases in MemDB and persist entity along with
|
|
|
|
// aliases in storage. If the alias is being transferred over from
|
|
|
|
// one entity to another, previous entity needs to get refreshed in MemDB
|
|
|
|
// and persisted in storage as well.
|
2018-09-18 03:03:00 +00:00
|
|
|
if err := i.upsertEntity(ctx, entity, previousEntity, true); err != nil {
|
2018-07-25 02:01:58 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Return ID of both alias and entity
|
|
|
|
resp.Data = map[string]interface{}{
|
|
|
|
"id": alias.ID,
|
|
|
|
"canonical_id": entity.ID,
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
return resp, nil
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:05:48 +00:00
|
|
|
// pathAliasIDRead returns the properties of an alias for a given
|
2017-10-11 17:21:20 +00:00
|
|
|
// alias ID
|
2018-01-08 18:31:38 +00:00
|
|
|
func (i *IdentityStore) pathAliasIDRead() framework.OperationFunc {
|
|
|
|
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
|
|
aliasID := d.Get("id").(string)
|
|
|
|
if aliasID == "" {
|
|
|
|
return logical.ErrorResponse("missing alias id"), nil
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-01-08 18:31:38 +00:00
|
|
|
alias, err := i.MemDBAliasByID(aliasID, false, false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
return i.handleAliasReadCommon(ctx, alias)
|
2018-01-08 18:31:38 +00:00
|
|
|
}
|
2017-11-02 20:05:48 +00:00
|
|
|
}
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
func (i *IdentityStore) handleAliasReadCommon(ctx context.Context, alias *identity.Alias) (*logical.Response, error) {
|
2017-10-11 17:21:20 +00:00
|
|
|
if alias == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
ns, err := namespace.FromContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if ns.ID != alias.NamespaceID {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2017-10-11 17:21:20 +00:00
|
|
|
respData := map[string]interface{}{}
|
|
|
|
respData["id"] = alias.ID
|
2017-11-02 20:05:48 +00:00
|
|
|
respData["canonical_id"] = alias.CanonicalID
|
2017-10-11 17:21:20 +00:00
|
|
|
respData["mount_accessor"] = alias.MountAccessor
|
|
|
|
respData["metadata"] = alias.Metadata
|
|
|
|
respData["name"] = alias.Name
|
2017-11-02 20:05:48 +00:00
|
|
|
respData["merged_from_canonical_ids"] = alias.MergedFromCanonicalIDs
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-05-25 18:34:24 +00:00
|
|
|
if mountValidationResp := i.core.router.validateMountByAccessor(alias.MountAccessor); mountValidationResp != nil {
|
|
|
|
respData["mount_path"] = mountValidationResp.MountPath
|
|
|
|
respData["mount_type"] = mountValidationResp.MountType
|
|
|
|
}
|
|
|
|
|
2017-10-11 17:21:20 +00:00
|
|
|
// Convert protobuf timestamp into RFC3339 format
|
|
|
|
respData["creation_time"] = ptypes.TimestampString(alias.CreationTime)
|
|
|
|
respData["last_update_time"] = ptypes.TimestampString(alias.LastUpdateTime)
|
|
|
|
|
|
|
|
return &logical.Response{
|
|
|
|
Data: respData,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:05:48 +00:00
|
|
|
// pathAliasIDDelete deletes the alias for a given alias ID
|
2018-01-08 18:31:38 +00:00
|
|
|
func (i *IdentityStore) pathAliasIDDelete() framework.OperationFunc {
|
|
|
|
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
|
|
aliasID := d.Get("id").(string)
|
|
|
|
if aliasID == "" {
|
|
|
|
return logical.ErrorResponse("missing alias ID"), nil
|
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
i.lock.Lock()
|
|
|
|
defer i.lock.Unlock()
|
2018-06-24 11:45:53 +00:00
|
|
|
|
|
|
|
// Create a MemDB transaction to delete entity
|
|
|
|
txn := i.db.Txn(true)
|
|
|
|
defer txn.Abort()
|
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Fetch the alias
|
|
|
|
alias, err := i.MemDBAliasByIDInTxn(txn, aliasID, false, false)
|
2018-06-24 11:45:53 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no alias for the ID, do nothing
|
|
|
|
if alias == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2018-09-18 03:03:00 +00:00
|
|
|
ns, err := namespace.FromContext(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if ns.ID != alias.NamespaceID {
|
|
|
|
return nil, logical.ErrUnsupportedPath
|
|
|
|
}
|
|
|
|
|
2018-07-25 02:01:58 +00:00
|
|
|
// Fetch the associated entity
|
2018-06-24 11:45:53 +00:00
|
|
|
entity, err := i.MemDBEntityByAliasIDInTxn(txn, alias.ID, true)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there is no entity tied to a valid alias, something is wrong
|
|
|
|
if entity == nil {
|
|
|
|
return nil, fmt.Errorf("alias not associated to an entity")
|
|
|
|
}
|
|
|
|
|
|
|
|
aliases := []*identity.Alias{
|
|
|
|
alias,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete alias from the entity object
|
|
|
|
err = i.deleteAliasesInEntityInTxn(txn, entity, aliases)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the entity index in the entities table
|
|
|
|
err = i.MemDBUpsertEntityInTxn(txn, entity)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Persist the entity object
|
|
|
|
entityAsAny, err := ptypes.MarshalAny(entity)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
item := &storagepacker.Item{
|
|
|
|
ID: entity.ID,
|
|
|
|
Message: entityAsAny,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = i.entityPacker.PutItem(item)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Committing the transaction *after* successfully updating entity in
|
|
|
|
// storage
|
|
|
|
txn.Commit()
|
|
|
|
|
|
|
|
return nil, nil
|
2018-01-08 18:31:38 +00:00
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// pathAliasIDList lists the IDs of all the valid aliases in the identity
|
|
|
|
// store
|
2018-01-08 18:31:38 +00:00
|
|
|
func (i *IdentityStore) pathAliasIDList() framework.OperationFunc {
|
|
|
|
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
2018-09-18 03:03:00 +00:00
|
|
|
return i.handleAliasListCommon(ctx, false)
|
2018-01-08 18:31:38 +00:00
|
|
|
}
|
2017-10-11 17:21:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var aliasHelp = map[string][2]string{
|
|
|
|
"alias": {
|
2017-11-02 20:05:48 +00:00
|
|
|
"Create a new alias.",
|
2017-10-11 17:21:20 +00:00
|
|
|
"",
|
|
|
|
},
|
|
|
|
"alias-id": {
|
2017-11-02 20:05:48 +00:00
|
|
|
"Update, read or delete an alias ID.",
|
2017-10-11 17:21:20 +00:00
|
|
|
"",
|
|
|
|
},
|
|
|
|
"alias-id-list": {
|
2018-04-17 17:54:04 +00:00
|
|
|
"List all the alias IDs.",
|
2017-10-11 17:21:20 +00:00
|
|
|
"",
|
|
|
|
},
|
|
|
|
}
|