Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,31 @@ public static async Task<int> RunAsync(PackageDownloadArgs args, ILoggerWithColo
}
else
{
if (!TryGetRepositoriesForPackage(
package.Id,
args,
packageSourceMapping!,
allRepositories,
logger,
out sourceRepositories))
var mappedNames = packageSourceMapping!.GetConfiguredPackageSources(package.Id);

if (mappedNames.Count == 0)
{
// fail, no sources mapped for this package
var notConsideredSources = string.Join(
", ",
allRepositories.Select(repository => repository.PackageSource));

logger.LogError(string.Format(
CultureInfo.CurrentCulture,
Strings.PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped,
package.Id,
notConsideredSources));

downloadedAllSuccessfully &= false;
continue;
}

sourceRepositories = GetMappedRepositories(mappedNames, allRepositories, package.Id, logger);

if (DetectAndReportInsecureSources(args.AllowInsecureConnections, sourceRepositories.Select(r => r.PackageSource), logger))
{
return ExitCodeError;
downloadedAllSuccessfully &= false;
continue;
}
}

Expand Down Expand Up @@ -224,67 +240,49 @@ await ResolvePackageDownloadVersion(
return (versionToDownload, downloadSourceRepository);
}

/// <summary>
/// Builds the set of SourceRepository objects to use for a given package,
/// applying package source mapping
/// validating HTTP usage only on the *effective* sources.
/// </summary>
private static bool TryGetRepositoriesForPackage(
string packageId,
PackageDownloadArgs args,
PackageSourceMapping packageSourceMapping,
internal static IReadOnlyList<SourceRepository> GetMappedRepositories(
IReadOnlyList<string> mappedNames,
IReadOnlyList<SourceRepository> allRepos,
ILoggerWithColor logger,
out IReadOnlyList<SourceRepository> repositories)
string packageId,
ILoggerWithColor logger)
{
var mappedNames = packageSourceMapping.GetConfiguredPackageSources(packageId);
var mappedRepos = new List<SourceRepository>(mappedNames.Count);

// Only validate insecure sources when mapping produced something
if (mappedNames.Count > 0)
foreach (var mappedName in mappedNames)
{
var mappedRepos = new List<SourceRepository>(mappedNames.Count);
foreach (var mappedName in mappedNames)
{
SourceRepository? repo = null;
for (int i = 0; i < allRepos.Count; i++)
{
if (string.Equals(allRepos[i].PackageSource.Name, mappedName, StringComparison.OrdinalIgnoreCase))
{
repo = allRepos[i];
break;
}
}
SourceRepository? repo = FindRepositoryByName(mappedName, allRepos);

if (repo != null)
{
mappedRepos.Add(repo);
}
else
{
logger.LogVerbose(
string.Format(
CultureInfo.CurrentCulture,
Strings.PackageDownloadCommand_PackageSourceMapping_NoSuchSource,
mappedName,
packageId));
}
if (repo != null)
{
mappedRepos.Add(repo);
}

if (DetectAndReportInsecureSources(args.AllowInsecureConnections, mappedRepos.Select(repo => repo.PackageSource), logger))
else
{
repositories = [];
return false;
logger.LogVerbose(
string.Format(
CultureInfo.CurrentCulture,
Strings.PackageDownloadCommand_PackageSourceMapping_NoSuchSource,
mappedName,
packageId));
}

repositories = mappedRepos;
return true;
}
else

return mappedRepos;
}

private static SourceRepository? FindRepositoryByName(
string mappedName,
IReadOnlyList<SourceRepository> allRepos)
{
for (int i = 0; i < allRepos.Count; i++)
{
// No mapping for this package: fall back to all sources
repositories = allRepos;
return true;
if (string.Equals(allRepos[i].PackageSource.Name, mappedName, StringComparison.OrdinalIgnoreCase))
{
return allRepos[i];
}
}

return null;
}

private static async Task<bool> DownloadPackageAsync(
Expand Down
11 changes: 10 additions & 1 deletion 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.

5 changes: 5 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1162,4 +1162,9 @@ Do not translate "PackageVersion"</comment>
<comment>0 - package source name
1 - package name</comment>
</data>
<data name="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped" xml:space="preserve">
<value>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</value>
<comment>{0} = package ID
{1} = comma-separated list of all configured sources </comment>
</data>
</root>
6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ Další informace najdete tady: https://docs.nuget.org/docs/reference/command-li
<target state="translated">Identifikátor balíčku (např. Newtonsoft.Json)</target>
<note />
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped">
<source>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</source>
<target state="new">Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</target>
<note>{0} = package ID
{1} = comma-separated list of all configured sources </note>
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSuchSource">
<source>The mapped source '{0}' for package '{1}' was not found among the configured sources.</source>
<target state="translated">Mapovaný zdroj {0} pro balíček {1} nebyl nalezen mezi nakonfigurovanými zdroji.</target>
Expand Down
6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ Weitere Informationen finden Sie unter: https://docs.nuget.org/docs/reference/co
<target state="translated">Paketbezeichner (z. B. „Newtonsoft.Json“).</target>
<note />
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped">
<source>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</source>
<target state="new">Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</target>
<note>{0} = package ID
{1} = comma-separated list of all configured sources </note>
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSuchSource">
<source>The mapped source '{0}' for package '{1}' was not found among the configured sources.</source>
<target state="translated">Die zugeordnete Quelle {0} für das Paket {1} wurde unter den konfigurierten Quellen nicht gefunden.</target>
Expand Down
6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ Para obtener más información, visite https://docs.nuget.org/docs/reference/com
<target state="translated">Identificador del paquete (por ejemplo, 'Newtonsoft.Json').</target>
<note />
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped">
<source>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</source>
<target state="new">Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</target>
<note>{0} = package ID
{1} = comma-separated list of all configured sources </note>
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSuchSource">
<source>The mapped source '{0}' for package '{1}' was not found among the configured sources.</source>
<target state="translated">No se encontró el origen asignado '{0}' para el paquete '{1}' entre los orígenes configurados.</target>
Expand Down
6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ Pour plus d'informations, visitez https://docs.nuget.org/docs/reference/command-
<target state="translated">Identificateur de package (par exemple, « Newtonsoft.Json »).</target>
<note />
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped">
<source>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</source>
<target state="new">Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</target>
<note>{0} = package ID
{1} = comma-separated list of all configured sources </note>
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSuchSource">
<source>The mapped source '{0}' for package '{1}' was not found among the configured sources.</source>
<target state="translated">La source mappée « {0} » pour le package « {1} » est introuvable parmi les sources configurées.</target>
Expand Down
6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ Per altre informazioni, vedere https://docs.nuget.org/docs/reference/command-lin
<target state="translated">Identificatore del pacchetto ,ad esempio 'Newtonsoft.Json'.</target>
<note />
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped">
<source>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</source>
<target state="new">Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</target>
<note>{0} = package ID
{1} = comma-separated list of all configured sources </note>
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSuchSource">
<source>The mapped source '{0}' for package '{1}' was not found among the configured sources.</source>
<target state="translated">L'origine mappata '{0}' per il pacchetto '{1}' non è stata trovata tra le origini configurate.</target>
Expand Down
6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ For more information, visit https://docs.nuget.org/docs/reference/command-line-r
<target state="translated">パッケージ識別子 (例: 'Newtonsoft.Json')。</target>
<note />
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped">
<source>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</source>
<target state="new">Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</target>
<note>{0} = package ID
{1} = comma-separated list of all configured sources </note>
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSuchSource">
<source>The mapped source '{0}' for package '{1}' was not found among the configured sources.</source>
<target state="translated">パッケージ '{1}' のマップされたソース '{0}' が、構成済みのソースの中に見つかりませんでした。</target>
Expand Down
6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ For more information, visit https://docs.nuget.org/docs/reference/command-line-r
<target state="translated">패키지 식별자(예: 'Newtonsoft.Json').</target>
<note />
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped">
<source>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</source>
<target state="new">Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</target>
<note>{0} = package ID
{1} = comma-separated list of all configured sources </note>
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSuchSource">
<source>The mapped source '{0}' for package '{1}' was not found among the configured sources.</source>
<target state="translated">구성된 원본 중 '{1}' 패키지에 대해 매핑된 원본 '{0}'을(를) 찾을 수 없습니다.</target>
Expand Down
6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ Aby uzyskać więcej informacji, odwiedź stronę https://docs.nuget.org/docs/re
<target state="translated">Identyfikator pakietu (np. „Newtonsoft.Json”).</target>
<note />
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped">
<source>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</source>
<target state="new">Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</target>
<note>{0} = package ID
{1} = comma-separated list of all configured sources </note>
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSuchSource">
<source>The mapped source '{0}' for package '{1}' was not found among the configured sources.</source>
<target state="translated">Zmapowane źródło „{0}” dla pakietu „{1}” nie zostało znalezione wśród skonfigurowanych źródeł.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ Para obter mais informações, acesse https://docs.nuget.org/docs/reference/comm
<target state="translated">Identificador de pacote (por exemplo, "Newtonsoft.Json").</target>
<note />
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped">
<source>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</source>
<target state="new">Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</target>
<note>{0} = package ID
{1} = comma-separated list of all configured sources </note>
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSuchSource">
<source>The mapped source '{0}' for package '{1}' was not found among the configured sources.</source>
<target state="translated">A origem mapeada "{0}" para o pacote "{1}" não foi encontrada entre as fontes configuradas.</target>
Expand Down
6 changes: 6 additions & 0 deletions src/NuGet.Core/NuGet.CommandLine.XPlat/xlf/Strings.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,12 @@ For more information, visit https://docs.nuget.org/docs/reference/command-line-r
<target state="translated">Идентификатор пакета (например, "Newtonsoft.Json").</target>
<note />
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSourcesMapped">
<source>Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</source>
<target state="new">Unable to download package '{0}'. PackageSourceMapping is enabled, but no mapped sources were found for this package. The following source(s) were not considered: {1}.</target>
<note>{0} = package ID
{1} = comma-separated list of all configured sources </note>
</trans-unit>
<trans-unit id="PackageDownloadCommand_PackageSourceMapping_NoSuchSource">
<source>The mapped source '{0}' for package '{1}' was not found among the configured sources.</source>
<target state="translated">Сопоставленный источник "{0}" для пакета "{1}" не найден среди настроенных источников.</target>
Expand Down
Loading