Skip to content

Commit

Permalink
Anonymous module artifact fetch when encountering status 403
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephane Lapointe committed Mar 25, 2022
1 parent dd0bad9 commit f97a6ba
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Bicep.Core/Registry/AzureContainerRegistryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Bicep.Core.Registry.Oci;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -38,11 +39,13 @@ public async Task<OciArtifactResult> PullArtifactAsync(RootConfiguration configu

try
{
Trace.WriteLine($"Authenticated attempt to pull artifact for module {moduleReference.FullyQualifiedReference}.");
// Try authenticated client first.
(manifest, manifestStream, manifestDigest) = await DownloadManifestAsync(moduleReference, client);
}
catch (RequestFailedException exception) when (exception.Status == 401)
catch (RequestFailedException exception) when (exception.Status == 401 || exception.Status == 403)
{
Trace.WriteLine($"Authenticated attempt to pull artifact for module {moduleReference.FullyQualifiedReference} failed, received code {exception.Status}. Fallback to anonymous pull.");
// Fall back to anonymous client.
client = this.CreateBlobClient(configuration, moduleReference, anonymousAccess: true);
(manifest, manifestStream, manifestDigest) = await DownloadManifestAsync(moduleReference, client);
Expand Down

0 comments on commit f97a6ba

Please sign in to comment.