Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add display attributes for OpenAPI OperationID's #104

Merged
merged 3 commits into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ const (
// defaultMaxVersions is the number of versions to keep around unless set by
// the config or key configuration.
defaultMaxVersions uint32 = 10

// operationPrefixKVv1 is used as prefixes for OpenAPI operation id's.
operationPrefixKVv1 = "kv-v1"

// operationPrefixKVv2 is used as prefixes for OpenAPI operation id's.
operationPrefixKVv2 = "kv-v2"
)

// versionedKVBackend implements logical.Backend
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.7
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2
github.com/hashicorp/vault/api v1.9.0
github.com/hashicorp/vault/sdk v0.8.1
github.com/hashicorp/vault/sdk v0.9.0
github.com/mitchellh/mapstructure v1.5.0
google.golang.org/protobuf v1.30.0
)
Expand All @@ -27,7 +27,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.0 // indirect
github.com/hashicorp/go-kms-wrapping/v2 v2.0.7 // indirect
github.com/hashicorp/go-kms-wrapping/v2 v2.0.8 // indirect
github.com/hashicorp/go-plugin v1.4.5 // indirect
github.com/hashicorp/go-retryablehttp v0.6.6 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
Expand All @@ -49,7 +49,7 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJ
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.0 h1:pSjQfW3vPtrOTcasTUKgCTQT7OGPPTTMVRrOfU6FJD8=
github.com/hashicorp/go-kms-wrapping/entropy/v2 v2.0.0/go.mod h1:xvb32K2keAc+R8DSFG2IwDcydK9DBQE+fGA5fsw6hSk=
github.com/hashicorp/go-kms-wrapping/v2 v2.0.7 h1:P+dh3M6k5aNl2wXrA9s6zquMHWPaYIkotCffiMIYt6U=
github.com/hashicorp/go-kms-wrapping/v2 v2.0.7/go.mod h1:sDQAfwJGv25uGPZA04x87ERglCG6avnRcBT9wYoMII8=
github.com/hashicorp/go-kms-wrapping/v2 v2.0.8 h1:9Q2lu1YbbmiAgvYZ7Pr31RdlVonUpX+mmDL7Z7qTA2U=
github.com/hashicorp/go-kms-wrapping/v2 v2.0.8/go.mod h1:qTCjxGig/kjuj3hk1z8pOUrzbse/GxB1tGfbrq8tGJg=
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
Expand Down Expand Up @@ -129,8 +129,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/hashicorp/vault/api v1.9.0 h1:ab7dI6W8DuCY7yCU8blo0UCYl2oHre/dloCmzMWg9w8=
github.com/hashicorp/vault/api v1.9.0/go.mod h1:lloELQP4EyhjnCQhF8agKvWIVTmxbpEJj70b98959sM=
github.com/hashicorp/vault/sdk v0.8.1 h1:bdlhIpxBmJuOZ5Anumao1xeiLocR2eQrBRuJynZfTac=
github.com/hashicorp/vault/sdk v0.8.1/go.mod h1:kEpyfUU2ECGWf6XohKVFzvJ97ybSnXvxsTsBkbeVcQg=
github.com/hashicorp/vault/sdk v0.9.0 h1:Cbu9ezaZafZTXnen98QKVmufEPquhZ+r1ORZ7csNLFU=
github.com/hashicorp/vault/sdk v0.9.0/go.mod h1:VX9d+xF62YBNtiEc4l3Z2aea9HVtAS49EoniuXzHtC4=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down Expand Up @@ -222,8 +222,8 @@ go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
golang.org/x/crypto v0.6.0 h1:qfktjS5LUO+fFKeJXZ+ikTRijMmljikvG68fpMMruSc=
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
Expand Down
19 changes: 19 additions & 0 deletions passthrough.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func LeaseSwitchedPassthroughBackend(ctx context.Context, conf *logical.BackendC
{
Pattern: framework.MatchAllRegex("path"),

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

Fields: map[string]*framework.FieldSchema{
"path": {
Type: framework.TypeString,
Expand All @@ -68,6 +72,9 @@ func LeaseSwitchedPassthroughBackend(ctx context.Context, conf *logical.BackendC
Operations: map[logical.Operation]framework.OperationHandler{
logical.ReadOperation: &framework.PathOperation{
Callback: b.handleRead(),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "read",
},
Responses: map[int][]framework.Response{
http.StatusOK: {{
Description: http.StatusText(http.StatusOK),
Expand All @@ -77,6 +84,9 @@ func LeaseSwitchedPassthroughBackend(ctx context.Context, conf *logical.BackendC
},
logical.CreateOperation: &framework.PathOperation{
Callback: b.handleWrite(),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "write",
},
Responses: map[int][]framework.Response{
http.StatusNoContent: {{
Description: http.StatusText(http.StatusNoContent),
Expand All @@ -85,6 +95,9 @@ func LeaseSwitchedPassthroughBackend(ctx context.Context, conf *logical.BackendC
},
logical.UpdateOperation: &framework.PathOperation{
Callback: b.handleWrite(),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "write",
},
Responses: map[int][]framework.Response{
http.StatusNoContent: {{
Description: http.StatusText(http.StatusNoContent),
Expand All @@ -93,6 +106,9 @@ func LeaseSwitchedPassthroughBackend(ctx context.Context, conf *logical.BackendC
},
logical.DeleteOperation: &framework.PathOperation{
Callback: b.handleDelete(),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "delete",
},
Responses: map[int][]framework.Response{
http.StatusNoContent: {{
Description: http.StatusText(http.StatusNoContent),
Expand All @@ -101,6 +117,9 @@ func LeaseSwitchedPassthroughBackend(ctx context.Context, conf *logical.BackendC
},
logical.ListOperation: &framework.PathOperation{
Callback: b.handleList(),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "list",
},
Responses: map[int][]framework.Response{
http.StatusOK: {{
Description: http.StatusText(http.StatusOK),
Expand Down
17 changes: 15 additions & 2 deletions path_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ import (
func pathConfig(b *versionedKVBackend) *framework.Path {
return &framework.Path{
Pattern: "config$",

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

Fields: map[string]*framework.FieldSchema{
"max_versions": {
Type: framework.TypeInt,
Expand All @@ -37,10 +42,14 @@ disables the use of delete_version_after on all keys. A zero duration
clears the current setting. Accepts a Go duration format string.`,
},
},

Operations: map[logical.Operation]framework.OperationHandler{
logical.UpdateOperation: &framework.PathOperation{
Callback: b.upgradeCheck(b.pathConfigWrite()),
Summary: "Configure backend level settings that are applied to every key in the key-value store.",
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "configure",
},
Summary: "Configure backend level settings that are applied to every key in the key-value store.",
Responses: map[int][]framework.Response{
http.StatusNoContent: {{
Description: http.StatusText(http.StatusNoContent),
Expand All @@ -49,7 +58,11 @@ clears the current setting. Accepts a Go duration format string.`,
},
logical.ReadOperation: &framework.PathOperation{
Callback: b.upgradeCheck(b.pathConfigRead()),
Summary: "Read the backend level settings.",
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "read",
OperationSuffix: "configuration",
},
Summary: "Read the backend level settings.",
Responses: map[int][]framework.Response{
http.StatusOK: {{
Description: http.StatusText(http.StatusOK),
Expand Down
26 changes: 23 additions & 3 deletions path_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ func pathData(b *versionedKVBackend) *framework.Path {

return &framework.Path{
Pattern: "data/" + matchAllNoTrailingSlashRegex("path"),

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

Fields: map[string]*framework.FieldSchema{
"path": {
Type: framework.TypeString,
Expand All @@ -83,15 +88,24 @@ version matches the version specified in the cas parameter.`,
},
Operations: map[logical.Operation]framework.OperationHandler{
logical.UpdateOperation: &framework.PathOperation{
Callback: b.upgradeCheck(b.pathDataWrite()),
Callback: b.upgradeCheck(b.pathDataWrite()),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "write",
},
Responses: updateCreatePatchResponseSchema,
},
logical.CreateOperation: &framework.PathOperation{
Callback: b.upgradeCheck(b.pathDataWrite()),
Callback: b.upgradeCheck(b.pathDataWrite()),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "write",
},
Responses: updateCreatePatchResponseSchema,
},
logical.ReadOperation: &framework.PathOperation{
Callback: b.upgradeCheck(b.pathDataRead()),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "read",
},
Responses: map[int][]framework.Response{
http.StatusOK: {{
Description: http.StatusText(http.StatusOK),
Expand All @@ -110,14 +124,20 @@ version matches the version specified in the cas parameter.`,
},
logical.DeleteOperation: &framework.PathOperation{
Callback: b.upgradeCheck(b.pathDataDelete()),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "delete",
},
Responses: map[int][]framework.Response{
http.StatusNoContent: {{
Description: http.StatusText(http.StatusNoContent),
}},
},
},
logical.PatchOperation: &framework.PathOperation{
Callback: b.upgradeCheck(b.pathDataPatch()),
Callback: b.upgradeCheck(b.pathDataPatch()),
DisplayAttrs: &framework.DisplayAttributes{
OperationVerb: "patch",
},
Responses: updateCreatePatchResponseSchema,
},
},
Expand Down
16 changes: 16 additions & 0 deletions path_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ func pathsDelete(b *versionedKVBackend) []*framework.Path {
return []*framework.Path{
{
Pattern: "delete/" + framework.MatchAllRegex("path"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixKVv2,
OperationVerb: "delete",
OperationSuffix: "versions",
},

Fields: map[string]*framework.FieldSchema{
"path": {
Type: framework.TypeString,
Expand All @@ -30,6 +37,7 @@ func pathsDelete(b *versionedKVBackend) []*framework.Path {
Description: "The versions to be archived. The versioned data will not be deleted, but it will no longer be returned in normal get requests.",
},
},

Operations: map[logical.Operation]framework.OperationHandler{
logical.UpdateOperation: &framework.PathOperation{
Callback: b.upgradeCheck(b.pathDeleteWrite()),
Expand All @@ -46,6 +54,13 @@ func pathsDelete(b *versionedKVBackend) []*framework.Path {
},
{
Pattern: "undelete/" + framework.MatchAllRegex("path"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixKVv2,
OperationVerb: "undelete",
OperationSuffix: "versions",
},

Fields: map[string]*framework.FieldSchema{
"path": {
Type: framework.TypeString,
Expand All @@ -56,6 +71,7 @@ func pathsDelete(b *versionedKVBackend) []*framework.Path {
Description: "The versions to unarchive. The versions will be restored and their data will be returned on normal get requests.",
},
},

Operations: map[logical.Operation]framework.OperationHandler{
logical.UpdateOperation: &framework.PathOperation{
Callback: b.upgradeCheck(b.pathUndeleteWrite()),
Expand Down
7 changes: 7 additions & 0 deletions path_destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ import (
func pathDestroy(b *versionedKVBackend) *framework.Path {
return &framework.Path{
Pattern: "destroy/" + framework.MatchAllRegex("path"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixKVv2,
OperationVerb: "destroy",
OperationSuffix: "versions",
},

Fields: map[string]*framework.FieldSchema{
"path": {
Type: framework.TypeString,
Expand Down
7 changes: 7 additions & 0 deletions path_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ import (
func pathMetadata(b *versionedKVBackend) *framework.Path {
return &framework.Path{
Pattern: "metadata/" + framework.MatchAllRegex("path"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixKVv2,
OperationSuffix: "metadata",
},

Fields: map[string]*framework.FieldSchema{
"path": {
Type: framework.TypeString,
Expand Down Expand Up @@ -59,6 +65,7 @@ version-agnostic information about a secret.
`,
},
},

Operations: map[logical.Operation]framework.OperationHandler{
logical.UpdateOperation: &framework.PathOperation{
Callback: b.upgradeCheck(b.pathMetadataWrite()),
Expand Down
7 changes: 7 additions & 0 deletions path_subkeys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ import (
func pathSubkeys(b *versionedKVBackend) *framework.Path {
return &framework.Path{
Pattern: "subkeys/" + framework.MatchAllRegex("path"),

DisplayAttrs: &framework.DisplayAttributes{
OperationPrefix: operationPrefixKVv2,
OperationVerb: "read",
OperationSuffix: "subkeys",
},

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