Skip to content

Instantly share code, notes, and snippets.

View dbarkol's full-sized avatar
💭
poppin and lockin

David Barkol dbarkol

💭
poppin and lockin
View GitHub Profile
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="EH_FQDN" value="{eventhubs-namespace-name}.servicebus.windows.net:9093"/>
<add key="EH_CONNECTION_STRING" value="Endpoint=sb://{eventhubs-namespace-name}.servicebus.windows.net/;SharedAccessKeyName=xxxx;SharedAccessKey=xxxx"/>
<add key="EH_NAME" value="{event-hub-name}"/>
<add key="CA_CERT_LOCATION" value=".\cacert.pem"/>
<add key="SCHEMA_GROUP" value="{schema-group-name}"/>
<add key="SCHEMA_REGISTRY_URL" value="{eventshubs-namespace-name}.servicebus.windows.net"/>
<add key="SCHEMA_REGISTRY_TENANT_ID" value="{tenant id}"/>
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using CloudNative.CloudEvents;
using SongRequests.Models;
using Newtonsoft.Json;
namespace SongRequests.Controllers
{
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.json({ type: 'application/*+json' }));
const port = 3000
app.get('/dapr/subscribe', (req, res) => {
res.json([
{
@dbarkol
dbarkol / cloudevents-options-apim.xml
Created January 20, 2020 20:15
CloudEvents validation with APIM
<inbound>
<base />
<!-- Get the WebHook-Request-Origin -->
<set-variable value="@(context.Request.Headers.GetValueOrDefault("WebHook-Request-Origin"))"
name="webhookRequestOrigin" />
<!--
Return the response with the allowed origin
and allowed rate to confirm the subscription.
@dbarkol
dbarkol / cloudevents-options-functions.cs
Created January 20, 2020 20:13
CloudEvents validation with Azure Functions
public static class TestFuncApi
{
[FunctionName("TestFuncApi")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post", "options", Route = null)] HttpRequest req,
ILogger log)
{
if (req.Method == "OPTIONS")
{
// Retrieve the request origin
@dbarkol
dbarkol / cloudevents-options-webapi.cs
Created January 20, 2020 19:25
Validation response for CloudEvents in ASP.NET Core Web API
[HttpOptions]
public async Task<IActionResult> Options()
{
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
{
// Retrieve the validation header fields
var webhookRequestOrigin = HttpContext.Request.Headers["WebHook-Request-Origin"].FirstOrDefault();
var webhookRequestCallback = HttpContext.Request.Headers["WebHook-Request-Callback"];
var webhookRequestRate = HttpContext.Request.Headers["WebHook-Request-Rate"];
@dbarkol
dbarkol / cloudevent-sample.json
Last active January 20, 2020 00:36
CloudEvent sample payload
{
"specversion" : "1.0",
"id" : "b85d631a-101e-005a-02f2-cee7aa06f148",
"type" : "zohan.music.request",
"source" : "https://zohan.dev/music/",
"subject" : "zohan/music/requests/4322",
"time" : "2020-09-14T10:00:00Z",
"data" : {
"artist": "Gerardo",
"song": "Rico Suave"
rgname={your-resource-group-name}
servicebus_uri={namespace-name}.servicebus.windows.net/{queue-name}
shared_access_key_name={your-shared-access-key-name}
shared_access_key={your-shared-access-key}
EXPIRY=${EXPIRY:=$((60 * 60 * 24))}
ENCODED_URI=$(echo -n $servicebus_uri | jq -s -R -r @uri)
TTL=$(($(date +%s) + $EXPIRY))
UTF8_SIGNATURE=$(printf "%s\n%s" $ENCODED_URI $TTL | iconv -t utf8)
<policies>
<inbound>
<base />
<!-- Retrieve the secret from Key Vault using a managed identity -->
<send-request mode="new" response-variable-name="secretResponse" timeout="20" ignore-error="false">
<set-url>{{vaultBaseUrl}}/secrets/{{secret-name}}/?api-version=7.0</set-url>
<set-method>GET</set-method>
<authentication-managed-identity resource="https://vault.azure.net" />
</send-request>