== Azure key vault isolated integration tests

=== Real Azure API

Prerequisites:

* A https://docs.microsoft.com/en-us/azure/storage/common/storage-account-create?toc=%2Fazure%2Fstorage%2Fblobs%2Ftoc.json&tabs=azure-portal[general-purpose v2 Azure storage account] and
https://docs.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-portal[create a container]
* The https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-change-feed?tabs=azure-portal#enable-and-disable-the-change-feed[change feed] is enabled on your storage account
* View the https://docs.microsoft.com/en-us/azure/storage/common/storage-account-keys-manage?tabs=azure-portal#view-account-access-keys[account keys] and set the following environment variables
* An https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-create[Azure Event Hub]
* An https://docs.microsoft.com/en-us/azure/event-hubs/event-hubs-get-connection-string[Event Hubs connection string]
* A https://learn.microsoft.com/en-us/azure/key-vault/general/overview[Key Vault] configured in your Azure account

=== Required resources

For running the test following resources have to exist:

* event hubs
* blob container

The configuration is handed to the test via environmental variables. All following variables are required for the test execution.

[source,shell]
----
export AZURE_CLIENT_ID=<your-azure-app-client-id>
export AZURE_CLIENT_SECRET=<your-azure-app-client-secret>
export AZURE_TENANT_ID=<your-azure-app-tenant-id>
export AZURE_VAULT_NAME=<your-azure-key-vault-name>
export AZURE_VAULT_EVENT_HUBS_BLOB_CONTAINER_NAME=<container for storing position of eventhub consumer>
export AZURE_VAULT_EVENT_HUBS_CONNECTION_STRING=<connection string for eventhub>
export AZURE_STORAGE_ACCOUNT_KEY=<storage account key required for context refresh configuration>
----

=== Script for resource configuration

To add resources required for the key-vault tests, you can use `key-vault-resources.sh` script as follows.

* Ensure that you have installed (and logged in) the https://docs.microsoft.com/en-us/cli/azure/[Azure CLI] beforehand.
* You have to have permissions for eventhubs and storage container creation, existing resource group and event hub namespace.

(In case you have an "empty" cloud and need to create all resources, please follow instructions from the parent module.)

Command for script execution:

[source,shell]
----
$ ./key-vault-resources.sh create
----

The script outputs a set of export commands that you may want to paste to your shell.

Here are the environment variables you need to set before the script execution:

[source,shell]
----
export RESOURCE_GROUP=<existing-resource-group>
export ZONE=<your-zone>
export EH_NAMESPACE=<existing event hub namespace>
export AZURE_STORAGE_ACCOUNT_NAME=<existing event hub storage account name>
----

To clean up, run

[source,shell]
----
$ ./key-vault-resources.sh delete
----

==== What is created by the script

* eventhub used for testing context reload
* storage container required for storing position of eventhub consumer

Following properties are generated by the script and are required for the test execution:
[source,shell]
----
    export AZURE_EVENT_HUBS_BLOB_CONTAINER_NAME=<container for storing position of eventhub consumer>
    export AZURE_VAULT_EVENT_HUBS_CONNECTION_STRING=<connection string for eventhub>
    export AZURE_STORAGE_ACCOUNT_KEY=<storage account key required for context refresh configuration>
----

=== Limitations

Do not execute the tests in parallel, without changing the Event Hubs resource!

Even thought each test is using a unique secret name regexp, the refresh trigger task receives all events, which are send to the event hub.
Therefore an event send by the first test might be consumed by the second test, which would fail the first test.