This article describes how to set up a local Gridwich development environment in either Visual Studio 2019 or above, or Visual Studio Code.
Prerequisites
- Up-to-date Visual Studio Code or Visual Studio 2019.
- Azure CLI
- .NET Core 3.1
- PowerShell
- Git installed, and your organization's Azure DevOps Gridwich repository cloned to your local machine. If you're using Windows GitHub Desktop, avoid cloning into user directories.
Optional:
Visual Studio Code setup
In Visual Studio Code, when prompted which version of Terraform language server to install, select the latest stable version:
After installation, run the following command:
dotnet restore ./src --interactiveAt the prompt, sign in to Azure so your build can access the artifact feed for installing the necessary NuGet packages.
Follow the instructions to create local.settings.json.
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/EventGridMediaInfo: [GET] http://localhost:7071/api/MediaInfo
Visual Studio setup
In Visual Studio, open the src\Gridwich.Host.FunctionApp.sln file in the directory where you cloned the Gridwich repository.
In Solution Explorer, right-click the Gridwich.Host.FunctionApp library and select Set as Startup Project.
Follow the instructions to create local.settings.json.
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/EventGridMediaInfo: [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.
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
mygridwichappwith 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.jsonEdit the resulting local.settings.sb.json file to remove the following lines:
AzureWebJobsDashboard- The
AzureWebJobsStoragepointing to a connection string WEBSITE_CONTENTAZUREFILECONNECTIONSTRINGWEBSITE_CONTENTSHAREWEBSITE_ENABLE_SYNC_UPDATE_SITEWEBSITE_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:
Run the following command:
az ad signed-in-user showIn the output, find and copy
userPrincipalName, which may look like:<your username_yourdomain>.com#EXT#@<an Azure Active Directory>.onmicrosoft.com.Run the following command, using the
userPrincipalNamevalue 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:
AmsDrmFairPlayCertificateB64. Use the base 64 string from FakeFairPlayCert/FairPlay-out-base64.txt. Remove the line endings and set the string in a single line.AmsDrmFairPlayPfxPassword. Use the dummy password from FakeFairPlayCert/password.txt.