Beispiel #1
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;
        }
Beispiel #2
0
        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?
        }