Skip to content

Instantly share code, notes, and snippets.

@TomaszOledzki
Created July 25, 2020 21:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TomaszOledzki/1c186db495d66df9dbddd017b4bf2c1c to your computer and use it in GitHub Desktop.
Save TomaszOledzki/1c186db495d66df9dbddd017b4bf2c1c to your computer and use it in GitHub Desktop.
# Script variables.
$functionAppId = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}';
$functionAppKey = @{
Name = 'ApiKey'
Value = '<my-secret-api-key>'
};
$headers = @{Authorization = ("Bearer {0}" -f $(GetToken))};
$body = @{Properties = $functionAppKey} | ConvertTo-Json;
## List api keys
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-Uri $("https://management.azure.com/{0}/host/default/listkeys?api-version=2019-08-01" -f $functionAppId);
## Create/Update api keys
Invoke-WebRequest `
-Method PUT `
-Headers $headers `
-Body $body `
-ContentType "application/json" `
-Uri $("https://management.azure.com/{0}/host/default/functionKeys/{1}?api-version=2019-08-01" -f $functionAppId,$functionAppKey.name);
## Delete api key
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri $("https://management.azure.com/{0}/host/default/functionKeys/{1}?api-version=2019-08-01" -f $functionAppId,$functionAppKey.Name);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment