Skip to content

Commit

Permalink
openapi: Add display attributes for database plugin (hashicorp#19414)
Browse files Browse the repository at this point in the history
  • Loading branch information
averche authored Apr 10, 2023
1 parent 4ba78d7 commit 4ff6b62
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 11 deletions.
9 changes: 5 additions & 4 deletions builtin/logical/database/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ import (
)

const (
databaseConfigPath = "config/"
databaseRolePath = "role/"
databaseStaticRolePath = "static-role/"
minRootCredRollbackAge = 1 * time.Minute
operationPrefixDatabase = "database"
databaseConfigPath = "config/"
databaseRolePath = "role/"
databaseStaticRolePath = "static-role/"
minRootCredRollbackAge = 1 * time.Minute
)

type dbPluginInstance struct {
Expand Down
52 changes: 47 additions & 5 deletions builtin/logical/database/path_config_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ func (c *DatabaseConfig) SupportsCredentialType(credentialType v5.CredentialType
func pathResetConnection(b *databaseBackend) *framework.Path {
return &framework.Path{
Pattern: fmt.Sprintf("reset/%s", framework.GenericNameRegex("name")),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixDatabase,
OperationVerb: "reset",
OperationSuffix: "connection",
},

Fields: map[string]*framework.FieldSchema{
"name": {
Type: framework.TypeString,
Expand Down Expand Up @@ -106,6 +113,11 @@ func (b *databaseBackend) pathConnectionReset() framework.OperationFunc {
func pathConfigurePluginConnection(b *databaseBackend) *framework.Path {
return &framework.Path{
Pattern: fmt.Sprintf("config/%s", framework.GenericNameRegex("name")),

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

Fields: map[string]*framework.FieldSchema{
"name": {
Type: framework.TypeString,
Expand Down Expand Up @@ -152,11 +164,36 @@ func pathConfigurePluginConnection(b *databaseBackend) *framework.Path {
},

ExistenceCheck: b.connectionExistenceCheck(),
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.CreateOperation: b.connectionWriteHandler(),
logical.UpdateOperation: b.connectionWriteHandler(),
logical.ReadOperation: b.connectionReadHandler(),
logical.DeleteOperation: b.connectionDeleteHandler(),

Operations: map[logical.Operation]framework.OperationHandler{
logical.CreateOperation: &framework.PathOperation{
Callback: b.connectionWriteHandler(),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "configure",
OperationSuffix: "connection",
},
},
logical.UpdateOperation: &framework.PathOperation{
Callback: b.connectionWriteHandler(),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "configure",
OperationSuffix: "connection",
},
},
logical.ReadOperation: &framework.PathOperation{
Callback: b.connectionReadHandler(),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "read",
OperationSuffix: "connection-configuration",
},
},
logical.DeleteOperation: &framework.PathOperation{
Callback: b.connectionDeleteHandler(),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "delete",
OperationSuffix: "connection-configuration",
},
},
},

HelpSynopsis: pathConfigConnectionHelpSyn,
Expand Down Expand Up @@ -184,6 +221,11 @@ func pathListPluginConnection(b *databaseBackend) *framework.Path {
return &framework.Path{
Pattern: fmt.Sprintf("config/?$"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixDatabase,
OperationSuffix: "connections",
},

Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ListOperation: b.connectionListHandler(),
},
Expand Down
14 changes: 14 additions & 0 deletions builtin/logical/database/path_creds_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ func pathCredsCreate(b *databaseBackend) []*framework.Path {
return []*framework.Path{
{
Pattern: "creds/" + framework.GenericNameRegex("name"),

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

Fields: map[string]*framework.FieldSchema{
"name": {
Type: framework.TypeString,
Expand All @@ -34,6 +41,13 @@ func pathCredsCreate(b *databaseBackend) []*framework.Path {
},
{
Pattern: "static-creds/" + framework.GenericNameRegex("name"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixDatabase,
OperationVerb: "read",
OperationSuffix: "static-role-credentials",
},

Fields: map[string]*framework.FieldSchema{
"name": {
Type: framework.TypeString,
Expand Down
24 changes: 22 additions & 2 deletions builtin/logical/database/path_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ func pathListRoles(b *databaseBackend) []*framework.Path {
{
Pattern: "roles/?$",

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixDatabase,
OperationVerb: "list",
OperationSuffix: "roles",
},

Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ListOperation: b.pathRoleList,
},
Expand All @@ -34,6 +40,12 @@ func pathListRoles(b *databaseBackend) []*framework.Path {
{
Pattern: "static-roles/?$",

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixDatabase,
OperationVerb: "list",
OperationSuffix: "static-roles",
},

Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ListOperation: b.pathRoleList,
},
Expand All @@ -47,7 +59,11 @@ func pathListRoles(b *databaseBackend) []*framework.Path {
func pathRoles(b *databaseBackend) []*framework.Path {
return []*framework.Path{
{
Pattern: "roles/" + framework.GenericNameRegex("name"),
Pattern: "roles/" + framework.GenericNameRegex("name"),
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixDatabase,
OperationSuffix: "role",
},
Fields: fieldsForType(databaseRolePath),
ExistenceCheck: b.pathRoleExistenceCheck,
Callbacks: map[logical.Operation]framework.OperationFunc{
Expand All @@ -62,7 +78,11 @@ func pathRoles(b *databaseBackend) []*framework.Path {
},

{
Pattern: "static-roles/" + framework.GenericNameRegex("name"),
Pattern: "static-roles/" + framework.GenericNameRegex("name"),
DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixDatabase,
OperationSuffix: "static-role",
},
Fields: fieldsForType(databaseStaticRolePath),
ExistenceCheck: b.pathStaticRoleExistenceCheck,
Callbacks: map[logical.Operation]framework.OperationFunc{
Expand Down
14 changes: 14 additions & 0 deletions builtin/logical/database/path_rotate_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ func pathRotateRootCredentials(b *databaseBackend) []*framework.Path {
return []*framework.Path{
{
Pattern: "rotate-root/" + framework.GenericNameRegex("name"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixDatabase,
OperationVerb: "rotate",
OperationSuffix: "root-credentials",
},

Fields: map[string]*framework.FieldSchema{
"name": {
Type: framework.TypeString,
Expand All @@ -39,6 +46,13 @@ func pathRotateRootCredentials(b *databaseBackend) []*framework.Path {
},
{
Pattern: "rotate-role/" + framework.GenericNameRegex("name"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixDatabase,
OperationVerb: "rotate",
OperationSuffix: "static-role-credentials",
},

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

0 comments on commit 4ff6b62

Please sign in to comment.