示例#1
0
        public async Task <string> Run([HttpTrigger(AuthorizationLevel.Anonymous, "POST", Route = null)] HttpRequestMessage req)
        {
            var key = JsonConvert.DeserializeObject <string>(await req.Content.ReadAsStringAsync());

            if (string.IsNullOrEmpty(key))
            {
                return("No key has been supplied.");
            }

            try
            {
                //Connect to the KeyVault by using the token and get the secret
                var            azureServiceTokenProvider = new AzureServiceTokenProvider();
                KeyVaultClient keyVaultClient            = new KeyVaultClient(
                    new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback)
                    );

                var keyvaultUri = GetYerMawOnTheBlower.GetEnvironmentVariable(KEYVAUL_URL_SETTINGS_KEY);
                var secretUrl   = $"{keyvaultUri}/secrets/{key}";

                var secret = await keyVaultClient.GetSecretAsync(secretUrl);

                return(secret.Value);
            }
            catch (KeyNotFoundException keyVaultException)
            {
                return(keyVaultException.Message);
            }
        }
示例#2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequestMessage req
            )
        {
            var emailPollerUri = GetYerMawOnTheBlower.GetEnvironmentVariable(EMAIL_POLLER_APP_SETTING_KEY);

            var taskList = new List <Task <KeyValuePair <string, string> > >()
            {
                GetKeyVaultValueToTuple(emailPollerUri, EMAIL_USER_KEY),
                GetKeyVaultValueToTuple(emailPollerUri, EMAIL_PASSWORD_KEY),
                GetKeyVaultValueToTuple(emailPollerUri, EMAIL_SERVER_KEY),
                GetKeyVaultValueToTuple(emailPollerUri, EMAIL_PORT_KEY),
            };

            var result = await Task.WhenAll(taskList);

            if (result.Any(x => string.IsNullOrEmpty(x.Value)))
            {
                return(new NotFoundResult());
            }

            var response = BuildQueryResponse(result);

            return(new OkObjectResult(response));
        }
示例#3
0
        private async Task SetEmailKeys()
        {
            var emailPollerUri = GetYerMawOnTheBlower.GetEnvironmentVariable(EMAIL_POLLER_APP_SETTING_KEY);

            var keyQueryResponse = await GetYerMawOnTheBlower.Honk(emailPollerUri, EMAIL_KEY_FUNCTION_NAME);

            var emailKeys = JsonConvert.DeserializeObject <EmailKeyQueryResponse>(keyQueryResponse);

            _mailSettings.Account           = emailKeys.Account;
            _mailSettings.ImapConfiguration = emailKeys.ImapComfig;
        }
示例#4
0
        private async Task SendServiceBusMessages(IEnumerable <MessageDetail> messages)
        {
            var emailPollerUri = GetYerMawOnTheBlower.GetEnvironmentVariable(EMAIL_POLLER_APP_SETTING_KEY);

            var honkTheLot = new List <Task>();

            foreach (var message in messages)
            {
                honkTheLot.Add(GetYerMawOnTheBlower.Honk <string>(emailPollerUri, SB_MESSAGE_FUNCTION_NAME, message));
            }

            await Task.WhenAll(honkTheLot);
        }