-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adding generic get-kv scripts Adding a couple generic "get kv" from tool scripts that can be used by other builds/tools * Upgrading Vault version for PLAT-3047 This uses the current version of the vault client * Adding put-consul-kv script and tests
- Loading branch information
1 parent
034c1d3
commit 25e2251
Showing
7 changed files
with
137 additions
and
2 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,45 @@ | ||
#!/usr/bin/env bash | ||
set -e | ||
set -o pipefail | ||
|
||
# Get value from Vault. Takes in two parameters <path> and <field> | ||
function get_vault_kv { | ||
vault_path=$1 | ||
vault_key=${2:-value} | ||
if [[ "$VAULT_ADDR" ]]; then | ||
#VAULT_KV=$(curl -s -H "X-Vault-Token: $(cat ~/.vault-token )" -X GET $VAULT_ADDR/v1/${vault_path} | jq -r .data.${vault_key}) | ||
VAULT_KV=$(vault kv get -field ${vault_key} ${vault_path}) | ||
fi | ||
} | ||
|
||
# PUT value from Consul prefix tasks a <path> parameters | ||
function put_consul_kv { | ||
if [[ "$CONSUL_HTTP_ADDR" ]]; then | ||
consul_path=$1 | ||
consul_value=$2 | ||
consul kv put ${consul_path} ${consul_value} | ||
fi | ||
} | ||
|
||
# Get value from Consul prefix tasks a <path> parameters | ||
function get_consul_kv { | ||
if [[ "$CONSUL_HTTP_ADDR" ]]; then | ||
consul_path=$1 | ||
consul kv get $consul_path | ||
fi | ||
} | ||
|
||
# Auth to Consul and set the correct env vars for use by other scripts and fucntions | ||
function auth_to_consul { | ||
if [[ "$VAULT_ADDR" ]]; then | ||
get_vault_kv "secret/consul" "http_auth" | ||
CONSUL_HTTP_AUTH=$VAULT_KV | ||
get_vault_kv "secret/consul" "http_addr" | ||
CONSUL_HTTP_ADDR=$VAULT_KV | ||
export CONSUL_HTTP_AUTH | ||
export CONSUL_HTTP_ADDR | ||
else | ||
echo "MISSING VAULT_ADDR" | ||
exit 1 | ||
fi | ||
} |
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,20 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck shell=bash | ||
# Script for outputing consul kv values | ||
set -e | ||
set -o pipefail | ||
source /opt/hermes/bin/functions | ||
|
||
if [ -e "$(which consul)" ]; then | ||
if [[ "$VAULT_ADDR" ]]; then | ||
auth_to_consul | ||
get_consul_kv $1 | ||
echo -n $CONSUL_KV | ||
else | ||
echo "MISSING VAULT_ADDR" | ||
exit 1 | ||
fi | ||
else | ||
echo "can not find consul" | ||
exit 1 | ||
fi |
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,19 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck shell=bash | ||
# Script for outputing values from the Vault KV | ||
set -e | ||
set -o pipefail | ||
source /opt/hermes/bin/functions | ||
|
||
if [ -e "$(which vault)" ]; then | ||
if [[ "$VAULT_ADDR" ]]; then | ||
get_vault_kv $1 $2 | ||
echo -n $VAULT_KV | ||
else | ||
echo "MISSING VAULT_ADDR" | ||
exit 1 | ||
fi | ||
else | ||
echo "can not find vault" | ||
exit 1 | ||
fi |
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 @@ | ||
#!/usr/bin/env bash | ||
# shellcheck shell=bash | ||
# Script for outputing consul kv values | ||
set -e | ||
set -o pipefail | ||
source /opt/hermes/bin/functions | ||
|
||
if [ -e "$(which consul)" ]; then | ||
if [[ "$VAULT_ADDR" ]]; then | ||
auth_to_consul | ||
consul_path=$1 | ||
consul_value=$2 | ||
put_consul_kv ${consul_path} ${consul_value} | ||
else | ||
echo "MISSING VAULT_ADDR" | ||
exit 1 | ||
fi | ||
else | ||
echo "can not find consul" | ||
exit 1 | ||
fi |
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