Beispiel #1
0
        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)));
        }
Beispiel #2
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            if (builder != null)
            {
                ADPKeyVault secretVault = new ADPKeyVault(
                    new Uri("https://globalsecrets.vault.usgovcloudapi.net/"),
                    "WorkforceNowAPI",
                    "WorkforceNowAPI-ClientID",
                    "WorkforceNowAPI-Secret"
                    );
                WorkforceNowService adpService = new WorkforceNowService(
                    secretVault,
                    new Uri("https://accounts.adp.com/auth/oauth/v2/token?")
                    );

                builder.Services.AddTransient <ADPEventService>(s => (ADPEventService) new EventNotificationService(
                                                                    adpService,
                                                                    new Uri("https://api.adp.com/core/v1/event-notification-messages")
                                                                    ));
            }
        }