-
Notifications
You must be signed in to change notification settings - Fork 1
/
Function1.cs
60 lines (55 loc) · 2.29 KB
/
Function1.cs
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
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using SampleADPAPI.Contracts;
using SampleADPAPI.Services;
using SampleADPAPI.Models.EventNotification;
namespace SampleADPAPI
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log, ExecutionContext context)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var config = new ConfigurationBuilder()
.SetBasePath(context.FunctionAppDirectory)
.AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
log.LogInformation("Starting Test");
log.LogInformation("Creating Key Vault");
ADPKeyVault secretVault = new ADPKeyVault(
new Uri(config["KeyVaultURI"]),
config["CertificateName"],
config["ClientIDName"],
config["ClientSecretName"]
);
log.LogInformation("Creating ADP Service");
WorkforceNowService adpService = new WorkforceNowService(
secretVault,
new Uri(config["TokenURI"])
);
log.LogInformation("Creating ADP Event Service");
EventNotificationService eventService = new EventNotificationService(
adpService,
new Uri(config["EventNotificationURI"])
);
log.LogInformation("Calling Events");
ADPEventMessage eventMessage = eventService.getEvents();
foreach (ADPEvent curEvent in eventMessage.Events)
log.LogInformation(curEvent.EventID + " - " + curEvent.EvenNameCode.CodeValue);
log.LogInformation("Nothing Crashed");
return new OkObjectResult(JsonConvert.SerializeObject(eventMessage));
}
}
}