From 56698d6d15aa561396fb8f01e2548907a0a09ea7 Mon Sep 17 00:00:00 2001 From: Anton Averchenkov <84287187+averche@users.noreply.github.com> Date: Thu, 6 Apr 2023 11:11:49 -0400 Subject: [PATCH] openapi: Add display attributes for token/ (#19399) --- vault/token_store.go | 125 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 119 insertions(+), 6 deletions(-) diff --git a/vault/token_store.go b/vault/token_store.go index 818932e90..cac490ebe 100644 --- a/vault/token_store.go +++ b/vault/token_store.go @@ -138,10 +138,17 @@ var ( ) func (ts *TokenStore) paths() []*framework.Path { + const operationPrefixToken = "token" + p := []*framework.Path{ { Pattern: "roles/?$", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationSuffix: "roles", + }, + Callbacks: map[logical.Operation]framework.OperationFunc{ logical.ListOperation: ts.tokenStoreRoleList, }, @@ -153,6 +160,11 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "accessors/$", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationSuffix: "accessors", + }, + Callbacks: map[logical.Operation]framework.OperationFunc{ logical.ListOperation: ts.tokenStoreAccessorList, }, @@ -164,6 +176,12 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "create-orphan$", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "create", + OperationSuffix: "orphan", + }, + Fields: map[string]*framework.FieldSchema{ "role_name": { Type: framework.TypeString, @@ -239,6 +257,12 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "create/" + framework.GenericNameRegex("role_name"), + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "create", + OperationSuffix: "against-role", + }, + Fields: map[string]*framework.FieldSchema{ "role_name": { Type: framework.TypeString, @@ -314,6 +338,11 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "create$", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "create", + }, + Fields: map[string]*framework.FieldSchema{ "display_name": { Type: framework.TypeString, @@ -385,6 +414,11 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "lookup", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "look-up", + }, + Fields: map[string]*framework.FieldSchema{ "token": { Type: framework.TypeString, @@ -392,9 +426,16 @@ func (ts *TokenStore) paths() []*framework.Path { }, }, - Callbacks: map[logical.Operation]framework.OperationFunc{ - logical.ReadOperation: ts.handleLookup, - logical.UpdateOperation: ts.handleLookup, + Operations: map[logical.Operation]framework.OperationHandler{ + logical.ReadOperation: &framework.PathOperation{ + Callback: ts.handleLookup, + DisplayAttrs: &framework.DisplayAttributes{ + OperationSuffix: "self3", // avoid collision with lookup-self + }, + }, + logical.UpdateOperation: &framework.PathOperation{ + Callback: ts.handleLookup, + }, }, HelpSynopsis: strings.TrimSpace(tokenLookupHelp), @@ -404,6 +445,12 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "lookup-accessor", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "look-up", + OperationSuffix: "accessor", + }, + Fields: map[string]*framework.FieldSchema{ "accessor": { Type: framework.TypeString, @@ -422,6 +469,11 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "lookup-self$", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "look-up", + }, + Fields: map[string]*framework.FieldSchema{ "token": { Type: framework.TypeString, @@ -429,9 +481,19 @@ func (ts *TokenStore) paths() []*framework.Path { }, }, - Callbacks: map[logical.Operation]framework.OperationFunc{ - logical.UpdateOperation: ts.handleLookupSelf, - logical.ReadOperation: ts.handleLookupSelf, + Operations: map[logical.Operation]framework.OperationHandler{ + logical.ReadOperation: &framework.PathOperation{ + Callback: ts.handleLookupSelf, + DisplayAttrs: &framework.DisplayAttributes{ + OperationSuffix: "self", + }, + }, + logical.UpdateOperation: &framework.PathOperation{ + Callback: ts.handleLookupSelf, + DisplayAttrs: &framework.DisplayAttributes{ + OperationSuffix: "self2", + }, + }, }, HelpSynopsis: strings.TrimSpace(tokenLookupHelp), @@ -441,6 +503,12 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "revoke-accessor", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "revoke", + OperationSuffix: "accessor", + }, + Fields: map[string]*framework.FieldSchema{ "accessor": { Type: framework.TypeString, @@ -459,6 +527,12 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "revoke-self$", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "revoke", + OperationSuffix: "self", + }, + Callbacks: map[logical.Operation]framework.OperationFunc{ logical.UpdateOperation: ts.handleRevokeSelf, }, @@ -470,6 +544,11 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "revoke", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "revoke", + }, + Fields: map[string]*framework.FieldSchema{ "token": { Type: framework.TypeString, @@ -488,6 +567,12 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "revoke-orphan", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "revoke", + OperationSuffix: "orphan", + }, + Fields: map[string]*framework.FieldSchema{ "token": { Type: framework.TypeString, @@ -506,6 +591,12 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "renew-accessor", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "renew", + OperationSuffix: "accessor", + }, + Fields: map[string]*framework.FieldSchema{ "accessor": { Type: framework.TypeString, @@ -529,6 +620,12 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "renew-self$", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "renew", + OperationSuffix: "self", + }, + Fields: map[string]*framework.FieldSchema{ "token": { Type: framework.TypeString, @@ -552,6 +649,11 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "renew", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "renew", + }, + Fields: map[string]*framework.FieldSchema{ "token": { Type: framework.TypeString, @@ -575,6 +677,11 @@ func (ts *TokenStore) paths() []*framework.Path { { Pattern: "tidy$", + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationVerb: "tidy", + }, + Callbacks: map[logical.Operation]framework.OperationFunc{ logical.UpdateOperation: ts.handleTidy, }, @@ -586,6 +693,12 @@ func (ts *TokenStore) paths() []*framework.Path { rolesPath := &framework.Path{ Pattern: "roles/" + framework.GenericNameRegex("role_name"), + + DisplayAttrs: &framework.DisplayAttributes{ + OperationPrefix: operationPrefixToken, + OperationSuffix: "role", + }, + Fields: map[string]*framework.FieldSchema{ "role_name": { Type: framework.TypeString,