Skip to content

Instantly share code, notes, and snippets.

View svenmalvik's full-sized avatar

Sven Malvik svenmalvik

View GitHub Profile
"$schema": "",
"contentVersion": "",
"parameters": {
"servicename": {
"type": "String",
"defaultValue": "YOUR_SERVICENAME"
"connectionstring": {
"type": "String"
svenmalvik / apim-logging-body-header.policy.xml
Last active May 27, 2022 08:31
Logging all headers and the body of a request from Azure API Management to Azure Event Hub
<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;
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 April 13, 2020 09:25
Provisioning API Management instance with PowerShell
#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 August 20, 2019 06:49
This policy snippet prevents one from using the master key by accident.
<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>