From 022f6c73529bda97931427d7699560f39473be5d Mon Sep 17 00:00:00 2001 From: cmanu Date: Mon, 25 Mar 2019 14:09:06 -0700 Subject: [PATCH 1/3] Change the name of the Validation.Symbols to Validation.Symbols.Job. (#733) --- NuGet.Jobs.sln | 2 +- build.ps1 | 2 +- .../Scripts/Validation.SymbolValidation.cmd | 2 +- ...idation.Symbols.csproj => Validation.Symbols.Job.csproj} | 6 ++++-- ...idation.Symbols.nuspec => Validation.Symbols.Job.nuspec} | 2 +- .../Validation.Symbols.Tests.csproj | 4 ++-- 6 files changed, 10 insertions(+), 8 deletions(-) rename src/Validation.Symbols/{Validation.Symbols.csproj => Validation.Symbols.Job.csproj} (97%) rename src/Validation.Symbols/{Validation.Symbols.nuspec => Validation.Symbols.Job.nuspec} (94%) diff --git a/NuGet.Jobs.sln b/NuGet.Jobs.sln index 62d27a47b..143daff15 100644 --- a/NuGet.Jobs.sln +++ b/NuGet.Jobs.sln @@ -133,7 +133,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Monitoring.RebootSearchInst EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Monitoring.RebootSearchInstance.Tests", "tests\Monitoring.RebootSearchInstance.Tests\Monitoring.RebootSearchInstance.Tests.csproj", "{21C0A0EE-8696-4013-950F-D6495D0C6E40}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.Symbols", "src\Validation.Symbols\Validation.Symbols.csproj", "{2DD07A73-8C88-4429-BB24-C2813586EF92}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.Symbols.Job", "src\Validation.Symbols\Validation.Symbols.Job.csproj", "{2DD07A73-8C88-4429-BB24-C2813586EF92}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Validation.Symbols.Tests", "tests\Validation.Symbols.Tests\Validation.Symbols.Tests.csproj", "{640D29AB-4D1B-4FC7-AE67-AD12EE5AC503}" EndProject diff --git a/build.ps1 b/build.ps1 index 714fcad3e..3be06f35d 100644 --- a/build.ps1 +++ b/build.ps1 @@ -162,7 +162,7 @@ Invoke-BuildStep 'Creating artifacts' { "src/Monitoring.RebootSearchInstance/Monitoring.RebootSearchInstance.csproj", ` "src/StatusAggregator/StatusAggregator.csproj", ` "src/Validation.Symbols.Core/Validation.Symbols.Core.csproj", ` - "src/Validation.Symbols/Validation.Symbols.csproj" + "src/Validation.Symbols/Validation.Symbols.Job.csproj" Foreach ($Project in $NuspecProjects) { New-Package (Join-Path $PSScriptRoot "$Project") -Configuration $Configuration -BuildNumber $BuildNumber -Version $SemanticVersion -Branch $Branch -MSBuildVersion "$msBuildVersion" diff --git a/src/Validation.Symbols/Scripts/Validation.SymbolValidation.cmd b/src/Validation.Symbols/Scripts/Validation.SymbolValidation.cmd index 45ad9e4ec..904d9ec58 100644 --- a/src/Validation.Symbols/Scripts/Validation.SymbolValidation.cmd +++ b/src/Validation.Symbols/Scripts/Validation.SymbolValidation.cmd @@ -7,7 +7,7 @@ echo "Starting job - #{Jobs.Validation.Symbols.Title}" title #{Jobs.Validation.Symbols.Title} -start /w Validation.Symbols.exe ^ +start /w Validation.Symbols.Job.exe ^ -Configuration #{Jobs.validation.SymbolValidation.Configuration} ^ -InstrumentationKey "#{Jobs.validation.SymbolValidation.InstrumentationKey}" diff --git a/src/Validation.Symbols/Validation.Symbols.csproj b/src/Validation.Symbols/Validation.Symbols.Job.csproj similarity index 97% rename from src/Validation.Symbols/Validation.Symbols.csproj rename to src/Validation.Symbols/Validation.Symbols.Job.csproj index f5be78935..745f47df6 100644 --- a/src/Validation.Symbols/Validation.Symbols.csproj +++ b/src/Validation.Symbols/Validation.Symbols.Job.csproj @@ -7,7 +7,7 @@ {2DD07A73-8C88-4429-BB24-C2813586EF92} Exe Validation.Symbols - Validation.Symbols + Validation.Symbols.Job v4.6.2 512 true @@ -65,7 +65,9 @@ - + + Designer + diff --git a/src/Validation.Symbols/Validation.Symbols.nuspec b/src/Validation.Symbols/Validation.Symbols.Job.nuspec similarity index 94% rename from src/Validation.Symbols/Validation.Symbols.nuspec rename to src/Validation.Symbols/Validation.Symbols.Job.nuspec index 0915ba152..b37bb2b69 100644 --- a/src/Validation.Symbols/Validation.Symbols.nuspec +++ b/src/Validation.Symbols/Validation.Symbols.Job.nuspec @@ -1,7 +1,7 @@ - Validation.Symbols + Validation.Symbols.Job $version$ Validation.Symbols .NET Foundation diff --git a/tests/Validation.Symbols.Tests/Validation.Symbols.Tests.csproj b/tests/Validation.Symbols.Tests/Validation.Symbols.Tests.csproj index 4c004caaa..e12ab47bc 100644 --- a/tests/Validation.Symbols.Tests/Validation.Symbols.Tests.csproj +++ b/tests/Validation.Symbols.Tests/Validation.Symbols.Tests.csproj @@ -77,9 +77,9 @@ {17510a22-176f-4e96-a867-e79f1b54f54f} Validation.Symbols.Core - + {2dd07a73-8c88-4429-bb24-c2813586ef92} - Validation.Symbols + Validation.Symbols.Job From 797adf3b551d69af719f42e71acc1db865700784 Mon Sep 17 00:00:00 2001 From: Svetlana Kofman Date: Mon, 25 Mar 2019 22:00:26 -0700 Subject: [PATCH 2/3] Embed packagetranslation.json in Assembly (#732) --- .../ImportAzureCdnStatisticsJob.cs | 2 +- .../PackageTranslator.cs | 18 ++++++++++++------ .../Properties/AssemblyInfo.cs | 9 ++++++++- .../Stats.ImportAzureCdnStatistics.csproj | 6 +++--- .../LogFileProcessorFacts.cs | 3 +-- .../PackageStatisticsParserFacts.cs | 2 +- .../PackageTranslatorFacts.cs | 2 +- .../TestablePackageTranslator.cs | 17 +++++++++++++++++ ...Tests.Stats.ImportAzureCdnStatistics.csproj | 7 ++++--- 9 files changed, 48 insertions(+), 18 deletions(-) create mode 100644 tests/Tests.Stats.ImportAzureCdnStatistics/TestablePackageTranslator.cs diff --git a/src/Stats.ImportAzureCdnStatistics/ImportAzureCdnStatisticsJob.cs b/src/Stats.ImportAzureCdnStatistics/ImportAzureCdnStatisticsJob.cs index e84411e76..5f762f849 100644 --- a/src/Stats.ImportAzureCdnStatistics/ImportAzureCdnStatisticsJob.cs +++ b/src/Stats.ImportAzureCdnStatistics/ImportAzureCdnStatisticsJob.cs @@ -81,7 +81,7 @@ public override async Task Run() var leasedLogFiles = await _blobLeaseManager.LeaseNextLogFilesToBeProcessedAsync(prefix, alreadyAggregatedLogFiles); foreach (var leasedLogFile in leasedLogFiles) { - var packageTranslator = new PackageTranslator("packagetranslations.json"); + var packageTranslator = new PackageTranslator(); var packageStatisticsParser = new PackageStatisticsParser(packageTranslator, LoggerFactory); await logProcessor.ProcessLogFileAsync(leasedLogFile, packageStatisticsParser, _configuration.AggregatesOnly); diff --git a/src/Stats.ImportAzureCdnStatistics/PackageTranslator.cs b/src/Stats.ImportAzureCdnStatistics/PackageTranslator.cs index 595f76bec..e38533cd9 100644 --- a/src/Stats.ImportAzureCdnStatistics/PackageTranslator.cs +++ b/src/Stats.ImportAzureCdnStatistics/PackageTranslator.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reflection; using System.Text.RegularExpressions; using Newtonsoft.Json.Linq; @@ -14,16 +15,16 @@ public class PackageTranslator private readonly Dictionary> _packageTranslations = new Dictionary>(StringComparer.OrdinalIgnoreCase); - public PackageTranslator(string packageTranslationsJsonPath) + public PackageTranslator() { - if (!File.Exists(packageTranslationsJsonPath)) + JObject packageTranslationsJson; + + using (var stream = GetPackageTranslationsStream()) + using (var reader = new StreamReader(stream)) { - throw new FileNotFoundException("Could not find file.", packageTranslationsJsonPath); + packageTranslationsJson = JObject.Parse(reader.ReadToEnd()); } - var packageTranslationsJson = JObject.Parse( - File.ReadAllText(packageTranslationsJsonPath)); - var packageTranslationsArray = (JArray) packageTranslationsJson["translations"]; foreach (var packageTranslationJson in packageTranslationsArray.Children()) { @@ -72,5 +73,10 @@ public bool TryTranslatePackageDefinition(PackageDefinition packageDefinition) return translateOccurred; } + + internal virtual Stream GetPackageTranslationsStream() + { + return Assembly.GetExecutingAssembly().GetManifestResourceStream("packagetranslations.json"); + } } } \ No newline at end of file diff --git a/src/Stats.ImportAzureCdnStatistics/Properties/AssemblyInfo.cs b/src/Stats.ImportAzureCdnStatistics/Properties/AssemblyInfo.cs index b586b021f..a6def1406 100644 --- a/src/Stats.ImportAzureCdnStatistics/Properties/AssemblyInfo.cs +++ b/src/Stats.ImportAzureCdnStatistics/Properties/AssemblyInfo.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("Stats.ImportAzureCdnStatistics")] @@ -15,4 +16,10 @@ [assembly: ComVisible(false)] [assembly: Guid("5b0d3ec6-4326-47a7-aee1-cc67d07d5c84")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.0.0.0")] + +#if SIGNED_BUILD +[assembly: InternalsVisibleTo("Tests.Stats.ImportAzureCdnStatistics, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")] +#else +[assembly: InternalsVisibleTo("Tests.Stats.ImportAzureCdnStatistics")] +#endif \ No newline at end of file diff --git a/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj b/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj index c27b0eae8..ca430c87d 100644 --- a/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj +++ b/src/Stats.ImportAzureCdnStatistics/Stats.ImportAzureCdnStatistics.csproj @@ -88,9 +88,9 @@ knownclients.yaml - - Always - + + packagetranslations.json + diff --git a/tests/Tests.Stats.ImportAzureCdnStatistics/LogFileProcessorFacts.cs b/tests/Tests.Stats.ImportAzureCdnStatistics/LogFileProcessorFacts.cs index 07efbe7a7..440b28504 100644 --- a/tests/Tests.Stats.ImportAzureCdnStatistics/LogFileProcessorFacts.cs +++ b/tests/Tests.Stats.ImportAzureCdnStatistics/LogFileProcessorFacts.cs @@ -20,8 +20,7 @@ public class LogFileProcessorFacts private static readonly Assembly _currentAssembly = typeof(LogFileProcessorFacts).Assembly; - private static readonly PackageTranslator _packageTranslator = - new PackageTranslator("packageTranslations.json"); + private static readonly PackageTranslator _packageTranslator = new PackageTranslator(); private static readonly IPackageStatisticsParser _packageStatisticsParser = new PackageStatisticsParser(_packageTranslator, new LoggerFactory()); diff --git a/tests/Tests.Stats.ImportAzureCdnStatistics/PackageStatisticsParserFacts.cs b/tests/Tests.Stats.ImportAzureCdnStatistics/PackageStatisticsParserFacts.cs index b184a11ba..1b7206dca 100644 --- a/tests/Tests.Stats.ImportAzureCdnStatistics/PackageStatisticsParserFacts.cs +++ b/tests/Tests.Stats.ImportAzureCdnStatistics/PackageStatisticsParserFacts.cs @@ -43,7 +43,7 @@ public void TranslatesPackagesCorrectly(string packageId, string packageVersion) // Arrange var logEntry = GetCdnLogEntry($"http://test.me/{packageId}.{packageVersion}.nupkg"); - var translator = new PackageTranslator("packagetranslations.json"); + var translator = new TestablePackageTranslator(); var statsParser = new PackageStatisticsParser(translator, new LoggerFactory()); // Act diff --git a/tests/Tests.Stats.ImportAzureCdnStatistics/PackageTranslatorFacts.cs b/tests/Tests.Stats.ImportAzureCdnStatistics/PackageTranslatorFacts.cs index 2fa5bebcb..f580c3bbe 100644 --- a/tests/Tests.Stats.ImportAzureCdnStatistics/PackageTranslatorFacts.cs +++ b/tests/Tests.Stats.ImportAzureCdnStatistics/PackageTranslatorFacts.cs @@ -10,7 +10,7 @@ public class PackageTranslatorFacts { private static PackageTranslator CreatePackageTranslator() { - return new PackageTranslator("packagetranslations.json"); + return new TestablePackageTranslator(); } [Fact] diff --git a/tests/Tests.Stats.ImportAzureCdnStatistics/TestablePackageTranslator.cs b/tests/Tests.Stats.ImportAzureCdnStatistics/TestablePackageTranslator.cs new file mode 100644 index 000000000..a31b57ee3 --- /dev/null +++ b/tests/Tests.Stats.ImportAzureCdnStatistics/TestablePackageTranslator.cs @@ -0,0 +1,17 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using Stats.ImportAzureCdnStatistics; +using System.IO; +using System.Reflection; + +namespace Tests.Stats.ImportAzureCdnStatistics +{ + public class TestablePackageTranslator : PackageTranslator + { + internal override Stream GetPackageTranslationsStream() + { + return Assembly.GetExecutingAssembly().GetManifestResourceStream("packagetranslations.json"); + } + } +} diff --git a/tests/Tests.Stats.ImportAzureCdnStatistics/Tests.Stats.ImportAzureCdnStatistics.csproj b/tests/Tests.Stats.ImportAzureCdnStatistics/Tests.Stats.ImportAzureCdnStatistics.csproj index f03d6fbca..ea10a18fc 100644 --- a/tests/Tests.Stats.ImportAzureCdnStatistics/Tests.Stats.ImportAzureCdnStatistics.csproj +++ b/tests/Tests.Stats.ImportAzureCdnStatistics/Tests.Stats.ImportAzureCdnStatistics.csproj @@ -54,6 +54,7 @@ + @@ -67,9 +68,9 @@ Always - - Always - + + packagetranslations.json + From 9c524adbcacb1aa727539d3adbe84eb57f658e1e Mon Sep 17 00:00:00 2001 From: Andrei Grigorev Date: Wed, 27 Mar 2019 14:42:03 -0700 Subject: [PATCH 3/3] Added HSTS header. Removed the 'X-Powered-By' header like Gallery does. (#735) --- src/NuGetCDNRedirect/Web.config | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/NuGetCDNRedirect/Web.config b/src/NuGetCDNRedirect/Web.config index b4dca096a..029859dd8 100644 --- a/src/NuGetCDNRedirect/Web.config +++ b/src/NuGetCDNRedirect/Web.config @@ -37,6 +37,12 @@ + + + + + +