public async Task <SymbolsServerRequest> AddSymbolsServerRequestAsync(SymbolsServerRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }
            var currentRequest = await GetSymbolsServerRequestAsync(request.RequestName, request.SymbolsKey);

            if (currentRequest != null)
            {
                return(currentRequest);
            }

            _validationEntitiesContext.SymbolsServerRequests.Add(request);
            try
            {
                await _validationEntitiesContext.SaveChangesAsync();

                return(request);
            }
            catch (DbUpdateException e) when(e.IsUniqueConstraintViolationException())
            {
                // The request must be ingested already.
                return(await GetSymbolsServerRequestAsync(request.RequestName, request.SymbolsKey));
            }
        }
Esempio n. 2
0
        private Task SaveGoodCertificateStatusAsync(EndCertificateValidation validation, CertificateVerificationResult result)
        {
            validation.EndCertificate.Status               = EndCertificateStatus.Good;
            validation.EndCertificate.StatusUpdateTime     = result.StatusUpdateTime;
            validation.EndCertificate.NextStatusUpdateTime = null;
            validation.EndCertificate.LastVerificationTime = DateTime.UtcNow;
            validation.EndCertificate.RevocationTime       = null;
            validation.EndCertificate.ValidationFailures   = 0;

            validation.Status = EndCertificateStatus.Good;

            return(_context.SaveChangesAsync());
        }
Esempio n. 3
0
        public async Task <PackageValidationSet> CreateValidationSetAsync(PackageValidationSet packageValidationSet)
        {
            packageValidationSet = packageValidationSet ?? throw new ArgumentNullException(nameof(packageValidationSet));
            _logger.LogInformation("Adding validation set entry to DB, {ValidationSetId} {PackageId} {PackageVersion}",
                                   packageValidationSet.ValidationTrackingId,
                                   packageValidationSet.PackageId,
                                   packageValidationSet.PackageNormalizedVersion);
            foreach (var validation in packageValidationSet.PackageValidations)
            {
                _validationContext.PackageValidations.Add(validation);
            }
            _validationContext.PackageValidationSets.Add(packageValidationSet);
            await _validationContext.SaveChangesAsync();

            return(await GetValidationSetAsync(packageValidationSet.ValidationTrackingId));
        }
        private async Task MarkRevalidationsAsCompletedAsync(IReadOnlyList <PackageRevalidation> revalidations)
        {
            try
            {
                foreach (var revalidation in revalidations)
                {
                    _logger.LogInformation(
                        "Marking package {PackageId} {PackageNormalizedVersion} revalidation as completed as the package is unavailable or the package is already repository signed...",
                        revalidation.PackageId,
                        revalidation.PackageNormalizedVersion);

                    revalidation.Completed = true;
                }

                await _validationContext.SaveChangesAsync();

                foreach (var revalidation in revalidations)
                {
                    _logger.LogInformation(
                        "Marked package {PackageId} {PackageNormalizedVersion} revalidation as completed",
                        revalidation.PackageId,
                        revalidation.PackageNormalizedVersion);

                    _telemetry.TrackPackageRevalidationMarkedAsCompleted(revalidation.PackageId, revalidation.PackageNormalizedVersion);
                }
            }
            catch (DbUpdateConcurrencyException e)
            {
                _logger.LogError(
                    0,
                    e,
                    "Failed to mark package revalidations as completed. " +
                    $"These revalidations will be marked as completed on the next iteration of {nameof(NextAsync)}...");
            }
        }
Esempio n. 5
0
        public async Task <int> RemovePackageRevalidationsAsync(int max)
        {
            var revalidations = await _context.PackageRevalidations
                                .Take(max)
                                .ToListAsync();

            if (revalidations.Any())
            {
                foreach (var revalidation in revalidations)
                {
                    _context.PackageRevalidations.Remove(revalidation);
                }

                await _context.SaveChangesAsync();
            }

            return(revalidations.Count);
        }
Esempio n. 6
0
        public async Task <AddStatusResult> AddStatusAsync(ValidatorStatus status)
        {
            if (status.ValidatorName != _validatorName)
            {
                throw new ArgumentException(
                          $"Expected validator name '{_validatorName}', actual: '{status.ValidatorName}'",
                          nameof(status));
            }

            _validationContext.ValidatorStatuses.Add(status);

            try
            {
                await _validationContext.SaveChangesAsync();

                return(AddStatusResult.Success);
            }
            catch (DbUpdateException e) when(e.IsUniqueConstraintViolationException())
            {
                return(AddStatusResult.StatusAlreadyExists);
            }
        }
        public async Task PromoteSignaturesAsync()
        {
            using (_telemetry.TrackPromoteSignaturesDuration())
            {
                var promotableSignatures = await FindPromotableSignaturesAsync();

                if (!promotableSignatures.Any())
                {
                    return;
                }

                foreach (var signature in promotableSignatures)
                {
                    _logger.LogInformation(
                        $"Promoting signature {{SignatureKey}} for package {{PackageKey}} to status {nameof(PackageSignatureStatus.Valid)}",
                        signature.Key,
                        signature.PackageKey);

                    signature.Status = PackageSignatureStatus.Valid;
                }

                await _context.SaveChangesAsync();
            }
        }
Esempio n. 8
0
        private async Task MarkAsCompleted(PackageRevalidation revalidation)
        {
            _logger.LogInformation(
                "Marking package revalidation as completed as it has a repository signature or is deleted for {PackageId} {PackageNormalizedVersion}",
                revalidation.PackageId,
                revalidation.PackageNormalizedVersion);

            try
            {
                revalidation.Completed = true;

                await _validationContext.SaveChangesAsync();

                _telemetry.TrackPackageRevalidationMarkedAsCompleted(revalidation.PackageId, revalidation.PackageNormalizedVersion);
            }
            catch (DbUpdateConcurrencyException)
            {
                // Swallow concurrency exceptions. The package will be marked as completed
                // on the next iteration of "NextOrNullAsync".
            }
        }