From 2e367c54183ca6029c4c4ddbe3db221cdb13015f Mon Sep 17 00:00:00 2001 From: Connor Poole Date: Fri, 8 Nov 2019 01:54:05 +0000 Subject: [PATCH] adding a write bytes method (#7611) --- api/logical.go | 13 ++++++++++++- go.mod | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/api/logical.go b/api/logical.go index d5f946446b..f4eb02a8df 100644 --- a/api/logical.go +++ b/api/logical.go @@ -134,9 +134,20 @@ func (c *Logical) Write(path string, data map[string]interface{}) (*Secret, erro return nil, err } + return c.write(path, r) +} + +func (c *Logical) WriteBytes(path string, data []byte) (*Secret, error) { + r := c.c.NewRequest("PUT", "/v1/"+path) + r.BodyBytes = data + + return c.write(path, r) +} + +func (c *Logical) write(path string, request *Request) (*Secret, error) { ctx, cancelFunc := context.WithCancel(context.Background()) defer cancelFunc() - resp, err := c.c.RawRequestWithContext(ctx, r) + resp, err := c.c.RawRequestWithContext(ctx, request) if resp != nil { defer resp.Body.Close() } diff --git a/go.mod b/go.mod index ea6a44699d..1bf613cd7d 100644 --- a/go.mod +++ b/go.mod @@ -51,6 +51,7 @@ require ( github.com/google/go-metrics-stackdriver v0.0.0-20190816035513-b52628e82e2a github.com/hashicorp/consul-template v0.22.0 github.com/hashicorp/consul/api v1.1.0 + github.com/hashicorp/consul/api v1.0.1 github.com/hashicorp/errwrap v1.0.0 github.com/hashicorp/go-cleanhttp v0.5.1 github.com/hashicorp/go-gcp-common v0.5.0