Skip to content

Commit

Permalink
Add support for "nuget.exe push -SymbolsSource XXX -SymbolsApiKey YYY"
Browse files Browse the repository at this point in the history
  • Loading branch information
spadapet committed Jun 27, 2016
1 parent 1a28cd9 commit 18f258a
Show file tree
Hide file tree
Showing 12 changed files with 237 additions and 17 deletions.
8 changes: 8 additions & 0 deletions src/NuGet.Clients/NuGet.CommandLine/Commands/PushCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public class PushCommand : Command
[Option(typeof(NuGetCommand), "CommandApiKey")]
public string ApiKey { get; set; }

[Option(typeof(NuGetCommand), "PushCommandSymbolSourceDescription")]
public string SymbolSource { get; set; }

[Option(typeof(NuGetCommand), "SymbolApiKey")]
public string SymbolApiKey { get; set; }

[Option(typeof(NuGetCommand), "PushCommandTimeoutDescription")]
public int Timeout { get; set; }

Expand Down Expand Up @@ -44,6 +50,8 @@ await PushRunner.Run(
packagePath,
Source,
apiKeyValue,
SymbolSource,
SymbolApiKey,
Timeout,
DisableBuffering,
NoSymbols,
Expand Down
20 changes: 19 additions & 1 deletion src/NuGet.Clients/NuGet.CommandLine/NuGetCommand.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/NuGet.Clients/NuGet.CommandLine/NuGetCommand.resx
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,9 @@ nuget pack foo.nuspec -Version 2.1.0</value>
<value>Specifies the server URL. If not specified, nuget.org is used unless DefaultPushSource config value is set in the NuGet config file.</value>
<comment>Please don't localize "DefaultPushSource"</comment>
</data>
<data name="PushCommandSymbolSourceDescription" xml:space="preserve">
<value>Specifies the symbol server URL. If not specified, nuget.smbsrc.net is used when pushing to nuget.org.</value>
</data>
<data name="PushCommandTimeoutDescription" xml:space="preserve">
<value>Specifies the timeout for pushing to a server in seconds. Defaults to 300 seconds (5 minutes).</value>
</data>
Expand Down Expand Up @@ -441,6 +444,9 @@ nuget update -Self</value>
<data name="CommandApiKey" xml:space="preserve">
<value>The API key for the server.</value>
</data>
<data name="SymbolApiKey" xml:space="preserve">
<value>The API key for the symbol server.</value>
</data>
<data name="DefaultConfigDescription" xml:space="preserve">
<value>NuGet's default configuration is obtained by loading %AppData%\NuGet\NuGet.config, then loading any nuget.config or .nuget\nuget.config starting from root of drive and ending in current directory.</value>
<comment>Please don't localize "%AppData%\NuGet\NuGet.config", "nuget.config", ".nuget\nuget.config"</comment>
Expand Down Expand Up @@ -5243,7 +5249,7 @@ nuget update -Self</value>
<value>Disable buffering when pushing to an HTTP(S) server to decrease memory usage. Note that when this option is enabled, integrated windows authentication might not work.</value>
</data>
<data name="PushCommandNoSymbolsDescription" xml:space="preserve">
<value>If a symbols package exists, it will not be pushed to a symbols server.</value>
<value>If a symbols package exists, it will not be pushed to a symbol server.</value>
</data>
<data name="CommandFallbackSourceDescription" xml:space="preserve">
<value>A list of package sources to use as fallbacks for this command.</value>
Expand Down
14 changes: 14 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/PushCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public static void Register(CommandLineApplication app, Func<ILogger> getLogger)
Strings.Source_Description,
CommandOptionType.SingleValue);
var symbolSource = push.Option(
"-ss|--symbol-source <source>",
Strings.SymbolSource_Description,
CommandOptionType.SingleValue);
var timeout = push.Option(
"-t|--timeout <timeout>",
Strings.Push_Timeout_Description,
Expand All @@ -36,6 +41,11 @@ public static void Register(CommandLineApplication app, Func<ILogger> getLogger)
Strings.ApiKey_Description,
CommandOptionType.SingleValue);
var symbolApiKey = push.Option(
"-sk|--symbol-api-key <apiKey>",
Strings.SymbolApiKey_Description,
CommandOptionType.SingleValue);
var disableBuffering = push.Option(
"-d|--disable-buffering",
Strings.DisableBuffering_Description,
Expand All @@ -61,6 +71,8 @@ public static void Register(CommandLineApplication app, Func<ILogger> getLogger)
string packagePath = arguments.Values[0];
string sourcePath = source.Value();
string apiKeyValue = apikey.Value();
string symbolSourcePath = symbolSource.Value();
string symbolApiKeyValue = symbolApiKey.Value();
bool disableBufferingValue = disableBuffering.HasValue();
bool noSymbolsValue = noSymbols.HasValue();
int timeoutSeconds = 0;
Expand All @@ -80,6 +92,8 @@ await PushRunner.Run(
packagePath,
sourcePath,
apiKeyValue,
symbolSourcePath,
symbolApiKeyValue,
timeoutSeconds,
disableBufferingValue,
noSymbolsValue,
Expand Down
18 changes: 18 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -305,4 +305,10 @@
<data name="Serviceable_Description" xml:space="preserve">
<value>Sets the nuspec serviceable element to true.</value>
</data>
<data name="SymbolSource_Description" xml:space="preserve">
<value>Specifies the symbol server URL. If not specified, nuget.smbsrc.net is used when pushing to nuget.org.</value>
</data>
<data name="SymbolApiKey_Description" xml:space="preserve">
<value>The API key for the symbol server.</value>
</data>
</root>
18 changes: 13 additions & 5 deletions src/NuGet.Core/NuGet.Commands/PushRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ public static async Task Run(
string packagePath,
string source,
string apiKey,
string symbolSource,
string symbolApiKey,
int timeoutSeconds,
bool disableBuffering,
bool noSymbols,
ILogger logger)
{
source = CommandRunnerUtility.ResolveSource(sourceProvider, source);
symbolSource = CommandRunnerUtility.ResolveSymbolSource(sourceProvider, symbolSource);

if (timeoutSeconds == 0)
{
Expand All @@ -32,24 +35,29 @@ public static async Task Run(
PackageUpdateResource packageUpdateResource = await CommandRunnerUtility.GetPackageUpdateResource(sourceProvider, source);

// only push to SymbolSource when the actual package is being pushed to the official NuGet.org
string symbolsSource = string.Empty;

Uri sourceUri = packageUpdateResource.SourceUri;
if (!noSymbols && !sourceUri.IsFile && sourceUri.IsAbsoluteUri)
if (string.IsNullOrEmpty(symbolSource) && !noSymbols && !sourceUri.IsFile && sourceUri.IsAbsoluteUri)
{
if (sourceUri.Host.Equals(NuGetConstants.NuGetHostName, StringComparison.OrdinalIgnoreCase) // e.g. nuget.org
|| sourceUri.Host.EndsWith("." + NuGetConstants.NuGetHostName, StringComparison.OrdinalIgnoreCase)) // *.nuget.org, e.g. www.nuget.org
{
symbolsSource = NuGetConstants.DefaultSymbolServerUrl;
symbolSource = NuGetConstants.DefaultSymbolServerUrl;

if (string.IsNullOrEmpty(symbolApiKey))
{
// Use the nuget.org API key if it was given
symbolApiKey = apiKey;
}
}
}

await packageUpdateResource.Push(
packagePath,
symbolsSource,
symbolSource,
timeoutSeconds,
disableBuffering,
endpoint => CommandRunnerUtility.GetApiKey(settings, endpoint, apiKey),
symbolsEndpoint => CommandRunnerUtility.GetApiKey(settings, symbolsEndpoint, symbolApiKey),
logger);
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/NuGet.Core/NuGet.Commands/Utility/CommandRunnerUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ public static string ResolveSource(IPackageSourceProvider sourceProvider, string
return source;
}

public static string ResolveSymbolSource(IPackageSourceProvider sourceProvider, string symbolSource)
{
if (!string.IsNullOrEmpty(symbolSource))
{
symbolSource = sourceProvider.ResolveAndValidateSource(symbolSource);
}

return symbolSource;
}

public static string GetApiKey(ISettings settings, string source, string apiKey)
{
if (string.IsNullOrEmpty(apiKey))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ public Uri SourceUri

public async Task Push(
string packagePath,
string symbolsSource, // empty to not push symbols
string symbolSource, // empty to not push symbols
int timeoutInSecond,
bool disableBuffering,
Func<string, string> getApiKey,
Func<string, string> getSymbolApiKey,
ILogger log)
{
// TODO: Figure out how to hook this up with the HTTP request
Expand All @@ -59,10 +60,13 @@ public async Task Push(

await PushPackage(packagePath, _source, apiKey, requestTimeout, log, tokenSource.Token);

if (!string.IsNullOrEmpty(symbolsSource) && !IsFileSource())
// symbolSource is only set when:
// - The user specified it on the command line
// - The package source is nuget.org and the default symbol source is used
if (!string.IsNullOrEmpty(symbolSource))
{
string symbolsApiKey = getApiKey(symbolsSource);
await PushSymbols(packagePath, symbolsSource, symbolsApiKey, requestTimeout, log, tokenSource.Token);
string symbolApiKey = getSymbolApiKey(symbolSource);
await PushSymbols(packagePath, symbolSource, symbolApiKey, requestTimeout, log, tokenSource.Token);
}
}
}
Expand Down Expand Up @@ -115,8 +119,10 @@ private async Task PushSymbols(string packagePath,
// Push the symbols package if it exists
if (File.Exists(symbolPackagePath))
{
var sourceUri = UriUtility.CreateSourceUri(source);

// See if the api key exists
if (String.IsNullOrEmpty(apiKey))
if (String.IsNullOrEmpty(apiKey) && !sourceUri.IsFile)
{
log.LogWarning(string.Format(CultureInfo.CurrentCulture,
Strings.Warning_SymbolServerNotConfigured,
Expand Down Expand Up @@ -145,7 +151,9 @@ private async Task PushPackage(string packagePath,
ILogger log,
CancellationToken token)
{
if (string.IsNullOrEmpty(apiKey) && !IsFileSource())
var sourceUri = UriUtility.CreateSourceUri(source);

if (string.IsNullOrEmpty(apiKey) && !sourceUri.IsFile)
{
log.LogWarning(string.Format(CultureInfo.CurrentCulture,
Strings.NoApiKeyFound,
Expand Down Expand Up @@ -177,7 +185,7 @@ private async Task PushPackageCore(string source,
Path.GetFileName(packageToPush),
sourceName));

if (IsFileSource())
if (sourceUri.IsFile)
{
await PushPackageToFileSystem(sourceUri, packageToPush, log, token);
}
Expand Down Expand Up @@ -347,7 +355,7 @@ private async Task DeletePackage(string source,
CancellationToken token)
{
var sourceUri = GetServiceEndpointUrl(source, string.Empty);
if (IsFileSource())
if (sourceUri.IsFile)
{
DeletePackageFromFileSystem(source, packageId, packageVersion, logger);
}
Expand Down
Loading

0 comments on commit 18f258a

Please sign in to comment.