Skip to content

Commit

Permalink
openapi: Add display attributes for token/ (#19399)
Browse files Browse the repository at this point in the history
  • Loading branch information
averche committed Apr 6, 2023
1 parent 74881dd commit d7ecfa0
Showing 1 changed file with 119 additions and 6 deletions.
125 changes: 119 additions & 6 deletions vault/token_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand All @@ -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,
},
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -385,16 +414,28 @@ 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,
Description: "Token to lookup (POST request body)",
},
},

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),
Expand All @@ -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,
Expand All @@ -422,16 +469,31 @@ 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,
Description: "Token to look up (unused, does not need to be set)",
},
},

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),
Expand All @@ -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,
Expand All @@ -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,
},
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
},
Expand All @@ -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,
Expand Down

0 comments on commit d7ecfa0

Please sign in to comment.