-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
70 lines (58 loc) · 2.83 KB
/
Copy pathProgram.cs
File metadata and controls
70 lines (58 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Collections.Generic;
using System.Configuration;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using Microsoft.Azure.EventGrid;
using Microsoft.Azure.EventGrid.Models;
namespace nz.co.connectedcircuits.eventpublisher
{
class Program
{
static void Main(string[] args)
{
const string LIT_KEYVAULT_SECRET_NAME = "lob-event-grid";
string keyVaultUrl = ConfigurationManager.AppSettings["KEY_VAULT_URL"]; //Azure keyvault URL
string clientId = ConfigurationManager.AppSettings["CLIENT_ID"]; //AAD App registration Client Id
string clientSecret = ConfigurationManager.AppSettings["CLIENT_SECRET"]; //AAD App registration secret
string tentantId = ConfigurationManager.AppSettings["TENTANT_ID"]; //AAD Tentant Id
string eventgridTopicEndpoint = ConfigurationManager.AppSettings["EVENT_GRID_TOPIC_ENDPOINT"]; //Azure event grid topic endpoint
//Get the event grid access key secret from key vault
var client = new SecretClient(new Uri(keyVaultUrl),
new ClientSecretCredential(tentantId, clientId, clientSecret));
var topicKey = client.GetSecret(LIT_KEYVAULT_SECRET_NAME).Value.Value;
TopicCredentials topicCredentials = new TopicCredentials(topicKey);
EventGridClient eventclient = new EventGridClient(topicCredentials);
for(int eventIndex=0; eventIndex < 3; eventIndex++)
{
//send an event to simulate address details have been updated
var entityId = Guid.NewGuid().ToString("D");
// Add EventGridEvents to a list to publish to the topic
List<EventGridEvent> eventsList = new List<EventGridEvent>
{
new EventGridEvent
{
DataVersion = "1.0",
EventTime = DateTime.UtcNow,
EventType = "nz.co.connectedcircuits.crm",
Id = Guid.NewGuid().ToString("D"),
Subject = "entity/address/update",
Data = new EventData
{
CallbackUrl = new UriBuilder("https", "en431qbm266j.x.pipedream.net/" + entityId + "/address").ToString(),
EntityId = entityId,
Source = "crm"
}
}
};
eventclient.PublishEventsAsync(new Uri(eventgridTopicEndpoint).Host, eventsList).GetAwaiter().GetResult();
}
}
}
class EventData
{
public string EntityId { get; set; }
public string Source { get; set; }
public string CallbackUrl { get; set; }
}
}