From 85500b5c3a7804c8db0aea0f6dcbe31ba3b8204b Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Thu, 26 Oct 2017 14:54:30 -0400 Subject: [PATCH] Change prefix to a string that can be specified, rather than a bool --- physical/couchdb/couchdb.go | 35 ++++++++----------- .../configuration/storage/couchdb.html.md | 7 ++-- 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/physical/couchdb/couchdb.go b/physical/couchdb/couchdb.go index a24668cfb..6fb7ab564 100644 --- a/physical/couchdb/couchdb.go +++ b/physical/couchdb/couchdb.go @@ -22,7 +22,7 @@ import ( // CouchDBBackend allows the management of couchdb users type CouchDBBackend struct { logger log.Logger - prefixed bool + prefix string client *couchDBClient permitPool *physical.PermitPool } @@ -159,17 +159,10 @@ func buildCouchDBBackend(conf map[string]string, logger log.Logger) (*CouchDBBac username = conf["username"] } - prefixed := true - prefixedStr := os.Getenv("COUCHDB_PREFIXED") - if prefixedStr == "" { - prefixedStr = conf["prefixed"] - } - if prefixedStr != "" { - var err error - prefixed, err = strconv.ParseBool(prefixedStr) - if err != nil { - return nil, err - } + prefix := "$" + prefixedStr, ok := conf["prefixed"] + if ok { + prefix = prefixedStr } password := os.Getenv("COUCHDB_PASSWORD") @@ -197,7 +190,7 @@ func buildCouchDBBackend(conf map[string]string, logger log.Logger) (*CouchDBBac password: password, Client: cleanhttp.DefaultPooledClient(), }, - prefixed: prefixed, + prefix: prefix, logger: logger, permitPool: physical.NewPermitPool(maxParInt), }, nil @@ -242,8 +235,8 @@ func (m *CouchDBBackend) Delete(key string) error { func (m *CouchDBBackend) List(prefix string) ([]string, error) { defer metrics.MeasureSince([]string{"couchdb", "list"}, time.Now()) - if m.prefixed { - prefix = "$" + prefix + if m.prefix != "" { + prefix = m.prefix + prefix } m.permitPool.Acquire() @@ -294,8 +287,8 @@ func NewTransactionalCouchDBBackend(conf map[string]string, logger log.Logger) ( func (m *CouchDBBackend) GetInternal(key string) (*physical.Entry, error) { defer metrics.MeasureSince([]string{"couchdb", "get"}, time.Now()) - if m.prefixed { - key = "$" + key + if m.prefix != "" { + key = m.prefix + key } return m.client.get(key) @@ -306,8 +299,8 @@ func (m *CouchDBBackend) PutInternal(entry *physical.Entry) error { defer metrics.MeasureSince([]string{"couchdb", "put"}, time.Now()) key := entry.Key - if m.prefixed { - key = "$" + entry.Key + if m.prefix != "" { + key = m.prefix + entry.Key } revision, _ := m.client.rev(url.PathEscape(key)) @@ -323,8 +316,8 @@ func (m *CouchDBBackend) PutInternal(entry *physical.Entry) error { func (m *CouchDBBackend) DeleteInternal(key string) error { defer metrics.MeasureSince([]string{"couchdb", "delete"}, time.Now()) - if m.prefixed { - key = "$" + key + if m.prefix != "" { + key = m.prefix + key } revision, _ := m.client.rev(url.PathEscape(key)) diff --git a/website/source/docs/configuration/storage/couchdb.html.md b/website/source/docs/configuration/storage/couchdb.html.md index b9bb556c1..50cc90cc5 100644 --- a/website/source/docs/configuration/storage/couchdb.html.md +++ b/website/source/docs/configuration/storage/couchdb.html.md @@ -30,11 +30,10 @@ storage "couchdb" { ## `couchdb` Parameters -- `prefixed` `(string: "true")` – Specifies whether each value written to - CouchDB should be prefixed with `$`. If turned off, Vault may run into error +- `prefix` `(string: "$")` – Specifies a prefix to use for each value written + to CouchDB. If turned off (by setting to `""`, Vault may run into error conditions if values are written that begin with an underscore, since it is a - reserved prefix in CouchDB. This can also be provided via the environment - variable `COUCHDB_PREFIXED`. + reserved prefix in CouchDB. - `endpoint` `(string: "")` – Specifies your CouchDB endpoint. This can also be provided via the environment variable `COUCHDB_ENDPOINT`.