Skip to content

Commit

Permalink
Merge pull request #236 from majguo/main
Browse files Browse the repository at this point in the history
Make possible to disable extension by configuration property
  • Loading branch information
majguo authored May 19, 2024
2 parents 898f41a + be92ee3 commit 053f712
Show file tree
Hide file tree
Showing 33 changed files with 560 additions and 122 deletions.
44 changes: 17 additions & 27 deletions .github/build-with-maven-native.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,45 @@ az group create \
--name "${RESOURCE_GROUP_NAME}" \
--location centralus

# Create a storage account
# Azure Storage Blob Extension
# The same commands used in
# - integration-tests/README.md
# - integration-tests/azure-storage-blob/README.md

az storage account create \
--name "${STORAGE_ACCOUNT_NAME}" \
--resource-group "${RESOURCE_GROUP_NAME}" \
--location centralus \
--sku Standard_LRS \
--kind StorageV2

# Retrieve the connection string for the storage account and export as an environment variable
export QUARKUS_AZURE_STORAGE_BLOB_CONNECTION_STRING=$(az storage account show-connection-string \
--resource-group "${RESOURCE_GROUP_NAME}" \
--name "${STORAGE_ACCOUNT_NAME}" \
--query connectionString -o tsv)

# Create an app configuration store
# Azure App Configuration Extension
# The same commands used in
# - integration-tests/README.md
# - integration-tests/azure-app-configuration/README.md

az appconfig create \
--name "${APP_CONFIG_NAME}" \
--resource-group "${RESOURCE_GROUP_NAME}" \
--location centralus

# Retrieve the connection string for the app configuration store
APP_CONFIG_CONNECTION_STRING=$(az appconfig credential list \
--name "${APP_CONFIG_NAME}" \
--resource-group "${RESOURCE_GROUP_NAME}" \
| jq -r 'map(select(.readOnly == false)) | .[0].connectionString')
while [ -z ${APP_CONFIG_CONNECTION_STRING} ]
do
echo "Failed to retrieve connection string of app config ${APP_CONFIG_NAME}, retry it in 5 seconds..."
sleep 5
APP_CONFIG_CONNECTION_STRING=$(az appconfig credential list \
--name "${APP_CONFIG_NAME}" \
--resource-group "${RESOURCE_GROUP_NAME}" \
| jq -r 'map(select(.readOnly == false)) | .[0].connectionString')
done

# Add a few key-value pairs to the app configuration store
az appconfig kv set \
--connection-string "${APP_CONFIG_CONNECTION_STRING}" \
--name "${APP_CONFIG_NAME}" \
--key my.prop \
--value 1234 \
--yes
az appconfig kv set \
--connection-string "${APP_CONFIG_CONNECTION_STRING}" \
--name "${APP_CONFIG_NAME}" \
--key another.prop \
--value 5678 \
--label prod \
--yes

# Retrieve the connection info for the app configuration store and export as environment variables
export QUARKUS_AZURE_APP_CONFIGURATION_ENDPOINT=$(az appconfig show \
--resource-group "${RESOURCE_GROUP_NAME}" \
--name "${APP_CONFIG_NAME}" \
Expand All @@ -78,18 +68,18 @@ export QUARKUS_AZURE_APP_CONFIGURATION_SECRET=$(echo "${credential}" | jq -r '.v
# - integration-tests/azure-keyvault/README.md

az keyvault create \
--name ${KEY_VAULT_NAME} \
--resource-group ${RESOURCE_GROUP_NAME} \
--name "${KEY_VAULT_NAME}" \
--resource-group "${RESOURCE_GROUP_NAME}" \
--location eastus

az ad signed-in-user show --query id -o tsv \
| az keyvault set-policy \
--name ${KEY_VAULT_NAME} \
--name "${KEY_VAULT_NAME}" \
--object-id @- \
--secret-permissions all

export QUARKUS_AZURE_KEYVAULT_SECRET_ENDPOINT=$(az keyvault show --name ${KEY_VAULT_NAME} \
--resource-group ${RESOURCE_GROUP_NAME}\
export QUARKUS_AZURE_KEYVAULT_SECRET_ENDPOINT=$(az keyvault show --name "${KEY_VAULT_NAME}" \
--resource-group "${RESOURCE_GROUP_NAME}" \
--query properties.vaultUri\
--output tsv)

Expand Down
12 changes: 6 additions & 6 deletions .github/delete-azure-resources.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
# - APP_CONFIG_NAME
# - KEY_VAULT_NAME

az appconfig delete --name ${APP_CONFIG_NAME} --resource-group ${RESOURCE_GROUP_NAME} --yes
az appconfig purge --name ${APP_CONFIG_NAME} --yes
az storage account delete --name ${STORAGE_ACCOUNT_NAME} --resource-group ${RESOURCE_GROUP_NAME} --yes
az keyvault delete --name ${KEY_VAULT_NAME} --resource-group ${RESOURCE_GROUP_NAME} --yes
az keyvault purge --name ${KEY_VAULT_NAME} --yes
az group delete --name ${RESOURCE_GROUP_NAME} --yes
az appconfig delete --name "${APP_CONFIG_NAME}" --resource-group "${RESOURCE_GROUP_NAME}" --yes
az appconfig purge --name "${APP_CONFIG_NAME}" --yes
az storage account delete --name "${STORAGE_ACCOUNT_NAME}" --resource-group "${RESOURCE_GROUP_NAME}" --yes
az keyvault delete --name "${KEY_VAULT_NAME}" --resource-group "${RESOURCE_GROUP_NAME}"
az keyvault purge --name "${KEY_VAULT_NAME}"
az group delete --name "${RESOURCE_GROUP_NAME}" --yes
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,29 @@ h|[[quarkus-azure-app-configuration_configuration]]link:#quarkus-azure-app-confi
h|Type
h|Default

a| [[quarkus-azure-app-configuration_quarkus-azure-app-configuration-enabled]]`link:#quarkus-azure-app-configuration_quarkus-azure-app-configuration-enabled[quarkus.azure.app.configuration.enabled]`


[.description]
--
The flag to enable the app configuration. If set to false, the app configuration will be disabled

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_AZURE_APP_CONFIGURATION_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_AZURE_APP_CONFIGURATION_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`true`


a| [[quarkus-azure-app-configuration_quarkus-azure-app-configuration-endpoint]]`link:#quarkus-azure-app-configuration_quarkus-azure-app-configuration-endpoint[quarkus.azure.app.configuration.endpoint]`


[.description]
--
The endpoint of the app configuration
The endpoint of the app configuration. Required if quarkus.azure.app.configuration.enabled is set to true

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_AZURE_APP_CONFIGURATION_ENDPOINT+++[]
Expand All @@ -24,15 +41,15 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_AZURE_APP_CONFIGURATION_ENDPOINT+++`
endif::add-copy-button-to-env-var[]
--|string
|required icon:exclamation-circle[title=Configuration property is required]
|


a| [[quarkus-azure-app-configuration_quarkus-azure-app-configuration-id]]`link:#quarkus-azure-app-configuration_quarkus-azure-app-configuration-id[quarkus.azure.app.configuration.id]`


[.description]
--
The id of the app configuration
The id of the app configuration. Required if quarkus.azure.app.configuration.enabled is set to true

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_AZURE_APP_CONFIGURATION_ID+++[]
Expand All @@ -41,15 +58,15 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_AZURE_APP_CONFIGURATION_ID+++`
endif::add-copy-button-to-env-var[]
--|string
|required icon:exclamation-circle[title=Configuration property is required]
|


a| [[quarkus-azure-app-configuration_quarkus-azure-app-configuration-secret]]`link:#quarkus-azure-app-configuration_quarkus-azure-app-configuration-secret[quarkus.azure.app.configuration.secret]`


[.description]
--
The secret of the app configuration
The secret of the app configuration. Required if quarkus.azure.app.configuration.enabled is set to true

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_AZURE_APP_CONFIGURATION_SECRET+++[]
Expand All @@ -58,7 +75,7 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_AZURE_APP_CONFIGURATION_SECRET+++`
endif::add-copy-button-to-env-var[]
--|string
|required icon:exclamation-circle[title=Configuration property is required]
|


a| [[quarkus-azure-app-configuration_quarkus-azure-app-configuration-labels]]`link:#quarkus-azure-app-configuration_quarkus-azure-app-configuration-labels[quarkus.azure.app.configuration.labels]`
Expand Down
29 changes: 0 additions & 29 deletions docs/modules/ROOT/pages/includes/quarkus-azure-key-vault.adoc

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

:summaryTableId: quarkus-azure-keyvault-secret
[.configuration-legend]
icon:lock[title=Fixed at build time] Configuration property fixed at build time - All other configuration properties are overridable at runtime
[.configuration-reference.searchable, cols="80,.^10,.^10"]
|===

h|[[quarkus-azure-keyvault-secret_configuration]]link:#quarkus-azure-keyvault-secret_configuration[Configuration property]

h|Type
h|Default

a| [[quarkus-azure-keyvault-secret_quarkus-azure-keyvault-secret-enabled]]`link:#quarkus-azure-keyvault-secret_quarkus-azure-keyvault-secret-enabled[quarkus.azure.keyvault.secret.enabled]`


[.description]
--
The flag to enable the key vault secret. If set to false, the key vault secret will be disabled

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_AZURE_KEYVAULT_SECRET_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_AZURE_KEYVAULT_SECRET_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`true`


a| [[quarkus-azure-keyvault-secret_quarkus-azure-keyvault-secret-endpoint]]`link:#quarkus-azure-keyvault-secret_quarkus-azure-keyvault-secret-endpoint[quarkus.azure.keyvault.secret.endpoint]`


[.description]
--
The endpoint of Azure Key Vault Secret. Required if quarkus.azure.keyvault.secret.enabled is set to true

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_AZURE_KEYVAULT_SECRET_ENDPOINT+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_AZURE_KEYVAULT_SECRET_ENDPOINT+++`
endif::add-copy-button-to-env-var[]
--|string
|

|===
21 changes: 19 additions & 2 deletions docs/modules/ROOT/pages/includes/quarkus-azure-storage-blob.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,29 @@ endif::add-copy-button-to-env-var[]
|`default-storage-blob`


a| [[quarkus-azure-storage-blob_quarkus-azure-storage-blob-enabled]]`link:#quarkus-azure-storage-blob_quarkus-azure-storage-blob-enabled[quarkus.azure.storage.blob.enabled]`


[.description]
--
The flag to enable the storage blob. If set to false, the storage blob will be disabled

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_AZURE_STORAGE_BLOB_ENABLED+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_AZURE_STORAGE_BLOB_ENABLED+++`
endif::add-copy-button-to-env-var[]
--|boolean
|`true`


a| [[quarkus-azure-storage-blob_quarkus-azure-storage-blob-connection-string]]`link:#quarkus-azure-storage-blob_quarkus-azure-storage-blob-connection-string[quarkus.azure.storage.blob.connection-string]`


[.description]
--
The connection string of Azure Storage Account.
The connection string of Azure Storage Account. Required if quarkus.azure.storage.blob.enabled is set to true

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_AZURE_STORAGE_BLOB_CONNECTION_STRING+++[]
Expand All @@ -136,6 +153,6 @@ ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_AZURE_STORAGE_BLOB_CONNECTION_STRING+++`
endif::add-copy-button-to-env-var[]
--|string
|required icon:exclamation-circle[title=Configuration property is required]
|

|===
2 changes: 1 addition & 1 deletion docs/modules/ROOT/pages/quarkus-azure-key-vault.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,4 @@ You can also inject `com.azure.security.keyvault.secrets.SecretAsyncClient` obje

== Extension Configuration Reference

include::includes/quarkus-azure-key-vault.adoc[leveloffset=+1, opts=optional]
include::includes/quarkus-azure-keyvault-secret.adoc[leveloffset=+1, opts=optional]
5 changes: 2 additions & 3 deletions docs/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkiverse.azureservices</groupId>
Expand All @@ -8,7 +8,6 @@
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>io.quarkiverse.azureservices</groupId>
<artifactId>quarkus-azure-services-docs</artifactId>
<name>Quarkus Azure Services :: Documentation</name>

Expand Down Expand Up @@ -114,7 +113,7 @@
</resource>
<resource>
<directory>${project.basedir}/../target/asciidoc/generated/config/</directory>
<include>quarkus-azure-key-vault.adoc</include>
<include>quarkus-azure-keyvault-secret.adoc</include>
<filtering>false</filtering>
</resource>
<resource>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,37 @@
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "quarkus.azure.app.configuration")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface AzureAppConfigurationConfig {
/** The endpoint of the app configuration */
String endpoint();

/** The id of the app configuration */
String id();
/** The flag to enable the app configuration. If set to false, the app configuration will be disabled */
@WithDefault("true")
boolean enabled();

/** The secret of the app configuration */
String secret();
/** The endpoint of the app configuration. Required if quarkus.azure.app.configuration.enabled is set to true */
Optional<String> endpoint();

/** The id of the app configuration. Required if quarkus.azure.app.configuration.enabled is set to true */
Optional<String> id();

/** The secret of the app configuration. Required if quarkus.azure.app.configuration.enabled is set to true */
Optional<String> secret();

/** The label filter of the app configuration. Use comma as separator for multiple label names */
Optional<String> labels();

/** The connection string */
default String connectionString() {
return "Endpoint=" + endpoint() + ";Id=" + id() + ";Secret=" + secret();
if (enabled()) {
assert endpoint().isPresent() : "The endpoint of the app configuration must be set";
assert id().isPresent() : "The id of the app configuration must be set";
assert secret().isPresent() : "The secret of the app configuration must be set";
return "Endpoint=" + endpoint().get() + ";Id=" + id().get() + ";Secret=" + secret().get();
} else {
return null;
}
}
}
Loading

0 comments on commit 053f712

Please sign in to comment.