Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 16 additions & 4 deletions src/code/ContainerRegistryServerAPICalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ public override Stream InstallPackage(string packageName, string packageVersion,
return results;
}

results = InstallVersion(packageName, packageVersion, out errRecord);
string packageNameForInstall = PrependMARPrefix(packageName);
results = InstallVersion(packageNameForInstall, packageVersion, out errRecord);
return results;
}

Expand Down Expand Up @@ -1601,13 +1602,14 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
string registryUrl = Repository.Uri.ToString();
string packageNameLowercase = packageName.ToLower();

string packageNameForFind = PrependMARPrefix(packageNameLowercase);
string containerRegistryAccessToken = GetContainerRegistryAccessToken(out errRecord);
if (errRecord != null)
{
return emptyHashResponses;
}

var foundTags = FindContainerRegistryImageTags(packageNameLowercase, "*", containerRegistryAccessToken, out errRecord);
var foundTags = FindContainerRegistryImageTags(packageNameForFind, "*", containerRegistryAccessToken, out errRecord);
if (errRecord != null || foundTags == null)
{
return emptyHashResponses;
Expand All @@ -1616,7 +1618,7 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
List<Hashtable> latestVersionResponse = new List<Hashtable>();
List<JToken> allVersionsList = foundTags["tags"].ToList();

SortedDictionary<NuGet.Versioning.SemanticVersion, string> sortedQualifyingPkgs = GetPackagesWithRequiredVersion(allVersionsList, versionType, versionRange, requiredVersion, packageNameLowercase, includePrerelease, out errRecord);
SortedDictionary<NuGet.Versioning.SemanticVersion, string> sortedQualifyingPkgs = GetPackagesWithRequiredVersion(allVersionsList, versionType, versionRange, requiredVersion, packageNameForFind, includePrerelease, out errRecord);
if (errRecord != null)
{
return emptyHashResponses;
Expand All @@ -1627,7 +1629,7 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
foreach (var pkgVersionTag in pkgsInDescendingOrder)
{
string exactTagVersion = pkgVersionTag.Value.ToString();
Hashtable metadata = GetContainerRegistryMetadata(packageNameLowercase, exactTagVersion, containerRegistryAccessToken, out errRecord);
Hashtable metadata = GetContainerRegistryMetadata(packageNameForFind, exactTagVersion, containerRegistryAccessToken, out errRecord);
if (errRecord != null || metadata.Count == 0)
{
return emptyHashResponses;
Expand Down Expand Up @@ -1694,6 +1696,16 @@ private Hashtable[] FindPackagesWithVersionHelper(string packageName, VersionTyp
return sortedPkgs;
}

private string PrependMARPrefix(string packageName)
{
// If the repostitory is MAR and its not a wildcard search, we need to prefix the package name with MAR prefix.
string updatedPackageName = Repository.IsMARRepository() && packageName.Trim() != "*"
? string.Concat(PSRepositoryInfo.MARPrefix, packageName)
: packageName;

return updatedPackageName;
}

#endregion
}
}
13 changes: 13 additions & 0 deletions src/code/PSRepositoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ namespace Microsoft.PowerShell.PSResourceGet.UtilClasses
/// </summary>
public sealed class PSRepositoryInfo
{
#region constants
internal const string MARPrefix = "psresource/";
#endregion

#region Enums

public enum APIVersion
Expand Down Expand Up @@ -95,5 +99,14 @@ public enum RepositoryProviderType
public bool IsAllowedByPolicy { get; set; }

#endregion

#region Methods

internal bool IsMARRepository()
{
return (ApiVersion == APIVersion.ContainerRegistry && Uri.Host.Contains("mcr.microsoft.com"));
}

#endregion
}
}
11 changes: 11 additions & 0 deletions src/code/PublishHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,17 @@ internal void PushResource(string Repository, string modulePrefix, bool SkipDepe
return;
}

if (repository.IsMARRepository())
{
_cmdletPassedIn.WriteError(new ErrorRecord(
new PSInvalidOperationException($"Repository '{repository.Name}' is a MAR repository and cannot be published to."),
"MARRepositoryPublishError",
ErrorCategory.PermissionDenied,
this));

return;
}

_networkCredential = Utils.SetNetworkCredential(repository, _networkCredential, _cmdletPassedIn);

// Check if dependencies already exist within the repo if:
Expand Down
Loading