Exemplo n.º 1
0
        /// <inheritdoc />
        public async Task SaveInProgressImageScan(ImageScanResultWithCVEs imageScanResult)
        {
            Logger.Information("Saving In-Progress Image Scan {ImageScanId} for {ImageTag}", imageScanResult.Id, imageScanResult.ImageTag);

            this.db.Set <ImageScanResultEntity>().Add(imageScanResult.ToEntity());
            await this.db.SaveChangesAsync();
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        public async Task SaveImageScanResult(ImageScanResultWithCVEs imageScanResult)
        {
            Logger.Information(
                "Saving Image Scan {ImageScanId} for {ImageTag} with {FoundCVE} found CVEs",
                imageScanResult.Id,
                imageScanResult.ImageTag,
                imageScanResult.FoundCVEs?.Count ?? 0);

            var existingScanResult = await this.db.Set <ImageScanResultEntity>().FirstOrDefaultAsync(i => i.ExternalId == imageScanResult.Id);

            if (existingScanResult == null)
            {
                this.db.Set <ImageScanResultEntity>().Add(imageScanResult.ToEntity());
            }
            else
            {
                var newEntity = imageScanResult.ToEntity();
                existingScanResult.Date        = newEntity.Date;
                existingScanResult.FoundCVEs   = newEntity.FoundCVEs;
                existingScanResult.Status      = newEntity.Status;
                existingScanResult.Description = newEntity.Description;

                this.db.Set <ImageScanResultEntity>().Update(existingScanResult);
            }

            // update in-progress check-results
            var checkResults = await this.db.Set <CheckResultEntity>()
                               .Where(i => i.Value == CheckValue.InProgress && i.ComponentId.EndsWith(imageScanResult.ImageTag))
                               .ToArrayAsync();

            foreach (var result in checkResults)
            {
                result.Value   = imageScanResult.GetCheckResultValue().ToEntity();
                result.Message = imageScanResult.GetCheckResultMessage();
                this.db.Update(result);
            }

            await this.db.SaveChangesAsync();
        }