예제 #1
0
        public MarkClean(
            IDictionary <string, string> jobArgsDictionary,
            ILogger <MarkClean> logger,
            CloudStorageAccount cloudStorageAccount,
            string containerName,
            NuGetV2Feed feed,
            PackageValidationAuditor packageValidationAuditor,
            string galleryBaseAddress)
        {
            _logger = logger;
            _cloudStorageAccount = cloudStorageAccount;
            _containerName       = containerName;

            PackageId      = JobConfigurationManager.GetArgument(jobArgsDictionary, CommandLineArguments.PackageId);
            PackageId      = HttpUtility.UrlDecode(PackageId);
            PackageVersion = JobConfigurationManager.GetArgument(jobArgsDictionary, CommandLineArguments.PackageVersion);
            PackageVersion = HttpUtility.UrlDecode(PackageVersion);
            var validationIdStr = JobConfigurationManager.GetArgument(jobArgsDictionary, CommandLineArguments.ValidationId);

            _validationId             = Guid.Parse(validationIdStr);
            _comment                  = JobConfigurationManager.GetArgument(jobArgsDictionary, CommandLineArguments.Comment);
            _alias                    = JobConfigurationManager.GetArgument(jobArgsDictionary, CommandLineArguments.Alias);
            _feed                     = feed;
            _packageValidationAuditor = packageValidationAuditor;
            _galleryBaseAddress       = galleryBaseAddress;
        }
예제 #2
0
        private static async Task <NuGetPackage> GetPackage(NuGetV2Feed feed, Uri url, bool includeDownloadUrl)
        {
            var packages = await feed.GetPackagesAsync(
                url,
                includeDownloadUrl,
                continuationsToFollow : 0);

            return(packages.FirstOrDefault());
        }
예제 #3
0
        public static async Task <NuGetPackage> GetPackage(
            string galleryBaseAddress,
            NuGetV2Feed feed,
            string packageId,
            string packageVersion,
            bool includeDownloadUrl)
        {
            // We'll try the normalized version first, then fall back to non-normalized
            // one if it fails.
            var url     = GetNormalizedPackageUrl(galleryBaseAddress, packageId, packageVersion);
            var package = await GetPackage(feed, url, includeDownloadUrl);

            if (package != null)
            {
                return(package);
            }
            url = GetPackageUrl(galleryBaseAddress, packageId, packageVersion);
            return(await GetPackage(feed, url, includeDownloadUrl));
        }
예제 #4
0
        public Rescan(
            IDictionary <string, string> jobArgsDictionary,
            ILogger <Rescan> logger,
            CloudStorageAccount cloudStorageAccount,
            string containerName,
            NuGetV2Feed feed,
            PackageValidationService packageValidationService,
            string galleryBaseAddress)
        {
            _logger = logger;
            _feed   = feed;

            _containerName       = containerName;
            _cloudStorageAccount = cloudStorageAccount;

            PackageId                 = JobConfigurationManager.GetArgument(jobArgsDictionary, CommandLineArguments.PackageId);
            PackageId                 = HttpUtility.UrlDecode(PackageId);
            PackageVersion            = JobConfigurationManager.GetArgument(jobArgsDictionary, CommandLineArguments.PackageVersion);
            PackageVersion            = HttpUtility.UrlDecode(PackageVersion);
            _packageValidationService = packageValidationService;
            _galleryBaseAddress       = galleryBaseAddress;
        }
예제 #5
0
파일: Job.cs 프로젝트: edyoung/NuGet.Jobs
        private async Task RunOrchestrateAsync()
        {
            Logger.LogInformation($"{{{TraceConstant.EventName}}}: Attempting orchestration",
                                  "OrchestrationAttempt");

            // Retrieve cursor (last created / last edited)
            var cursor = new PackageValidationOrchestrationCursor(_cloudStorageAccount, _containerName + "-audit", "cursor.json", LoggerFactory);
            await cursor.LoadAsync();

            // Setup package validation service
            var packageValidationService = new PackageValidationService(_cloudStorageAccount, _containerName, LoggerFactory);

            // Get reference timestamps
            var referenceLastCreated = cursor.LastCreated ?? DateTimeOffset.UtcNow.AddMinutes(-15);
            var referenceLastEdited  = cursor.LastEdited ?? DateTimeOffset.UtcNow.AddMinutes(-15);

            // Fetch newly added / edited packages and enqueue validations
            using (var client = new HttpClient())
            {
                var packages = new HashSet <NuGetPackage>(new NuGetV2PackageEqualityComparer());

                var feed = new NuGetV2Feed(client, LoggerFactory.CreateLogger <NuGetV2Feed>());

                var createdPackagesUrl = MakePackageQueryUrl(_galleryBaseAddress, "Created", referenceLastCreated);
                Logger.LogInformation("Querying packages created since {StartTime}, URL: {QueryUrl}", referenceLastCreated, createdPackagesUrl);
                var createdPackages = await feed.GetPackagesAsync(
                    createdPackagesUrl,
                    includeDownloadUrl : false,
                    continuationsToFollow : 0);

                foreach (var package in createdPackages)
                {
                    packages.Add(package);

                    if (package.Created > cursor.LastCreated || cursor.LastCreated == null)
                    {
                        cursor.LastCreated = package.Created;
                    }
                }

                // todo: do we also want to check edited packages again?
                //var editedPackagesUrl = MakePackageQueryUrl(_galleryBaseAddress, "LastEdited", referenceLastEdited);
                //var editedPackages = await feed.GetPackagesAsync(editedPackagesUrl, followContinuations: true);
                //foreach (var package in editedPackages)
                //{
                //    //packages.Add(package);

                //    if (package.LastEdited > cursor.LastEdited || cursor.LastEdited == null)
                //    {
                //        cursor.LastEdited = package.LastEdited;
                //    }
                //}

                // Start the validation process for each package
                foreach (var package in packages)
                {
                    await packageValidationService.StartValidationProcessAsync(package, _requestValidationTasks);
                }

                // Store cursor
                await cursor.SaveAsync();
            }

            // TODO: check for validations that have never been executed?
        }