Skip to content

Commit 8077c92

Browse files
Deprecate http usage: nuget list promote warning to error for http sources (#5694)
1 parent 1845d6b commit 8077c92

5 files changed

Lines changed: 105 additions & 61 deletions

File tree

src/NuGet.Core/NuGet.Commands/ListCommand/ListCommandRunner.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task ExecuteCommand(ListArgs listArgs)
4949
}
5050
}
5151

52-
WarnForHTTPSources(listArgs);
52+
AvoidHttpSources(listArgs);
5353

5454
var allPackages = new List<IEnumerableAsync<IPackageSearchMetadata>>();
5555
var log = listArgs.IsDetailed ? listArgs.Logger : NullLogger.Instance;
@@ -64,7 +64,7 @@ await feed.ListAsync(listArgs.Arguments.FirstOrDefault(), listArgs.Prerelease, l
6464
await PrintPackages(listArgs, new AggregateEnumerableAsync<IPackageSearchMetadata>(allPackages, comparer, comparer).GetEnumeratorAsync());
6565
}
6666

67-
private static void WarnForHTTPSources(ListArgs listArgs)
67+
private static void AvoidHttpSources(ListArgs listArgs)
6868
{
6969
List<PackageSource> httpPackageSources = null;
7070
foreach (PackageSource packageSource in listArgs.ListEndpoints)
@@ -83,17 +83,17 @@ private static void WarnForHTTPSources(ListArgs listArgs)
8383
{
8484
if (httpPackageSources.Count == 1)
8585
{
86-
listArgs.Logger.LogWarning(
86+
throw new ArgumentException(
8787
string.Format(CultureInfo.CurrentCulture,
88-
Strings.Warning_HttpServerUsage,
88+
Strings.Error_HttpSource_Single,
8989
"list",
9090
httpPackageSources[0]));
9191
}
9292
else
9393
{
94-
listArgs.Logger.LogWarning(
94+
throw new ArgumentException(
9595
string.Format(CultureInfo.CurrentCulture,
96-
Strings.Warning_HttpServerUsage_MultipleSources,
96+
Strings.Error_HttpSources_Multiple,
9797
"list",
9898
Environment.NewLine + string.Join(Environment.NewLine, httpPackageSources.Select(e => e.Name))));
9999
}

src/NuGet.Core/NuGet.Commands/Strings.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGet.Core/NuGet.Commands/Strings.resx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,4 +1099,12 @@ Non-HTTPS access will be removed in a future version. Consider migrating to 'HTT
10991099
<data name="SourcesCommandValidProtocolVersion" xml:space="preserve">
11001100
<value>The protocol version specified is invalid. Valid protocol versions are from {0} to {1}.</value>
11011101
</data>
1102+
<data name="Error_HttpSources_Multiple" xml:space="preserve">
1103+
<value>You are running the '{0}' operation with 'HTTP' sources: {1}. NuGet requires HTTPS sources. To use HTTP sources, you must explicitly set 'allowInsecureConnections' to true in your NuGet.Config file. Please refer to https://aka.ms/nuget-https-everywhere.</value>
1104+
<comment>0 - The command name. Ex. Push/Delete. 1 - list of server URIs</comment>
1105+
</data>
1106+
<data name="Error_HttpSource_Single" xml:space="preserve">
1107+
<value>You are running the '{0}' operation with an 'HTTP' source: {1}. NuGet requires HTTPS sources. To use an HTTP source, you must explicitly set 'allowInsecureConnections' to true in your NuGet.Config file. Please refer to https://aka.ms/nuget-https-everywhere.</value>
1108+
<comment>0 - The command name. Ex. Push/Delete. 1 - server URI.</comment>
1109+
</data>
11021110
</root>

0 commit comments

Comments
 (0)