Skip to content

Instantly share code, notes, and snippets.


Sven Malvik svenmalvik

View GitHub Profile
View appservice.json
"$schema": "",
"contentVersion": "",
"parameters": {
"servicename": {
"type": "String",
"defaultValue": "YOUR_SERVICENAME"
"connectionstring": {
"type": "String"
svenmalvik / apim-logging-body-header.policy.xml
Last active May 27, 2022
Logging all headers and the body of a request from Azure API Management to Azure Event Hub
View apim-logging-body-header.policy.xml
<log-to-eventhub logger-id="svenmalvik-logger">
var body = context.Request.Body.As<string>(preserveContent: true);
// ToBase64 to get it better tranfered
var bodyToLog = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(body));
var headers = context.Request.Headers;
View azure-app-configuration-pre-request.js
function signRequest(host,
method, // GET, PUT, POST, DELETE
url, // path+query
body, // request body (undefined of none)
credential, // access key id
secret) // access key value (base64 encoded)
provider "azurerm" {
subscription_id = "YOUR_SUBSCRIPTION_ID"
tenant_id = "YOUR_TENANT_ID"
resource "azurerm_resource_group" "rg" {
name = "test-rg"
location = "westeurope"
svenmalvik / deployApim.ps1
Last active Apr 13, 2020
Provisioning API Management instance with PowerShell
View deployApim.ps1
#Requires -Version 3.0
TenantId of where API Management will be created
SubscriptionId of where API Management will be created
.PARAMETER SubscriptionId
Resource Group to be created or updated where API Management will be created
.PARAMETER ResourceGroupName
svenmalvik / apim-masterkey-prevention.policy.xml
Created Aug 20, 2019
This policy snippet prevents one from using the master key by accident.
View apim-masterkey-prevention.policy.xml
<when condition="@(context.Subscription != null && context.Subscription.Id == "master")">
<set-status code="400" reason="Bad Request" />
<set-header name="Content-Type" exists-action="override">
<value>application/json; charset=UTF-8</value>
<set-body>{"message": "Access denied due to invalid subscription key."}</set-body>