Reputation: 103
I'm having what I suspect is a quoting error in a bash script.
SECRET_VALUE_CMD="curl -s -L -H \"X-Vault-Token: $VAULT_TOKEN\" -X GET \"https://$VAULT_ADDR/v1/secret/$secret_path\""
SECRET_VALUE_RESPONSE=$(eval $SECRET_VALUE_CMD)
SECRET_VALUE=$(echo "$SECRET_VALUE_RESPONSE" | jq --raw-output '.data.value')
When I execute this in my script, I get the following to stderr:
parse error: Expected separator between values at line 1, column 63
and $SECRET_VALUE is blank.
An example of $SECRET_VALUE_RESPONSE is:
{"request_id":"XXXX-YYYY..,"lease_id":"","renewable":false,"lease_duration":nnnnnn,"data":{"value":"secret-value"},"wrap_info":null,"warnings":null,"auth":null}
I've tried adding escaped quotes around the parameters to eval and echo, but can't seem to find a working combination. Any help would be greatly appreciated!
Upvotes: 2
Views: 3485
Reputation: 124646
Don't use eval
. You could create a function to execute curl
, for example:
get_secret_value() {
curl -s -L -H "X-Vault-Token: $VAULT_TOKEN" -X GET "https://$VAULT_ADDR/v1/secret/$secret_path"
}
secret_value=$(get_secret_value | jq --raw-output '.data.value')
Upvotes: 3