예제 #1
0
        public async Task <List <SecureScore> > ConvertAsync(SecureScoreAttribute input, CancellationToken cancellationToken)
        {
            GraphService       graphService;
            List <SecureScore> secureScore;

            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));

                secureScore = await graphService.GetSecureScoreAsync(int.Parse(input.Period, CultureInfo.CurrentCulture), cancellationToken).ConfigureAwait(false);

                return(secureScore);
            }
            catch (ServiceClientException ex)
            {
                log.LogError(ex, $"Encountered an error when processing {input.CustomerId}");
                return(null);
            }
            finally
            {
                graphService = null;
            }
        }
        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;
            }
        }
예제 #3
0
 public async Task <IPartner> ConvertAsync(PartnerServiceAttribute input, CancellationToken cancellationToken)
 {
     return(PartnerService.Instance.CreatePartnerOperations(
                await PartnerCredentials.GenerateByApplicationCredentialsAsync(
                    input.ApplicationId,
                    await vault.GetSecretAsync(options.KeyVaultEndpoint, input.SecretName).ConfigureAwait(false),
                    input.ApplicationTenantId).ConfigureAwait(false),
                await GetPartnerHttpClientAsync(input.ApplicationTenantId).ConfigureAwait(false)));
 }
예제 #4
0
 public async Task <PartnerServiceClient> ConvertAsync(PartnerServiceAttribute input, CancellationToken cancellationToken)
 {
     return(new PartnerServiceClient(
                new Uri(input.Endpoint),
                new ServiceCredentials(
                    input.ApplicationId,
                    await vault.GetSecretAsync(options.KeyVaultEndpoint, input.SecretName).ConfigureAwait(false),
                    input.Resource,
                    input.ApplicationTenantId),
                await GetPartnerHttpClientAsync(input.ApplicationTenantId).ConfigureAwait(false)));
 }
예제 #5
0
        /// <summary>
        /// Initializes an instance of the <see cref="StorageService" /> class.
        /// </summary>
        /// <param name="keyVaultEndpoint">The Azure Key Vault endpoint address.</param>
        /// <param name="connectionString">Name of the secret that contains the Azure Storage connection string.</param>
        /// <returns>An instance of the <see cref="Task" /> class that represents the asynchronous operation.</returns>
        public async Task InitializeAsync(string keyVaultEndpoint, string connectionString)
        {
            vaultSerivce = new KeyVaultService(keyVaultEndpoint);

            if (!CloudStorageAccount.TryParse(
                    await vaultSerivce.GetSecretAsync(connectionString).ConfigureAwait(false),
                    out storageAccount))
            {
                throw new Exception("Unable to intialize the storage account. Please check the connection string setting.");
            }
        }
예제 #6
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);
            }
        }
        private async Task <IDocumentRepository <TEntity> > GetRepoAsync <TEntity>(
            string collectionId,
            string partitionKey = null) where TEntity : class
        {
            DocumentRepository <TEntity> repo;
            string authKey;

            try
            {
                await Semaphore.WaitAsync().ConfigureAwait(false);

                if (!repos.ContainsKey(collectionId))
                {
                    authKey = await vault.GetSecretAsync(options.KeyVaultEndpoint, CosmsosDbAccessKey).ConfigureAwait(false);

                    repo = new DocumentRepository <TEntity>(
                        options.CosmosDbEndpoint,
                        authKey,
                        DatabaseId,
                        collectionId,
                        partitionKey);

                    await repo.InitializeAsync().ConfigureAwait(false);

                    repos[collectionId] = repo;
                }

                return(repos[collectionId] as IDocumentRepository <TEntity>);
            }
            catch (Exception ex)
            {
                log.LogError(ex.ToString());

                throw;
            }
            finally
            {
                Semaphore.Release();
            }
        }
예제 #8
0
        public async Task <string> GetSecretMessage()
        {
            var secret = await _vaultService.GetSecretAsync("MessageResponder-ASecret");

            return(secret);
        }