////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at
  http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////
[[VaultVariableResolver]]
:imagesdir: ../assets/images
:openvar: #{
:closevar: }
:description: This describes the usage of a variable resolver to retrieve secrets from a Hashicorp Vault

== Functionality

This variable resolver can retrieve secrets from a https://www.vaultproject.io/[Hashicorp Vault].
Here are the options to use:

* Vault address: The base address and port of the Vault server (for example: https://vault-server:8200)
* Vault token: The token to use to authenticate
* Validate HTTPS connections?: It's recommended to enable connection validation in production. This secures the connection with the X.509 certificate specified in one of either next option.
* PEM file path: The name of the file (VFS) containing the X.509 certificate string
* PEM string: The X.509 string itself in case you're not using a file
* Open connection timeout: The connection timeout when getting a http(s) connection in milliseconds.
* Read connection timeout: The timeout in milliseconds when reading.

The variable expression you can resolve with this plugin type is (as always) in the following format:

`{openvar}name:path-key:value-key{closevar}`

* name: the name of the variable resolver metadata element to use
* path-key: the path to the secret in the Vault.
* value-key: the key of the value to retrieve.

In case we don't specify a `value-key`, you will give back the complete JSON string of the secret.

== Example

Suppose we have a secret defined in the Vault, in a KV secrets engine:

image:metadata-types/variable-resolver/vault-variable-resolver-server.png

We can define a connection called `vault` and retrieve values with expressions:

* `{openvar}vault:hop/data/some-db:hostname{closevar}` : localhost
* `{openvar}vault:hop/data/some-db:username{closevar}` : john
* `{openvar}vault:hop/data/some-db{closevar}` : `{"db":"test","hostname":"localhost","password":"some-password","port":"3306","username":"john"}`

