Gridwich local development environment setup

Azure DevOps
Key Vault

This article describes how to set up a local Gridwich development environment in either Visual Studio 2019 or above, or Visual Studio Code.

Prerequisites

Optional:

Visual Studio Code setup

  1. In Visual Studio Code, when prompted which version of Terraform language server to install, select the latest stable version:

  2. After installation, run the following command:

    dotnet restore ./src --interactive
    
  3. At the prompt, sign in to Azure so your build can access the artifact feed for installing the necessary NuGet packages.

  4. Follow the instructions to create local.settings.json.

  5. Press F5.

You can now make requests to the two Function endpoints shown in the build output, for example:

  • EventGrid: [POST] http://localhost:7071/api/EventGrid
  • MediaInfo: [GET] http://localhost:7071/api/MediaInfo

Visual Studio setup

  1. In Visual Studio, open the src\Gridwich.Host.FunctionApp.sln file in the directory where you cloned the Gridwich repository.

  2. In Solution Explorer, right-click the Gridwich.Host.FunctionApp library and select Set as Startup Project.

  3. Follow the instructions to create local.settings.json.

  4. Press F5.

You can now make requests to the two Function endpoints shown in the build output, for example:

  • EventGrid: [POST] http://localhost:7071/api/EventGrid
  • MediaInfo: [GET] http://localhost:7071/api/MediaInfo

Create local.settings.json

The following procedure creates the settings on your local machine to run the Gridwich Azure Function.

For an example local.settings.json file, see sample.local.settings.json.

If you need an Azure PowerShell CLI environment, you can use Azure Cloud Shell and select PowerShell instead of Bash.

  1. To create the file, use the following PowerShell script and edit the results. In the script, use your Azure tenant and subscription values, and replace mygridwichapp with your application name.

    # Change the $targetEnv if you're not using the 'sb' environment
    $targetEnv = "sb"
    $targetTenant = "00000000-0000-0000-0000-000000000000"
    $targetSub = "00000000-0000-0000-0000-000000000000"
    $appname = "mygridwichapp"
    
    az account set --subscription $targetSub
    $appSettings = az webapp config appsettings list --subscription $targetSub --name $appname-grw-fxn-$targetEnv -g $appname-application-rg-$targetEnv | ConvertFrom-Json
    $settingsList = New-Object System.Collections.ArrayList($null)
    $settingsList.AddRange($appSettings)
    echo "{""IsEncrypted"": false,""Values"": {" > local.settings.$targetEnv.json
    $settingsList.ForEach({echo """$($_.name)"":""$($_.value)"","}) >> local.settings.$targetEnv.json
    echo """AzureWebJobsStorage"": ""UseDevelopmentStorage=true"",""FUNCTIONS_WORKER_RUNTIME"": ""dotnet"",""AZURE_TENANT_ID"": ""$targetTenant"",""AZURE_SUBSCRIPTION_ID"": ""$targetSub""}}" >> local.settings.$targetEnv.json
    type local.settings.$targetEnv.json
    
  2. Edit the resulting local.settings.sb.json file to remove the following lines:

    • AzureWebJobsDashboard
    • The AzureWebJobsStorage pointing to a connection string
    • WEBSITE_CONTENTAZUREFILECONNECTIONSTRING
    • WEBSITE_CONTENTSHARE
    • WEBSITE_ENABLE_SYNC_UPDATE_SITE
    • WEBSITE_RUN_FROM_PACKAGE

Update Azure Key Vault secrets

To view Azure Key Vault keys and secrets, run the following script:

$keyVaultName = 'gridwich-kv-sb'
$targetUserPrincipalName = (az ad signed-in-user show | ConvertFrom-Json).userPrincipalName
az keyvault set-policy --name $keyVaultName --secret-permissions list get --upn $targetUserPrincipalName

Or, you can use the following Azure CLI commands:

  1. Run the following command:

    az ad signed-in-user show
    
  2. In the output, find and copy userPrincipalName, which may look like: <your username_yourdomain>.com#EXT#@<an Azure Active Directory>.onmicrosoft.com.

  3. Run the following command, using the userPrincipalName value you copied:

    az keyvault set-policy --name gridwich-kv-sb --secret-permissions list get --upn "<your username_yourdomain>.com#EXT#@<an Azure Active Directory>.onmicrosoft.com"
    

To replace the @Microsoft.KeyVault secrets in local.settings.sb.json with actual values, run:

$keyVaultName="$appname-kv-$targetEnv"
$targetUserPrincipalName = (az ad signed-in-user show | ConvertFrom-Json).userPrincipalName
az keyvault set-policy --name $keyVaultName --secret-permissions list get --upn $targetUserPrincipalName
$AmsAadClientId=$((az keyvault secret show --vault-name $keyVaultName --name ams-sp-client-id | ConvertFrom-Json).value)
$AmsAadClientSecret=$((az keyvault secret show --vault-name $keyVaultName --name ams-sp-client-secret  | ConvertFrom-Json).value)
$APPINSIGHTS_INSTRUMENTATIONKEY=$((az keyvault secret show --vault-name $keyVaultName --name appinsights-instrumentationkey  | ConvertFrom-Json).value)
$TELESTREAMCLOUD_API_KEY=$((az keyvault secret show --vault-name $keyVaultName --name telestream-cloud-api-key  | ConvertFrom-Json).value)
$GRW_TOPIC_END_POINT=$((az keyvault secret show --vault-name $keyVaultName --name grw-topic-end-point  | ConvertFrom-Json).value)
$GRW_TOPIC_KEY=$((az keyvault secret show --vault-name $keyVaultName --name grw-topic-key   | ConvertFrom-Json).value)
$AmsDrmFairPlayAskHex=$((az keyvault secret show --vault-name $keyVaultName --name ams-fairplay-ask-hex   | ConvertFrom-Json).value)
echo $('"AmsAadClientId":"'+$AmsAadClientId+'",') $('"AmsAadClientSecret":"'+$AmsAadClientSecret+'",') $('"APPINSIGHTS_INSTRUMENTATIONKEY":"'+$APPINSIGHTS_INSTRUMENTATIONKEY+'",') $('"TELESTREAMCLOUD_API_KEY":"'+$TELESTREAMCLOUD_API_KEY+'",') $('"GRW_TOPIC_END_POINT":"'+$GRW_TOPIC_END_POINT+'",') $('"GRW_TOPIC_KEY":"'+$GRW_TOPIC_KEY+'",') $('"AmsDrmFairPlayAskHex":"'+$AmsDrmFairPlayAskHex+'",')

Replace the local file

Rename local.settings.sb.json to local.settings.json and copy it to Gridwich.Host.FunctionApp/src. Or edit local.settings.json in place, using the console output from the preceding scripts.

Add dummy values for Azure FairPlay DRM

Manually add the following two values to local.settings.json:

Next steps