Skip to content

Commit

Permalink
API refactoring and doc updates (#3577)
Browse files Browse the repository at this point in the history
* Doc updates and API refactoring

* fix tests

* change metadata fieldtype to TypeKVPairs

* Give example for TypeKVPairs in CLI for metadata

* Update API docs examples to reflect the native expected value for TypeKVPairs

* Don't mention comma separation in the docs for TypeCommaStringSlice

* s/groups/group; s/entities/entity; s/entity-aliases/entity-alias; s/group-aliases/group-alias

* Address review feedback

* Fix formatting

* fix sidebar links
  • Loading branch information
vishalnayak authored Nov 14, 2017
1 parent 58ce26a commit b659e94
Show file tree
Hide file tree
Showing 14 changed files with 1,143 additions and 500 deletions.
81 changes: 22 additions & 59 deletions vault/identity_store_aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ import (

// aliasPaths returns the API endpoints to operate on aliases.
// Following are the paths supported:
// alias - To register/modify an alias
// alias/id - To lookup, delete and list aliases based on ID
// entity-alias - To register/modify an alias
// entity-alias/id - To read, modify, delete and list aliases based on their ID
func aliasPaths(i *IdentityStore) []*framework.Path {
return []*framework.Path{
{
Pattern: "entity-alias$",
Fields: map[string]*framework.FieldSchema{
"id": {
Type: framework.TypeString,
Description: "ID of the alias",
Description: "ID of the entity alias. If set, updates the corresponding entity alias.",
},
// entity_id is deprecated
// entity_id is deprecated in favor of canonical_id
"entity_id": {
Type: framework.TypeString,
Description: "Entity ID to which this alias belongs to",
Expand All @@ -42,8 +42,12 @@ func aliasPaths(i *IdentityStore) []*framework.Path {
Description: "Name of the alias",
},
"metadata": {
Type: framework.TypeKVPairs,
Description: "Metadata to be associated with the alias.",
Type: framework.TypeKVPairs,
Description: `Metadata to be associated with the alias.
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
`,
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
Expand Down Expand Up @@ -79,8 +83,12 @@ func aliasPaths(i *IdentityStore) []*framework.Path {
Description: "Name of the alias",
},
"metadata": {
Type: framework.TypeKVPairs,
Description: "Metadata to be associated with the alias.",
Type: framework.TypeKVPairs,
Description: `Metadata to be associated with the alias.
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
`,
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
Expand Down Expand Up @@ -115,47 +123,12 @@ func aliasPaths(i *IdentityStore) []*framework.Path {
Description: "Name of the alias",
},
"metadata": {
Type: framework.TypeKVPairs,
Description: "Metadata to be associated with the alias.",
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: i.pathAliasIDUpdate,
logical.ReadOperation: i.pathAliasIDRead,
logical.DeleteOperation: i.pathAliasIDDelete,
},

HelpSynopsis: strings.TrimSpace(aliasHelp["alias-id"][0]),
HelpDescription: strings.TrimSpace(aliasHelp["alias-id"][1]),
},
// BC path for identity/entity-alias/id/<id>
{
Pattern: "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": {
Type: framework.TypeString,
Description: "Entity ID to which this alias should be tied to",
},
"canonical_id": {
Type: framework.TypeString,
Description: "Entity ID to which this alias should be tied to",
},
"mount_accessor": {
Type: framework.TypeString,
Description: "Mount accessor to which this alias belongs to",
},
"name": {
Type: framework.TypeString,
Description: "Name of the alias",
},
"metadata": {
Type: framework.TypeKVPairs,
Description: "Metadata to be associated with the alias.",
Type: framework.TypeKVPairs,
Description: `Metadata to be associated with the alias.
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
`,
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
Expand All @@ -173,16 +146,6 @@ func aliasPaths(i *IdentityStore) []*framework.Path {
logical.ListOperation: i.pathAliasIDList,
},

HelpSynopsis: strings.TrimSpace(aliasHelp["alias-id-list"][0]),
HelpDescription: strings.TrimSpace(aliasHelp["alias-id-list"][1]),
},
// BC path for identity/alias/id
{
Pattern: "alias/id/?$",
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ListOperation: i.pathAliasIDList,
},

HelpSynopsis: strings.TrimSpace(aliasHelp["alias-id-list"][0]),
HelpDescription: strings.TrimSpace(aliasHelp["alias-id-list"][1]),
},
Expand Down
22 changes: 11 additions & 11 deletions vault/identity_store_aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestIdentityStore_ListAlias(t *testing.T) {
}
aliasReq := &logical.Request{
Operation: logical.UpdateOperation,
Path: "alias",
Path: "entity-alias",
Data: aliasData,
}
resp, err = is.HandleRequest(aliasReq)
Expand All @@ -51,7 +51,7 @@ func TestIdentityStore_ListAlias(t *testing.T) {

listReq := &logical.Request{
Operation: logical.ListOperation,
Path: "alias/id",
Path: "entity-alias/id",
}
resp, err = is.HandleRequest(listReq)
if err != nil || (resp != nil && resp.IsError()) {
Expand All @@ -78,7 +78,7 @@ func TestIdentityStore_AliasSameAliasNames(t *testing.T) {

aliasReq := &logical.Request{
Operation: logical.UpdateOperation,
Path: "alias",
Path: "entity-alias",
Data: aliasData,
}

Expand Down Expand Up @@ -285,7 +285,7 @@ func TestIdentityStore_AliasRegister(t *testing.T) {

aliasReq := &logical.Request{
Operation: logical.UpdateOperation,
Path: "alias",
Path: "entity-alias",
Data: aliasData,
}

Expand Down Expand Up @@ -329,7 +329,7 @@ func TestIdentityStore_AliasUpdate(t *testing.T) {

aliasReq := &logical.Request{
Operation: logical.UpdateOperation,
Path: "alias",
Path: "entity-alias",
Data: aliasData,
}

Expand All @@ -347,7 +347,7 @@ func TestIdentityStore_AliasUpdate(t *testing.T) {
}

aliasReq.Data = updateData
aliasReq.Path = "alias/id/" + aliasID
aliasReq.Path = "entity-alias/id/" + aliasID
resp, err = is.HandleRequest(aliasReq)
if err != nil || (resp != nil && resp.IsError()) {
t.Fatalf("err:%v resp:%#v", err, resp)
Expand Down Expand Up @@ -381,7 +381,7 @@ func TestIdentityStore_AliasUpdate_ByID(t *testing.T) {

updateReq := &logical.Request{
Operation: logical.UpdateOperation,
Path: "alias/id/invalidaliasid",
Path: "entity-alias/id/invalidaliasid",
Data: updateData,
}

Expand All @@ -402,7 +402,7 @@ func TestIdentityStore_AliasUpdate_ByID(t *testing.T) {

registerReq := &logical.Request{
Operation: logical.UpdateOperation,
Path: "alias",
Path: "entity-alias",
Data: registerData,
}

Expand All @@ -420,7 +420,7 @@ func TestIdentityStore_AliasUpdate_ByID(t *testing.T) {
t.Fatalf("invalid alias id")
}

updateReq.Path = "alias/id/" + id
updateReq.Path = "entity-alias/id/" + id
resp, err = is.HandleRequest(updateReq)
if err != nil || (resp != nil && resp.IsError()) {
t.Fatalf("err:%v resp:%#v", err, resp)
Expand Down Expand Up @@ -479,7 +479,7 @@ func TestIdentityStore_AliasReadDelete(t *testing.T) {

registerReq := &logical.Request{
Operation: logical.UpdateOperation,
Path: "alias",
Path: "entity-alias",
Data: registerData,
}

Expand All @@ -500,7 +500,7 @@ func TestIdentityStore_AliasReadDelete(t *testing.T) {
// Read it back using alias id
aliasReq := &logical.Request{
Operation: logical.ReadOperation,
Path: "alias/id/" + id,
Path: "entity-alias/id/" + id,
}
resp, err = is.HandleRequest(aliasReq)
if err != nil || (resp != nil && resp.IsError()) {
Expand Down
26 changes: 17 additions & 9 deletions vault/identity_store_entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,23 @@ func entityPaths(i *IdentityStore) []*framework.Path {
Fields: map[string]*framework.FieldSchema{
"id": {
Type: framework.TypeString,
Description: "ID of the entity",
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.",
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",
Description: "Policies to be tied to the entity.",
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
Expand All @@ -52,19 +56,23 @@ func entityPaths(i *IdentityStore) []*framework.Path {
Fields: map[string]*framework.FieldSchema{
"id": {
Type: framework.TypeString,
Description: "ID of the entity",
Description: "ID of the entity.",
},
"name": {
Type: framework.TypeString,
Description: "Name of the entity",
Description: "Name of the entity.",
},
"metadata": {
Type: framework.TypeKVPairs,
Description: "Metadata to be associated with the entity.",
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",
Description: "Policies to be tied to the entity.",
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
Expand Down
1 change: 0 additions & 1 deletion vault/identity_store_group_aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func groupAliasPaths(i *IdentityStore) []*framework.Path {
},
},
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.UpdateOperation: i.pathGroupAliasIDUpdate,
logical.ReadOperation: i.pathGroupAliasIDRead,
logical.DeleteOperation: i.pathGroupAliasIDDelete,
},
Expand Down
18 changes: 13 additions & 5 deletions vault/identity_store_groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func groupPaths(i *IdentityStore) []*framework.Path {
Fields: map[string]*framework.FieldSchema{
"id": {
Type: framework.TypeString,
Description: "ID of the group.",
Description: "ID of the group. If set, updates the corresponding existing group.",
},
"type": {
Type: framework.TypeString,
Expand All @@ -34,8 +34,12 @@ func groupPaths(i *IdentityStore) []*framework.Path {
Description: "Name of the group.",
},
"metadata": {
Type: framework.TypeKVPairs,
Description: "Metadata to be associated with the group.",
Type: framework.TypeKVPairs,
Description: `Metadata to be associated with the group.
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,
Expand Down Expand Up @@ -74,8 +78,12 @@ func groupPaths(i *IdentityStore) []*framework.Path {
Description: "Name of the group.",
},
"metadata": {
Type: framework.TypeKVPairs,
Description: "Metadata to be associated with the group.",
Type: framework.TypeKVPairs,
Description: `Metadata to be associated with the group.
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,
Expand Down
Loading

0 comments on commit b659e94

Please sign in to comment.