Skip to content

Commit

Permalink
Anonymous module artifact fetch when encountering status 403 (#6284)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephane Lapointe <stephane.lap@outlook.com>
  • Loading branch information
slapointe and Stephane Lapointe authored Mar 25, 2022
1 parent dd0bad9 commit 0c42576
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 0c42576

Please sign in to comment.