|
| 1 | +#!/bin/bash |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one or more |
| 4 | +# contributor license agreements. See the NOTICE file distributed with |
| 5 | +# this work for additional information regarding copyright ownership. |
| 6 | +# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 7 | +# (the "License"); you may not use this file except in compliance with |
| 8 | +# the License. You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | +# |
| 18 | + |
| 19 | +#script to create/delete all resources required for key-vault refresh test. |
| 20 | +#In comparison with ../azure-resources/sh, the script is not creating any permissions, resource groups, ... |
| 21 | +#Following properties has to be se upon running the script |
| 22 | +#export RESOURCE_GROUP=<existing-resource-group> |
| 23 | +#export ZONE=<your-zone> |
| 24 | +#export EH_NAMESPACE=<existing event hub namespace> |
| 25 | +#export AZURE_STORAGE_ACCOUNT_NAME=<existing event hub storage account name> |
| 26 | + |
| 27 | +if ! which az > /dev/null 2>&1; then |
| 28 | + echo "$(basename $0) requires the Azure CLI." |
| 29 | + echo |
| 30 | + echo "https://docs.microsoft.com/en-us/cli/azure/" |
| 31 | + echo |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | + |
| 35 | +suffix="$(az ad signed-in-user show --query displayName -o tsv | tr '[:upper:]' '[:lower:]' | tr -cd '[:alnum:]' | cut -c-12)" |
| 36 | +suffix="${suffix}4" |
| 37 | + |
| 38 | +export AZURE_VAULT_REFRESH_EH_NAME=camel-quarkus-secret-refresh-hub-${suffix} |
| 39 | +export AZURE_BLOB_CONTAINER_NAME=cq-container-${suffix} |
| 40 | + |
| 41 | +function createResources() { |
| 42 | + set -e |
| 43 | + set -x |
| 44 | + AZURE_EVENT_HUBS_CONNECTION_STRING=$(az eventhubs namespace authorization-rule keys list --resource-group ${RESOURCE_GROUP} --namespace-name ${EH_NAMESPACE} --name RootManageSharedAccessKey --query primaryConnectionString -o tsv) |
| 45 | + |
| 46 | + az storage container create --account-name ${AZURE_STORAGE_ACCOUNT_NAME} --name ${AZURE_BLOB_CONTAINER_NAME} --auth-mode login |
| 47 | + |
| 48 | + AZURE_STORAGE_ACCOUNT_KEY=$(az storage account keys list --account-name ${AZURE_STORAGE_ACCOUNT_NAME} --query '[0].value' -o tsv) |
| 49 | + |
| 50 | + az eventhubs eventhub create --name ${AZURE_VAULT_REFRESH_EH_NAME} --resource-group ${RESOURCE_GROUP} --namespace-name ${EH_NAMESPACE} --cleanup-policy Delete --partition-count 1 --retention-time 1 |
| 51 | + |
| 52 | + set +x |
| 53 | + echo "Add the following to your environment:" |
| 54 | + echo 'export AZURE_VAULT_EVENT_HUBS_BLOB_CONTAINER_NAME="'${AZURE_BLOB_CONTAINER_NAME}'"' |
| 55 | + echo 'export AZURE_VAULT_EVENT_HUBS_CONNECTION_STRING="'$AZURE_EVENT_HUBS_CONNECTION_STRING';EntityPath='${AZURE_VAULT_REFRESH_EH_NAME}'"' |
| 56 | + echo 'export AZURE_STORAGE_ACCOUNT_KEY="'${AZURE_STORAGE_ACCOUNT_KEY}'"' |
| 57 | +} |
| 58 | + |
| 59 | + |
| 60 | +function deleteResources() { |
| 61 | + set -x |
| 62 | + set +e |
| 63 | + |
| 64 | + az storage container delete --account-name ${AZURE_STORAGE_ACCOUNT_NAME} --name ${AZURE_BLOB_CONTAINER_NAME} --auth-mode login |
| 65 | + |
| 66 | + az eventhubs eventhub delete --name ${AZURE_VAULT_REFRESH_EH_NAME} --resource-group ${RESOURCE_GROUP} --namespace-name ${EH_NAMESPACE} |
| 67 | +} |
| 68 | + |
| 69 | +case "$1" in |
| 70 | +create) echo "Creating Azure resources" |
| 71 | + createResources |
| 72 | + ;; |
| 73 | +delete) echo "Deleting Azure resources" |
| 74 | + deleteResources |
| 75 | + ;; |
| 76 | +*) echo "usage: $0 [create|delete]" |
| 77 | + ;; |
| 78 | +esac |
0 commit comments