public override Response <AuditResponse, Error> Handle(HttpRequest request) { var model = SerialiseToModel(request); model.ApiKey = Guid.Parse(request.Headers["X-API-KEY"].First()); return(InnerHandler.Handle(model)); }
public override Response <AuditResponse, Error> Handle(AuditRequest request) { var response = InnerHandler.Handle(request); if (response.IsSuccess) { FilterDefinitionBuilder <Tenant> filterBuilder = new FilterDefinitionBuilder <Tenant>(); var filter = filterBuilder.ElemMatch(x => x.Keys, key => key.Value == request.ApiKey); var tenant = _tenantCollection.FindSync(filter).First(); tenant.RecordProjectResult(new Project { Name = request.Project, Version = request.Version, Packages = response.Success.Packages.Select(package => new Domain.Package { Name = package.Name, Version = package.Version, PackageManager = "nuget", Vulnerabilities = package.Vulnerabilities?.Select(vulnerability => new Vulnerability { Classification = Classification.Unknown, Description = vulnerability.Description, Title = vulnerability.Title, References = vulnerability.References, AffectedVersions = vulnerability.Versions }).ToArray() ?? new Vulnerability[0] }) }); _tenantCollection.ReplaceOne(x => x.Id == tenant.Id, tenant); } return(response); }
public override TResponse Handle(HttpRequest request) { using (StreamReader reader = new StreamReader(request.Body)) { var json = reader.ReadToEnd(); var model = JsonConvert.DeserializeObject <TModel>(json); return(InnerHandler.Handle(model)); } }
public override Response <OrderDispatched, OrderError> Handle(Order request) { if (string.IsNullOrEmpty(request.Address)) { return(OrderError.Validation); } return(InnerHandler.Handle(request)); }
public override Response <TSuccess, Error> Handle(HttpRequest request) { if (request.Headers.ContainsKey("X-API-KEY") && Guid.TryParse(request.Headers["X-API-KEY"].FirstOrDefault(), out var key) && DoesKeyExist(key)) { return(InnerHandler.Handle(request)); } return(SharedPipes.Authorization.Errors.AuthorizationErrors.Unauthorized); }
public override Response <TSuccess, Error> Handle(HttpRequest request) { var result = ExtractToken(request); if (result.IsSuccess) { Thread.CurrentPrincipal = ValidateToken(result.Success); return(InnerHandler.Handle(request)); } return(result.Error); }
public override TestResponse Handle(TestRequestA request) { _request = request; _timestamp = DateTime.UtcNow; if (InnerHandler != null) { return(InnerHandler.Handle(new TestRequestB())); } return(new TestResponse()); }
public async Task <TResult> Handle(TCommand command, CancellationToken cancellationToken) { Logger.Info($"Executing command '{typeof(TCommand).Name}'."); var stopwatch = Stopwatch.StartNew(); var result = await InnerHandler.Handle(command, cancellationToken); var elapsed = stopwatch.Elapsed; Logger.Info($"Finished executing command '{typeof(TCommand).Name}' in {elapsed.TotalMilliseconds}ms."); return(result); }
public override Response <TSuccess, Error> Handle(HttpRequest request) { try { var result = ExtractToken(request); if (result.IsSuccess) { Thread.CurrentPrincipal = ValidateToken(result.Success); return(InnerHandler.Handle(request)); } return(result.Error); } catch (Exception e) { return(new Error(WellKnownErrorCodes.UnAuthorized, e.Message)); } }
public override Response <IList <TResponse>, Error> Handle(IList <TRequest> request) { IList <TResponse> cachedPackages = _redisClient.GetByIds(request.Select(x => x.Id)); var newPackages = request.Where(x => cachedPackages.All(package => package.Id != x.Id)) .ToList(); var response = InnerHandler.Handle(newPackages); if (response.IsSuccess) { CacheResponse(response.Success); return(response.Success .Union(cachedPackages) .ToList()); } return(response); }
public override Response <AuditResponse, Error> Handle(AuditRequest request) { IList <PackageSummary> cachedPackages = _redisClient.GetByIds(request.Packages.Select(x => $"{x.Name}{x.Version}".ToUpper())); request.Packages = request.Packages .Where(x => cachedPackages.All(package => x.Name != package.Name && x.Version != package.Version)) .ToList(); var response = InnerHandler.Handle(request); if (response.IsSuccess) { CacheResponse(response.Success.Packages); return(response.Success); } return(response); }
public async Task <TResult> Handle(TCommand command, CancellationToken cancellationToken) { // Run all validators at once. var results = await Task.WhenAll(Validators .Select(validator => validator.ValidateAsync(command)) .ToArray()); // Collect all errors. var errors = results.Where(x => !x.IsValid) .SelectMany(x => x.Errors) .ToArray(); if (errors.Any()) { // Validation failed, throw exception. throw new ValidationException(errors); } // Continue to next handler. return(await InnerHandler.Handle(command, cancellationToken)); }
public override TResponse Handle(TRequest request) { var account = Thread.CurrentPrincipal.ToAccount(); return(InnerHandler.Handle(account)); }
public override TResponse Handle(HttpRequest request) { var model = SerialiseToModel(request); return(InnerHandler.Handle(model)); }