Skip to content

Commit

Permalink
openapi: Add display attributes for Nomad plugin (#19415)
Browse files Browse the repository at this point in the history
Please see #19319 for more details on how this will affect the generated OpenAPI schema.
___

The following OperationID's will be generated for Nomad plugin:

nomad-read-access-configuration
nomad-configure-access
nomad-delete-access-configuration
nomad-read-lease-configuration
nomad-configure-lease
nomad-delete-lease-configuration
nomad-generate-credentials
nomad-list-roles
nomad-read-role
nomad-write-role
nomad-delete-role
  • Loading branch information
averche authored Apr 7, 2023
1 parent 39aa9be commit 827e2f0
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 9 deletions.
2 changes: 2 additions & 0 deletions builtin/logical/nomad/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/hashicorp/vault/sdk/logical"
)

const operationPrefixNomad = "nomad"

// Factory returns a Nomad backend that satisfies the logical.Backend interface
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
b := Backend()
Expand Down
39 changes: 34 additions & 5 deletions builtin/logical/nomad/path_config_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const configAccessKey = "config/access"
func pathConfigAccess(b *backend) *framework.Path {
return &framework.Path{
Pattern: "config/access",

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixNomad,
},

Fields: map[string]*framework.FieldSchema{
"address": {
Type: framework.TypeString,
Expand Down Expand Up @@ -48,11 +53,35 @@ must be x509 PEM encoded and if this is set you need to also set client_cert.`,
},
},

Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ReadOperation: b.pathConfigAccessRead,
logical.CreateOperation: b.pathConfigAccessWrite,
logical.UpdateOperation: b.pathConfigAccessWrite,
logical.DeleteOperation: b.pathConfigAccessDelete,
Operations: map[logical.Operation]framework.OperationHandler{
logical.ReadOperation: &framework.PathOperation{
Callback: b.pathConfigAccessRead,
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "read",
OperationSuffix: "access-configuration",
},
},
logical.CreateOperation: &framework.PathOperation{
Callback: b.pathConfigAccessWrite,
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "configure",
OperationSuffix: "access",
},
},
logical.UpdateOperation: &framework.PathOperation{
Callback: b.pathConfigAccessWrite,
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "configure",
OperationSuffix: "access",
},
},
logical.DeleteOperation: &framework.PathOperation{
Callback: b.pathConfigAccessDelete,
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "delete",
OperationSuffix: "access-configuration",
},
},
},

ExistenceCheck: b.configExistenceCheck,
Expand Down
31 changes: 27 additions & 4 deletions builtin/logical/nomad/path_config_lease.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ const leaseConfigKey = "config/lease"
func pathConfigLease(b *backend) *framework.Path {
return &framework.Path{
Pattern: "config/lease",

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixNomad,
},

Fields: map[string]*framework.FieldSchema{
"ttl": {
Type: framework.TypeDurationSecond,
Expand All @@ -27,10 +32,28 @@ func pathConfigLease(b *backend) *framework.Path {
},
},

Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ReadOperation: b.pathLeaseRead,
logical.UpdateOperation: b.pathLeaseUpdate,
logical.DeleteOperation: b.pathLeaseDelete,
Operations: map[logical.Operation]framework.OperationHandler{
logical.ReadOperation: &framework.PathOperation{
Callback: b.pathLeaseRead,
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "read",
OperationSuffix: "lease-configuration",
},
},
logical.UpdateOperation: &framework.PathOperation{
Callback: b.pathLeaseUpdate,
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "configure",
OperationSuffix: "lease",
},
},
logical.DeleteOperation: &framework.PathOperation{
Callback: b.pathLeaseDelete,
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "delete",
OperationSuffix: "lease-configuration",
},
},
},

HelpSynopsis: pathConfigLeaseHelpSyn,
Expand Down
7 changes: 7 additions & 0 deletions builtin/logical/nomad/path_creds_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ const maxTokenNameLength = 256
func pathCredsCreate(b *backend) *framework.Path {
return &framework.Path{
Pattern: "creds/" + framework.GenericNameRegex("name"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixNomad,
OperationVerb: "generate",
OperationSuffix: "credentials",
},

Fields: map[string]*framework.FieldSchema{
"name": {
Type: framework.TypeString,
Expand Down
11 changes: 11 additions & 0 deletions builtin/logical/nomad/path_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ func pathListRoles(b *backend) *framework.Path {
return &framework.Path{
Pattern: "role/?$",

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixNomad,
OperationSuffix: "roles",
},

Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ListOperation: b.pathRoleList,
},
Expand All @@ -25,6 +30,12 @@ func pathListRoles(b *backend) *framework.Path {
func pathRoles(b *backend) *framework.Path {
return &framework.Path{
Pattern: "role/" + framework.GenericNameRegex("name"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixNomad,
OperationSuffix: "role",
},

Fields: map[string]*framework.FieldSchema{
"name": {
Type: framework.TypeString,
Expand Down

0 comments on commit 827e2f0

Please sign in to comment.