-
Notifications
You must be signed in to change notification settings - Fork 692
/
PushRunner.cs
113 lines (105 loc) · 4.41 KB
/
PushRunner.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// 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 System;
using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Configuration;
using NuGet.Protocol.Core.Types;
namespace NuGet.Commands
{
/// <summary>
/// Shared code to run the "push" command from the command line projects
/// </summary>
public static class PushRunner
{
public static async Task Run(
ISettings settings,
IPackageSourceProvider sourceProvider,
IList<string> packagePaths,
string source,
string apiKey,
string symbolSource,
string symbolApiKey,
int timeoutSeconds,
bool disableBuffering,
bool noSymbols,
bool noServiceEndpoint,
bool skipDuplicate,
ILogger logger)
{
source = CommandRunnerUtility.ResolveSource(sourceProvider, source);
symbolSource = CommandRunnerUtility.ResolveSymbolSource(sourceProvider, symbolSource);
if (timeoutSeconds == 0)
{
timeoutSeconds = 5 * 60;
}
PackageSource packageSource = CommandRunnerUtility.GetOrCreatePackageSource(sourceProvider, source);
var packageUpdateResource = await CommandRunnerUtility.GetPackageUpdateResource(sourceProvider, packageSource);
// Only warn for V3 style sources because they have a service index which is different from the final push url.
if (packageSource.IsHttp && !packageSource.IsHttps &&
(packageSource.ProtocolVersion == 3 || packageSource.Source.EndsWith("json", StringComparison.OrdinalIgnoreCase)))
{
logger.LogWarning(string.Format(CultureInfo.CurrentCulture, Strings.Warning_HttpServerUsage, "push", packageSource.Source));
}
packageUpdateResource.Settings = settings;
SymbolPackageUpdateResourceV3 symbolPackageUpdateResource = null;
// figure out from index.json if pushing snupkg is supported
var sourceUri = packageUpdateResource.SourceUri;
if (string.IsNullOrEmpty(symbolSource)
&& !noSymbols
&& !sourceUri.IsFile
&& sourceUri.IsAbsoluteUri)
{
symbolPackageUpdateResource = await CommandRunnerUtility.GetSymbolPackageUpdateResource(sourceProvider, source);
if (symbolPackageUpdateResource != null)
{
symbolSource = symbolPackageUpdateResource.SourceUri.AbsoluteUri;
symbolApiKey = apiKey;
}
}
await packageUpdateResource.Push(
packagePaths,
symbolSource,
timeoutSeconds,
disableBuffering,
endpoint => apiKey ?? CommandRunnerUtility.GetApiKey(settings, endpoint, source),
symbolsEndpoint => symbolApiKey ?? CommandRunnerUtility.GetApiKey(settings, symbolsEndpoint, symbolSource),
noServiceEndpoint,
skipDuplicate,
symbolPackageUpdateResource,
logger);
}
[Obsolete("Use Run method which takes multiple package paths.")]
public static Task Run(
ISettings settings,
IPackageSourceProvider sourceProvider,
string packagePath,
string source,
string apiKey,
string symbolSource,
string symbolApiKey,
int timeoutSeconds,
bool disableBuffering,
bool noSymbols,
bool noServiceEndpoint,
bool skipDuplicate,
ILogger logger)
{
return Run(settings: settings,
sourceProvider: sourceProvider,
packagePaths: new[] { packagePath },
source: source,
apiKey: apiKey,
symbolSource: symbolSource,
symbolApiKey: symbolApiKey,
timeoutSeconds: timeoutSeconds,
disableBuffering: disableBuffering,
noSymbols: noSymbols,
noServiceEndpoint: noServiceEndpoint,
skipDuplicate: skipDuplicate,
logger: logger);
}
}
}