public async Task <List <Alert> > ConvertAsync(SecurityAlertsAttribute input, CancellationToken cancellationToken)
        {
            GraphService graphService;
            List <Alert> alerts;

            try
            {
                graphService = new GraphService(new Uri(input.Resource),
                                                new ServiceCredentials(
                                                    input.ApplicationId,
                                                    await vault.GetSecretAsync(options.KeyVaultEndpoint, input.SecretName).ConfigureAwait(false),
                                                    input.Resource,
                                                    input.CustomerId));

                alerts = await graphService.GetAlertsAsync(cancellationToken).ConfigureAwait(false);

                return(alerts);
            }
            catch (ServiceClientException ex)
            {
                log.LogError(ex, $"Encountered an error when processing {input.CustomerId}");
                return(null);
            }
            finally
            {
                graphService = null;
            }
        }
예제 #2
0
        public async Task <List <Alert> > ConvertAsync(SecurityAlertsAttribute input, CancellationToken cancellationToken)
        {
            GraphServiceClient            client;
            ISecurityAlertsCollectionPage page;
            List <Alert> alerts;

            try
            {
                client = new GraphServiceClient(
                    new DelegateAuthenticationProvider(async(requestMessage) =>
                {
                    requestMessage
                    .Headers
                    .Authorization = new AuthenticationHeaderValue(
                        "Bearer",
                        await GetTokenAsync(
                            input.ApplicationId,
                            await vault.GetSecretAsync(options.KeyVaultEndpoint, input.SecretName).ConfigureAwait(false),
                            input.Resource,
                            input.CustomerId).ConfigureAwait(false));
                }));

                page = await client.Security.Alerts.Request().GetAsync().ConfigureAwait(false);

                alerts = new List <Alert>(page.CurrentPage);

                while (page.NextPageRequest != null)
                {
                    page = await page.NextPageRequest.GetAsync().ConfigureAwait(false);

                    alerts.AddRange(page.CurrentPage);
                }

                return(alerts);
            }
            catch (ServiceClientException ex)
            {
                log.LogError(ex, $"Encountered an error when processing {input.CustomerId}");
                return(null);
            }
        }