Exemple #1
0
 public Task StartValidationProcessAsync(NuGetPackage package, string[] validators)
 {
     return(StartValidationProcessAsync(
                package,
                validators,
                Guid.NewGuid()));
 }
Exemple #2
0
        /// <summary>
        /// Azure Queues have a max message length of 65536 bytes.
        /// This method truncates potentially long fields so that a serialized representation
        /// of the package falls within that boundary.
        /// </summary>
        /// <param name="package">The package to truncate</param>
        /// <returns>Truncated package</returns>
        public static NuGetPackage TruncateForAzureQueue(this NuGetPackage package)
        {
            // Clone the package
            var clone = JsonConvert.DeserializeObject <NuGetPackage>(
                JsonConvert.SerializeObject(package));

            // Truncate long properties (https://github.com/NuGet/NuGet.Jobs/pull/54/files/228105a40129c076afc9b9e21551ffadef315f92#r70679869)
            clone.Description  = Truncated;
            clone.ReleaseNotes = Truncated;
            clone.Summary      = Truncated;
            clone.Tags         = Truncated;

            return(clone);
        }
Exemple #3
0
        public async Task StartValidationProcessAsync(NuGetPackage package, string[] validators, Guid validationId)
        {
            var packageId      = package.Id;
            var packageVersion = package.GetVersion();
            var created        = DateTimeOffset.UtcNow;

            _logger.LogInformation(
                $"Starting validation process for validation {{{TraceConstant.ValidationId}}} " +
                $"- package {{{TraceConstant.PackageId}}} " +
                $"v. {{{TraceConstant.PackageVersion}}}...",
                validationId,
                packageId,
                packageVersion);

            // Write a tracking entity
            await _packageValidationTable.StoreAsync(new PackageValidationEntity
            {
                ValidationId        = validationId,
                PackageId           = packageId,
                PackageVersion      = packageVersion,
                RequestedValidators = string.Join(";", validators.OrderBy(v => v)),
                CompletedValidators = string.Empty,
                Created             = created
            });

            // Enqueue validations
            foreach (var validator in validators)
            {
                var message = new PackageValidationMessage
                {
                    ValidationId   = validationId,
                    PackageId      = packageId,
                    PackageVersion = packageVersion,
                    Package        = package
                };

                await _packageValidationQueue.EnqueueAsync(validator, message);
            }

            // Write audit entry so we can get all the nitty-gritty details on our validation process
            try
            {
                await _packageValidationAuditor.StartAuditAsync(validationId, validators, created, packageId, packageVersion, package);
            }
            catch (Exception ex)
            {
                var logMessage = $"Error while starting validation process for validation {validationId} - package {packageId} {packageVersion}: {ex.Message} {ex.StackTrace}";

                _logger.LogError(TraceEvent.StartValidationAuditFailed, ex,
                                 $"Error while starting validation process for validation {{{TraceConstant.ValidationId}}} " +
                                 $"- package {{{TraceConstant.PackageId}}} " +
                                 $"v. {{{TraceConstant.PackageVersion}}}",
                                 validationId,
                                 packageId,
                                 packageVersion);

                await _notificationService.SendNotificationAsync(
                    "exception",
                    "Error while starting validation process for validation",
                    logMessage);

                throw;
            }

            _logger.LogInformation($"Started validation process for validation {{{TraceConstant.ValidationId}}} " +
                                   $"- package {{{TraceConstant.PackageId}}} " +
                                   $"v. {{{TraceConstant.PackageVersion}}}",
                                   validationId,
                                   packageId,
                                   packageVersion);
        }
        public async Task StartAuditAsync(Guid validationId, string[] validators, DateTimeOffset started, string packageId, string packageVersion, NuGetPackage package)
        {
            _logger.LogInformation("Start writing Start PackageValidationAudit for " +
                                   $"validation {{{TraceConstant.ValidationId}}} " +
                                   $"- package {{{TraceConstant.PackageId}}} " +
                                   $"v. {{{TraceConstant.PackageVersion}}}...",
                                   validationId,
                                   package.Id,
                                   packageVersion);

            var packageValidationAudit = new PackageValidationAudit();

            packageValidationAudit.ValidationId   = validationId;
            packageValidationAudit.PackageId      = packageId;
            packageValidationAudit.PackageVersion = packageVersion;
            packageValidationAudit.Package        = package;
            packageValidationAudit.Started        = started;
            packageValidationAudit.Validators     = validators;

            await StoreAuditAsync(
                validationId,
                packageValidationAudit.PackageId,
                packageValidationAudit.PackageVersion,
                _ => packageValidationAudit,
                uploadAccessCondition : AccessCondition.GenerateIfNoneMatchCondition("*"));

            _logger.LogInformation("Finished writing Start PackageValidationAudit for " +
                                   $"validation {{{TraceConstant.ValidationId}}} " +
                                   $"- package {{{TraceConstant.PackageId}}} " +
                                   $"v. {{{TraceConstant.PackageVersion}}}.",
                                   validationId,
                                   package.Id,
                                   packageVersion);
        }
Exemple #5
0
 public static string GetVersion(this NuGetPackage package)
 {
     return(package.NormalizedVersion ?? package.Version);
 }