Ejemplo n.º 1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "requestinfocreator")] HttpRequest req,
            ILogger log,
            ExecutionContext context)
        {
            IConfigurationRoot config = new ConfigurationBuilder()
                                        .SetBasePath(context.FunctionAppDirectory)
                                        .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                                        .AddEnvironmentVariables()
                                        .Build();

            string  requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data        = JsonConvert.DeserializeObject(requestBody);

            try
            {
                string content   = data.content;
                string secretkey = data.secretkey;
                string endpoint  = data.endpoint;

                byte[] contentData = Encoding.UTF8.GetBytes(content);

                string now = DateTime.Now.ToString("O");

                string contentMd5    = MessageCreator.CalculateMD5Hash(content);
                string message       = MessageCreator.GenerateMessage(contentMd5, now, content, endpoint);
                string signature     = SignatureCreator.GenerateSignature(secretkey, message);
                int    contentLength = contentData.Length;

                var returnVal = new
                {
                    contentMd5,
                    signature,
                    now,
                    contentLength
                };

                return((ActionResult) new OkObjectResult(JsonConvert.SerializeObject(returnVal)));
            }
            catch (Exception e)
            {
                return(new BadRequestObjectResult("Error in PostiviidakkoRequestInfoCreator: " + e.ToString()));
            }
        }