Challenge 04 - Configuration

< Previous Challenge - Home - Next Challenge >

Introduction

The TollBooth application’s function code does not have any credentials or settings stored in its code files. Instead, it reads its secrets and configuration settings from Environment Variables that must be set and passed in by the hosting environment (Azure Function App).

Azure Function Apps enable you to set these values in their hosting environment. They are known as Application Settings. For further security, the secret values are not directly stored in the Application Settings, we just point to the KeyVault secret instead, and let Azure dynamically fetch the secret values thanks to Managed Identities and RBAC.

Description

In this challenge, you will create Application Settings for each of the configuration settings and secrets the TollBooth app requires, leveraging the native KeyVault integration.

You will also prepare the TollBooth application’s code by adding code snippets that reference the Environment Variables and other functions it will call.

Configure Function App Application Settings in Azure

Via the Azure Portal, add the application settings in the first Azure Function App (.NET based, with name containing app), as follows:

Application Key Value
computerVisionApiUrl Computer Vision API endpoint you copied earlier. Append vision/v3.2/ocr to the end. Example: https://westus.api.cognitive.microsoft.com/vision/v3.2/ocr
computerVisionApiKey computerVisionApiKey pointer to the Key Vault secret
eventGridTopicEndpoint Event Grid Topic endpoint
eventGridTopicKey eventGridTopicKey pointer to the Key Vault secret
cosmosDBEndPointUrl Cosmos DB URI
cosmosDBAuthorizationKey cosmosDBAuthorizationKey pointer to the Key Vault secret
cosmosDBDatabaseId Cosmos DB database id (i.e “LicensePlates”)
cosmosDBCollectionId Cosmos DB processed container id (i.e “Processed”)
exportCsvContainerName Blob storage CSV export container name (i.e “export”)
blobStorageConnection blobStorageConnection pointer to the Key Vault secret

HINT: The pointers to KeyVault Secrets must finish with a trailing “/” when not referring a version. For example: @Microsoft.KeyVault(SecretUri=https://kvname.vault.azure.net/secrets/blobStorageConnection/)

If you did not configure the Function App in Azure to access Key Vault in the previous challenge, you will need to do this now:

Configure TollBooth Application Code

// TODO 1: Set the licensePlateText value by awaiting a new FindLicensePlateText.GetLicensePlate method.
licensePlateText = await new FindLicensePlateText(log, _client).GetLicensePlate(licensePlateImage);
// TODO 2: Populate the below two variables with the correct AppSettings properties.
var uriBase = Environment.GetEnvironmentVariable("computerVisionApiUrl");
var apiKey = Environment.GetEnvironmentVariable("computerVisionApiKey");
// TODO 3: Modify send method to include the proper eventType name value for saving plate data.
await Send("savePlateData", "TollBooth/CustomerService", data);

// TODO 4: Modify send method to include the proper eventType name value for queuing plate for manual review.
await Send("queuePlateForManualCheckup", "TollBooth/CustomerService", data);

Understand the TollBooth App code (Optional)

Success Criteria

  1. The solution successfully builds
  2. The Application Settings menu in the Function App does not show any access error for the variables pointing to KeyVault secrets

Learning Resources