-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
235 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package client | ||
|
||
import ( | ||
"github.com/hashicorp/vault/api" | ||
"sync" | ||
) | ||
|
||
// Cache is a thread-safe cache for vault queries | ||
type Cache struct { | ||
vaultClient *api.Client | ||
listQueries map[string]*cacheElement | ||
mutex sync.Mutex | ||
} | ||
|
||
type cacheElement struct { | ||
Secret *api.Secret | ||
Err error | ||
} | ||
|
||
// NewCache create a new thread-safe cache object | ||
func NewCache(vaultClient *api.Client) *Cache { | ||
return &Cache{ | ||
vaultClient: vaultClient, | ||
listQueries: make(map[string]*cacheElement), | ||
} | ||
} | ||
|
||
// Clear removes all entries from the cache | ||
func (cache *Cache) Clear() { | ||
cache.mutex.Lock() | ||
cache.listQueries = make(map[string]*cacheElement) | ||
cache.mutex.Unlock() | ||
} | ||
|
||
// List tries to get path from cache. | ||
// If path is not available in cache, it uses the vault client to query and update cache. | ||
func (cache *Cache) List(path string) (result *api.Secret, err error) { | ||
// try to get path from cache | ||
cache.mutex.Lock() | ||
value, hit := cache.listQueries[path] | ||
cache.mutex.Unlock() | ||
if hit { | ||
return value.Secret, value.Err | ||
} | ||
|
||
// not found in cache -> query vault | ||
// NOTE: this part is not mutexed | ||
result, err = cache.vaultClient.Logical().List(path) | ||
|
||
// update cache | ||
cache.mutex.Lock() | ||
cache.listQueries[path] = &cacheElement{ | ||
Secret: result, | ||
Err: err, | ||
} | ||
cache.mutex.Unlock() | ||
return result, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
load ../../util/common | ||
load ../../util/concurrency-setup | ||
load ../../bin/plugins/bats-support/load | ||
load ../../bin/plugins/bats-assert/load | ||
|
||
@test "vault-${VAULT_VERSION} concurrency 'mv'" { | ||
####################################### | ||
echo "==== case: move large directory tree ====" | ||
run ${APP_BIN} -c "mv /KV2/src/ /KV2/dest/" | ||
assert_success | ||
|
||
echo "ensure at least one file got moved to destination" | ||
run get_vault_value "value" "/KV2/dest/a/a/50" | ||
assert_success | ||
assert_output "1" | ||
|
||
echo "ensure at least one src file got removed" | ||
run get_vault_value "value" "/KV2/src/a/a/50" | ||
assert_success | ||
assert_output --partial "${NO_VALUE_FOUND}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.