示例#1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "diagnosis")] HttpRequest req)
        {
            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            var diagnosis   = JsonConvert.DeserializeObject <DiagnosisSubmissionParameter>(requestBody);

            // validation
            var validationResult = await Validation.ValidateAsync(req, diagnosis);

            if (!validationResult.IsValid)
            {
                return(validationResult.ErrorActionResult);
            }

            var timestamp = (ulong)DateTimeOffset.UtcNow.ToUnixTimeSeconds();

            // TODO: Device verify

            await DiagnosisRepository.SubmitDiagnosisAsync(
                diagnosis.SubmissionNumber,
                diagnosis.UserUuid,
                diagnosis.Keys.Select(_ => _.ToModel(diagnosis, timestamp)).ToArray());

            return(new OkResult());
        }
        public async Task <IActionResult> RunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "diagnosis")] HttpRequest req)
        {
            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            var diagnosis   = JsonConvert.DeserializeObject <DiagnosisSubmissionParameter>(requestBody);

            // payload valid
            if (!diagnosis.IsValid())
            {
                return(new BadRequestErrorMessageResult("Invalid parameter"));
            }

            if (!SupportRegions.Contains(diagnosis.Region))
            {
                return(new BadRequestErrorMessageResult("Regions not supported."));
            }

            // validation
            var validationResult = await Validation.ValidateAsync(req, diagnosis);

            if (!validationResult.IsValid)
            {
                return(validationResult.ErrorActionResult);
            }

            // Device validation
            if (false == await DeviceCheck.Validation(diagnosis))
            {
                return(new BadRequestErrorMessageResult("Invalid Device"));
            }

            var timestamp = DateTimeOffset.UtcNow;
            var keys      = diagnosis.Keys.Select(_ => _.ToModel(diagnosis, (ulong)timestamp.ToUnixTimeSeconds())).ToArray();

            await DiagnosisRepository.SubmitDiagnosisAsync(
                diagnosis.SubmissionNumber,
                timestamp,
                diagnosis.UserUuid,
                keys);

            foreach (var k in keys)
            {
                await TekRepository.UpsertAsync(k);
            }

            return(new NoContentResult());
        }
示例#3
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "diagnosis")] HttpRequest req)
        {
            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            var diagnosis   = JsonConvert.DeserializeObject <DiagnosisSubmissionParameter>(requestBody);

            // validation
            var validationResult = await Validation.ValidateAsync(req, diagnosis);

            if (!validationResult.IsValid)
            {
                return(validationResult.ErrorActionResult);
            }

            await DiagnosisRepository.SubmitDiagnosisAsync(diagnosis);

            return(new OkResult());
        }
示例#4
0
        public async Task <IActionResult> RunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "diagnosis")] HttpRequest req)
        {
            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();

            Logger.LogInformation($"{nameof(RunAsync)} request body {requestBody}");

            // Check Valid Route
            IValidationServerService.ValidateResult validateResult = ValidationServerService.Validate(req);
            if (!validateResult.IsValid)
            {
                return(validateResult.ErrorActionResult);
            }

            var diagnosis = JsonConvert.DeserializeObject <DiagnosisSubmissionParameter>(requestBody);
            var reqTime   = DateTimeOffset.UtcNow;

            // payload valid
            if (!diagnosis.IsValid())
            {
                Logger.LogInformation($"Invalid parameter");
                return(new BadRequestErrorMessageResult("Invalid parameter"));
            }

            // validation support region
            if (!diagnosis.Regions.Any(_ => SupportRegions.Contains(_)))
            {
                Logger.LogInformation($"Regions not supported.");
                return(new BadRequestErrorMessageResult("Regions not supported."));
            }

            // validation
            var validationResult = await Validation.ValidateAsync(req, diagnosis);

            if (!validationResult.IsValid)
            {
                Logger.LogInformation($"validation error.");
                return(validationResult.ErrorActionResult);
            }

            // TODO: Security Consider, additional validation for user uuid.

            // validation device
            if (false == await DeviceCheck.Validation(diagnosis, reqTime))
            {
                Logger.LogInformation($"Invalid Device");
                return(new BadRequestErrorMessageResult("Invalid Device"));
            }

            // validatetion VerificationPayload
            var verificationResult = await VerificationService.VerificationAsync(diagnosis.VerificationPayload);

            if (verificationResult != 200)
            {
                return(new ObjectResult("Bad VerificationPayload")
                {
                    StatusCode = verificationResult
                });
            }

            var timestamp = DateTimeOffset.UtcNow;
            var keys      = diagnosis.Keys.Select(_ => _.ToModel(diagnosis, (ulong)timestamp.ToUnixTimeSeconds())).ToArray();

            await DiagnosisRepository.SubmitDiagnosisAsync(
                diagnosis.VerificationPayload,
                timestamp,
                diagnosis.UserUuid,
                keys);

            foreach (var k in keys)
            {
                await TekRepository.UpsertAsync(k);
            }

            return(new NoContentResult());
        }
示例#5
0
        public async Task <IActionResult> RunAsync(
            [HttpTrigger(AuthorizationLevel.Function, "put", Route = "diagnosis")] HttpRequest req)
        {
            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            var diagnosis   = JsonConvert.DeserializeObject <DiagnosisSubmissionParameter>(requestBody);
            var reqTime     = DateTimeOffset.UtcNow;

            // payload valid
            if (!diagnosis.IsValid())
            {
                return(new BadRequestErrorMessageResult("Invalid parameter"));
            }

            // validation support region
            if (!diagnosis.Regions.Any(_ => SupportRegions.Contains(_)))
            {
                return(new BadRequestErrorMessageResult("Regions not supported."));
            }


            // validation
            var validationResult = await Validation.ValidateAsync(req, diagnosis);

            if (!validationResult.IsValid)
            {
                return(validationResult.ErrorActionResult);
            }

            // validation device
            if (false == await DeviceCheck.Validation(diagnosis, reqTime))
            {
                return(new BadRequestErrorMessageResult("Invalid Device"));
            }

            // TODO: validatetion VerificationPayload 4xx
            if (false == true)
            {
                return(new ObjectResult("Bad VerificationPayload")
                {
                    StatusCode = 406
                });
            }
            // TODO: validatetion VerificationPayload connnection error 5xx
            if (false == true)
            {
                return(new ObjectResult("Unable to communicate with center")
                {
                    StatusCode = 503
                });
            }

            var timestamp = DateTimeOffset.UtcNow;
            var keys      = diagnosis.Keys.Select(_ => _.ToModel(diagnosis, (ulong)timestamp.ToUnixTimeSeconds())).ToArray();

            await DiagnosisRepository.SubmitDiagnosisAsync(
                diagnosis.VerificationPayload,
                timestamp,
                diagnosis.UserUuid,
                keys);

            foreach (var k in keys)
            {
                await TekRepository.UpsertAsync(k);
            }

            return(new NoContentResult());
        }