Skip to content

Commit

Permalink
Merge remote-tracking branch 'devdiv/release-6.2.x-MSRC' into release…
Browse files Browse the repository at this point in the history
…-6.2.x
  • Loading branch information
zivkan committed Jun 14, 2022
2 parents e513dc5 + 4be14ee commit ec6e62a
Show file tree
Hide file tree
Showing 18 changed files with 701 additions and 50 deletions.
2 changes: 1 addition & 1 deletion build/config.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<!-- when changing any of the NuGetVersion props below, run tools-local\ship-public-apis -->
<MajorNuGetVersion Condition="'$(MajorNuGetVersion)' == ''">6</MajorNuGetVersion>
<MinorNuGetVersion Condition="'$(MinorNuGetVersion)' == ''">2</MinorNuGetVersion>
<PatchNuGetVersion Condition="'$(PatchNuGetVersion)' == ''">0</PatchNuGetVersion>
<PatchNuGetVersion Condition="'$(PatchNuGetVersion)' == ''">1</PatchNuGetVersion>
<SemanticVersion Condition=" '$(SemanticVersion)' == '' ">$(MajorNuGetVersion).$(MinorNuGetVersion).$(PatchNuGetVersion)</SemanticVersion>

<!-- ** Change for each new preview/rc -->
Expand Down
32 changes: 26 additions & 6 deletions scripts/cibuild/ConfigureVstsBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ Function Set-RtmLabel {
Write-Host "##vso[task.setvariable variable=RtmLabel;]$label"
}

Function Get-LocBranchExists {
param(
[Parameter(Mandatory = $true)]
[string]$branchName
)

Write-Host "Looking for branch '$branchName' in NuGet.Build.Localization"
$lsRemoteOpts = 'ls-remote', 'origin', $branchName
$branchExists = & git -C $NuGetLocalization $lsRemoteOpts
return $branchExists
}

$isRTMBuild = [boolean]::Parse($BuildRTM)

Set-RtmLabel -isRTMBuild $isRTMBuild
Expand All @@ -98,17 +110,25 @@ $NuGetLocalization = Join-Path $Submodules NuGet.Build.Localization -Resolve

# Check if there is a localization branch associated with this branch repo
$currentNuGetBranch = $env:BUILD_SOURCEBRANCHNAME
$lsRemoteOpts = 'ls-remote', 'origin', $currentNuGetBranch
Write-Host "Looking for branch '$currentNuGetBranch' in NuGet.Build.Localization"
$lsResult = & git -C $NuGetLocalization $lsRemoteOpts

if ($lsResult)
if (Get-LocBranchExists $currentNuGetBranch)
{
$NuGetLocalizationRepoBranch = $currentNuGetBranch
}
else
{
$NuGetLocalizationRepoBranch = 'dev'
if ($currentNuGetBranch -like "*-MSRC") {
$currentNuGetBranch = $currentNuGetBranch -replace "-MSRC$", ""
if (Get-LocBranchExists $currentNuGetBranch) {
$NuGetLocalizationRepoBranch = $currentNuGetBranch
}
else
{
$NuGetLocalizationRepoBranch = "dev"
}
}
else {
$NuGetLocalizationRepoBranch = 'dev'
}
}
Write-Host "NuGet.Build.Localization Branch: $NuGetLocalizationRepoBranch"

Expand Down
18 changes: 1 addition & 17 deletions src/NuGet.Clients/NuGet.CommandLine/Commands/SetApiKeyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ public override void ExecuteCommand()
//Frist argument should be the ApiKey
string apiKey = Arguments[0];

bool setSymbolServerKey = false;

//If the user passed a source use it for the gallery location
string source;
if (String.IsNullOrEmpty(Source))
{
source = NuGetConstants.DefaultGalleryServerUrl;
// If no source was specified, set the default symbol server key to be the same
setSymbolServerKey = true;
}
else
{
Expand All @@ -45,19 +41,7 @@ public override void ExecuteCommand()

string sourceName = CommandLineUtility.GetSourceDisplayName(source);

// Setup the symbol server key
if (setSymbolServerKey)
{
SettingsUtility.SetEncryptedValueForAddItem(Settings, ConfigurationConstants.ApiKeys, NuGetConstants.DefaultSymbolServerUrl, apiKey);
Console.WriteLine(LocalizedResourceManager.GetString("SetApiKeyCommandDefaultApiKeysSaved"),
apiKey,
sourceName,
CommandLineUtility.GetSourceDisplayName(NuGetConstants.DefaultSymbolServerUrl));
}
else
{
Console.WriteLine(LocalizedResourceManager.GetString("SetApiKeyCommandApiKeySaved"), apiKey, sourceName);
}
Console.WriteLine(LocalizedResourceManager.GetString("SetApiKeyCommandApiKeySaved"), apiKey, sourceName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ public static void ValidateSource(string source)

public static string GetSourceDisplayName(string source)
{
if (String.IsNullOrEmpty(source) || source.Equals(NuGetConstants.DefaultGalleryServerUrl, StringComparison.OrdinalIgnoreCase))
if (string.IsNullOrEmpty(source) || source.Equals(NuGetConstants.DefaultGalleryServerUrl, StringComparison.OrdinalIgnoreCase))
{
return LocalizedResourceManager.GetString("LiveFeed") + " (" + NuGetConstants.DefaultGalleryServerUrl + ")";
}
if (source.Equals(NuGetConstants.DefaultSymbolServerUrl, StringComparison.OrdinalIgnoreCase))
{
return LocalizedResourceManager.GetString("DefaultSymbolServer") + " (" + NuGetConstants.DefaultSymbolServerUrl + ")";
}

return "'" + source + "'";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public static async Task Run(
await packageUpdateResource.Delete(
packageId,
packageVersion,
endpoint => apiKey ?? CommandRunnerUtility.GetApiKey(settings, endpoint, source, defaultApiKey: null, isSymbolApiKey: false),
endpoint => apiKey ?? CommandRunnerUtility.GetApiKey(settings, endpoint, source),
desc => nonInteractive || confirmFunc(desc),
noServiceEndpoint,
logger);
Expand Down
4 changes: 2 additions & 2 deletions src/NuGet.Core/NuGet.Commands/CommandRunners/PushRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ await packageUpdateResource.Push(
symbolSource,
timeoutSeconds,
disableBuffering,
endpoint => apiKey ?? CommandRunnerUtility.GetApiKey(settings, endpoint, source, defaultApiKey: null, isSymbolApiKey: false),
symbolsEndpoint => symbolApiKey ?? CommandRunnerUtility.GetApiKey(settings, symbolsEndpoint, symbolSource, apiKey, isSymbolApiKey: true),
endpoint => apiKey ?? CommandRunnerUtility.GetApiKey(settings, endpoint, source),
symbolsEndpoint => symbolApiKey ?? CommandRunnerUtility.GetApiKey(settings, symbolsEndpoint, symbolSource),
noServiceEndpoint,
skipDuplicate,
symbolPackageUpdateResource,
Expand Down
13 changes: 7 additions & 6 deletions src/NuGet.Core/NuGet.Commands/Utility/CommandRunnerUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Configuration;
using NuGet.Protocol;
using NuGet.Protocol.Core.Types;
Expand Down Expand Up @@ -45,7 +46,7 @@ public static string ResolveSymbolSource(IPackageSourceProvider sourceProvider,
return symbolSource;
}

public static string GetApiKey(ISettings settings, string endpoint, string source, string defaultApiKey, bool isSymbolApiKey)
public static string GetApiKey(ISettings settings, string endpoint, string source)
{
// try searching API key by endpoint first
// needed to support config key mappings like 'https://www.nuget.org/api/v2/package'
Expand All @@ -56,15 +57,15 @@ public static string GetApiKey(ISettings settings, string endpoint, string sourc

// fallback for a case of nuget.org source
// try to retrieve an api key mapped to a default "gallery" url
if (apiKey == null
&& source.IndexOf(NuGetConstants.NuGetHostName, StringComparison.OrdinalIgnoreCase) >= 0)
if (apiKey == null &&
UriUtility.IsNuGetOrg(source))
{
var defaultConfigKey = isSymbolApiKey ? NuGetConstants.DefaultSymbolServerUrl : NuGetConstants.DefaultGalleryServerUrl;
var defaultConfigKey = NuGetConstants.DefaultGalleryServerUrl;
apiKey = SettingsUtility.GetDecryptedValueForAddItem(settings, ConfigurationConstants.ApiKeys, defaultConfigKey);
}

// return an API key when found or the default one
return apiKey ?? defaultApiKey;
// return an API key when found or null when not found
return apiKey;
}

public static async Task<PackageUpdateResource> GetPackageUpdateResource(IPackageSourceProvider sourceProvider, string source)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static NuGet.Common.UriUtility.IsNuGetOrg(string source) -> bool
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static NuGet.Common.UriUtility.IsNuGetOrg(string source) -> bool
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
static NuGet.Common.UriUtility.IsNuGetOrg(string source) -> bool
33 changes: 33 additions & 0 deletions src/NuGet.Core/NuGet.Common/UriUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public static class UriUtility
{
private const string FilePrefix = "file://";

private static bool IsHttpUrl(Uri uri)
{
return uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps;
}

/// <summary>
/// Same as "new Uri" except that it can handle UNIX style paths that start with '/'
/// </summary>
Expand Down Expand Up @@ -132,5 +137,33 @@ public static string GetAbsolutePath(string rootDirectory, string path)
// Absolute path or non-http url.
return local;
}

/// <summary>
/// Determines if a package source url points to nuget.org
/// </summary>
/// <param name="source">Package source url</param>
/// <returns>True if the source is HTTP and has a *.nuget.org or nuget.org host otherwise false</returns>
public static bool IsNuGetOrg(string source)
{
if (string.IsNullOrWhiteSpace(source))
{
return false;
}

var uri = TryCreateSourceUri(source, UriKind.Absolute);

if (uri == null || !IsHttpUrl(uri))
{
return false;
}

if (StringComparer.OrdinalIgnoreCase.Equals(uri.Host, "nuget.org")
|| uri.Host.EndsWith(".nuget.org", StringComparison.OrdinalIgnoreCase))
{
return true;
}

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static class NuGetConstants
/// nuget.exe setApiKey XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
/// </remarks>
public static readonly string DefaultGalleryServerUrl = "https://www.nuget.org";
public static readonly string DefaultSymbolServerUrl = "https://nuget.smbsrc.net/";

public static readonly string ReadmeFileName = "readme.txt";
public static readonly string NuGetSolutionSettingsFolder = ".nuget";
Expand Down
1 change: 0 additions & 1 deletion src/NuGet.Core/NuGet.Configuration/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ static readonly NuGet.Configuration.ConfigurationConstants.ValidAuthenticationTy
static readonly NuGet.Configuration.ConfigurationConstants.ValueAttribute -> string
static readonly NuGet.Configuration.NuGetConstants.DefaultConfigContent -> string
static readonly NuGet.Configuration.NuGetConstants.DefaultGalleryServerUrl -> string
static readonly NuGet.Configuration.NuGetConstants.DefaultSymbolServerUrl -> string
static readonly NuGet.Configuration.NuGetConstants.FeedName -> string
static readonly NuGet.Configuration.NuGetConstants.ManifestExtension -> string
static readonly NuGet.Configuration.NuGetConstants.ManifestSymbolsExtension -> string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,7 @@ private static string GetSourceDisplayName(string source)
{
return Strings.LiveFeed + " (" + NuGetConstants.DefaultGalleryServerUrl + ")";
}
if (source.Equals(NuGetConstants.DefaultSymbolServerUrl, StringComparison.OrdinalIgnoreCase))
{
return Strings.DefaultSymbolServer + " (" + NuGetConstants.DefaultSymbolServerUrl + ")";
}

return "'" + source + "'";
}

Expand Down
Loading

0 comments on commit ec6e62a

Please sign in to comment.