Reading only the secret value using HTTP APIs

916 views
Skip to first unread message

Hemant Gupta

unread,
Jan 20, 2016, 3:49:50 PM1/20/16
to Vault
I am using the below weblink as a reference to access the secret from Vault.

I am able to successfully read the secret using the below curl command:
$ curl \
    -H "X-Vault-Token:$VAULT_TOKEN" \

However, as an output I just need the secret value and not the whole json. 
In other words, I just need baz as a string from the below output:

{
  "lease_id": "secret/foo/cc529d06-36c8-be27-31f5-2390e1f6e2ae",
  "renewable": false,
  "lease_duration": 2592000,
  "data": {
    "bar": "baz"
  },
  "auth": null
}

Jeff Mitchell

unread,
Jan 20, 2016, 3:53:13 PM1/20/16
to vault...@googlegroups.com
Hi Hemant,

I recommend piping the output to 'jq', which can do all sorts of
transformation and filtering -- I think something like "jq 'data.bar'"
should work.

Alternately, if the Vault CLI is available, you can use the -field
option to 'vault read'.

--Jeff
> --
> This mailing list is governed under the HashiCorp Community Guidelines -
> https://www.hashicorp.com/community-guidelines.html. Behavior in violation
> of those guidelines may result in your removal from this mailing list.
>
> GitHub Issues: https://github.com/hashicorp/vault/issues
> IRC: #vault-tool on Freenode
> ---
> You received this message because you are subscribed to the Google Groups
> "Vault" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to vault-tool+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/vault-tool/b694d11f-8057-45fe-92b5-6bc29b467715%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Hemant Gupta

unread,
Jan 21, 2016, 12:51:06 AM1/21/16
to Vault
Thanks Jeff for your response.

I am able to get the value by piping as below:
python -c 'import sys, json; print json.load(sys.stdin)["data"]["value"]'
Reply all
Reply to author
Forward
0 new messages