How to add Policy value while creating Policy in HashiCorp Vault using curl?

Viewed 26
curl -k --request POST --url  https://vault:8200/v1/sys/policy/policy-test --header 'Authorization: Bearer <Token>' --header 'Content-Type: application/json' --data '"policy":"{""path\\"" //*\" { \n capabilities = [\"create\",\"read\",\"list\",\"update\"]}}}"'

While trying this command, I am getting this error:

{"errors":["error parsing JSON"]}

Could anyone help with syntax for Vault policy here?

1 Answers

It's easy to visualize (and fix the errors) if you use the "@-" --data option and a here-document, like shown following:

curl -k --request POST --url https://vault:8200/v1/sys/policy/policy-test --header 'Authorization: Bearer ' --header 'Content-Type: application/json' --data @- <<EOF
{
    "policy":
    {
        "path \"/*\"
        {
            capabilities = [\"create\", \"read\", \"list\", \"update\"]
        }"
    }
}
EOF
Related