-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvault-http-api.sh
42 lines (32 loc) · 1.14 KB
/
vault-http-api.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
function startVaultServerForApi()
{
printf "***** Starting a Vault Server in standard mode using file storage backend\n"
local configFolder=$1
local containerName='vaultapi'
docker run -v $configFolder:/config -p 8241:8200 --name $containerName -h $containerName -d sjourdan/vault server -config=/config/file.hcl
sleep 2
_printLogs $containerName
}
function checkInitStatus()
{
printf "***** [HTTP API] Checking Vault server init status\n"
# 8241
local port=$1
curl --silent "http://127.0.0.1:$port/v1/sys/init" | jq
}
function initVaultFromApi()
{
printf "***** [HTTP API] Initializing Vault server\n"
local port=$1
local initOutput=$(curl --silent -X PUT --data '{"secret_shares": 5, "secret_threshold": 3}' "http://localhost:$port/v1/sys/init")
echo -e "$initOutput" | jq
_setVaultRootTokenAndUnsealKeySet $VAULT_SERVER_CONTAINER_NAME "$initOutput" 'jsonText'
}
function unsealVaultFromApi()
{
printf "***** [HTTP API] Unsealing Vault server\n"
local key=$1
local port=$2
curl --silent -X PUT --data "{\"key\": \"$key\"}" "http://127.0.0.1:$port/v1/sys/unseal"
}