Skip to content

Commit

Permalink
Add patch support (#49)
Browse files Browse the repository at this point in the history
* add initial PatchOperation support with cas validation

* update go.mod, go.sum

* Add PatchOperation case to invalid patch fallthrough

* initial PatchOperation handler for data endpoint

* move old version cleanup logic into its own function

* respond with 404 for PATCH to deleted or destroyed version

* go fmt

* add test for put with cas=0

* additional patch tests for no data provided and entry/metadata not found

* add better error messaging for data path tests

* add comments

* make patch resp when deleted/destroyed consistent with success resp

* fixes for PR feedback

* check for data in patch handler prior to locking

* pass storage view and key to cleanupOldVersions directly

* remove replace directive for vault/sdk

* get vault/sdk @kv-patch branch

* add cas_required check to TestVersionedKV_Patch_CASValidation

* cleanupOldVersions now returns string instead of error

* remove direct dependency on json-patch

* require the json-patch library

* fix TestVersionedKV_Patch_NoData

* upgrade to go 1.16

Co-authored-by: Josh Black <raskchanky@users.noreply.github.com>
  • Loading branch information
ccapurso and raskchanky committed Oct 13, 2021
1 parent e060c23 commit eec8a1c
Show file tree
Hide file tree
Showing 6 changed files with 1,076 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2.1

references:
images:
go: &GOLANG_IMAGE docker.mirror.hashicorp.services/circleci/golang:1.12
go: &GOLANG_IMAGE docker.mirror.hashicorp.services/circleci/golang:1.16.7-buster

jobs:
go-test:
Expand Down
3 changes: 3 additions & 0 deletions backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,8 @@ func pathInvalid(b *versionedKVBackend) []*framework.Path {
switch req.Operation {
case logical.CreateOperation, logical.UpdateOperation:
subCommand = "put"
case logical.PatchOperation:
subCommand = "patch"
case logical.ReadOperation:
subCommand = "get"
case logical.ListOperation:
Expand All @@ -188,6 +190,7 @@ func pathInvalid(b *versionedKVBackend) []*framework.Path {
Operations: map[logical.Operation]framework.OperationHandler{
logical.UpdateOperation: &framework.PathOperation{Callback: handler, Unpublished: true},
logical.CreateOperation: &framework.PathOperation{Callback: handler, Unpublished: true},
logical.PatchOperation: &framework.PathOperation{Callback: handler, Unpublished: true},
logical.ReadOperation: &framework.PathOperation{Callback: handler, Unpublished: true},
logical.DeleteOperation: &framework.PathOperation{Callback: handler, Unpublished: true},
logical.ListOperation: &framework.PathOperation{Callback: handler, Unpublished: true},
Expand Down
11 changes: 5 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
module github.com/hashicorp/vault-plugin-secrets-kv

go 1.12
go 1.16

require (
github.com/evanphx/json-patch v0.5.2 // indirect
github.com/go-test/deep v1.0.7 // indirect
github.com/golang/protobuf v1.5.0
github.com/hashicorp/go-hclog v0.12.0
github.com/hashicorp/go-multierror v1.0.0 // indirect
github.com/hashicorp/go-hclog v0.16.2
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.1
github.com/hashicorp/go-secure-stdlib/strutil v0.1.1 // indirect
github.com/hashicorp/vault/api v1.0.5-0.20200215224050-f6547fa8e820
github.com/hashicorp/vault/sdk v0.1.14-0.20200215224050-f6547fa8e820
github.com/hashicorp/vault/sdk v0.2.2-0.20211004171540-a8c7e135dd6a
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
github.com/mitchellh/mapstructure v1.4.1
golang.org/x/text v0.3.1-0.20181227161524-e6919f6577db // indirect
google.golang.org/genproto v0.0.0-20190404172233-64821d5d2107 // indirect
google.golang.org/protobuf v1.27.1 // indirect
)

0 comments on commit eec8a1c

Please sign in to comment.