diff --git a/src/Bicep.Cli/Commands/PublishCommand.cs b/src/Bicep.Cli/Commands/PublishCommand.cs index 2a34f22df10..7b8efad7cdc 100644 --- a/src/Bicep.Cli/Commands/PublishCommand.cs +++ b/src/Bicep.Cli/Commands/PublishCommand.cs @@ -13,7 +13,6 @@ using Bicep.Core.Features; using Bicep.Core.FileSystem; using Bicep.Core.Registry; -using Bicep.Core.Registry.Oci; using Bicep.Core.SourceCode; namespace Bicep.Cli.Commands @@ -99,7 +98,7 @@ private async Task PublishModuleAsync(ArtifactReference target, Stream compiledA private ArtifactReference ValidateReference(string targetModuleReference, Uri targetModuleUri) { - if (!this.moduleDispatcher.TryGetArtifactReference(targetModuleReference, "module", targetModuleUri).IsSuccess(out var moduleReference, out var failureBuilder)) + if (!this.moduleDispatcher.TryGetModuleReference(targetModuleReference, targetModuleUri).IsSuccess(out var moduleReference, out var failureBuilder)) { // TODO: We should probably clean up the dispatcher contract so this sort of thing isn't necessary (unless we change how target module is set in this command) var message = failureBuilder(DiagnosticBuilder.ForDocumentStart()).Message; diff --git a/src/Bicep.Core.IntegrationTests/RegistryTests.cs b/src/Bicep.Core.IntegrationTests/RegistryTests.cs index d8b0863322c..7d2747ac298 100644 --- a/src/Bicep.Core.IntegrationTests/RegistryTests.cs +++ b/src/Bicep.Core.IntegrationTests/RegistryTests.cs @@ -182,7 +182,7 @@ public async Task ModuleRestoreContentionShouldProduceConsistentState(bool publi var moduleReferences = dataSet.RegistryModules.Values .OrderBy(m => m.Metadata.Target) - .Select(m => dispatcher.TryGetArtifactReference(m.Metadata.Target, "module", RandomFileUri()).IsSuccess(out var @ref) ? @ref : throw new AssertFailedException($"Invalid module target '{m.Metadata.Target}'.")) + .Select(m => dispatcher.TryGetModuleReference(m.Metadata.Target, RandomFileUri()).IsSuccess(out var @ref) ? @ref : throw new AssertFailedException($"Invalid module target '{m.Metadata.Target}'.")) .ToImmutableList(); moduleReferences.Should().HaveCount(7); @@ -238,7 +238,7 @@ public async Task ModuleRestoreWithStuckFileLockShouldFailAfterTimeout(IEnumerab var configuration = BicepTestConstants.BuiltInConfigurationWithAllAnalyzersDisabled; var moduleReferences = moduleInfos .OrderBy(m => m.Metadata.Target) - .Select(m => dispatcher.TryGetArtifactReference(m.Metadata.Target, "module", RandomFileUri()).IsSuccess(out var @ref) ? @ref : throw new AssertFailedException($"Invalid module target '{m.Metadata.Target}'.")) + .Select(m => dispatcher.TryGetModuleReference(m.Metadata.Target, RandomFileUri()).IsSuccess(out var @ref) ? @ref : throw new AssertFailedException($"Invalid module target '{m.Metadata.Target}'.")) .ToImmutableList(); moduleReferences.Should().HaveCount(moduleCount); @@ -307,7 +307,7 @@ public async Task ForceModuleRestoreWithStuckFileLockShouldFailAfterTimeout(IEnu var moduleReferences = moduleInfos .OrderBy(m => m.Metadata.Target) - .Select(m => dispatcher.TryGetArtifactReference(m.Metadata.Target, "module", RandomFileUri()).IsSuccess(out var @ref) ? @ref : throw new AssertFailedException($"Invalid module target '{m.Metadata.Target}'.")) + .Select(m => dispatcher.TryGetModuleReference(m.Metadata.Target, RandomFileUri()).IsSuccess(out var @ref) ? @ref : throw new AssertFailedException($"Invalid module target '{m.Metadata.Target}'.")) .ToImmutableList(); moduleReferences.Should().HaveCount(moduleCount); @@ -384,7 +384,7 @@ public async Task ForceModuleRestoreShouldRestoreAllModules(IEnumerable m.Metadata.Target) - .Select(m => dispatcher.TryGetArtifactReference(m.Metadata.Target, "module", RandomFileUri()).IsSuccess(out var @ref) ? @ref : throw new AssertFailedException($"Invalid module target '{m.Metadata.Target}'.")) + .Select(m => dispatcher.TryGetModuleReference(m.Metadata.Target, RandomFileUri()).IsSuccess(out var @ref) ? @ref : throw new AssertFailedException($"Invalid module target '{m.Metadata.Target}'.")) .ToImmutableList(); moduleReferences.Should().HaveCount(moduleCount); diff --git a/src/Bicep.Core.Samples/DataSetsExtensions.cs b/src/Bicep.Core.Samples/DataSetsExtensions.cs index 5a8985db5d0..0680d2ff325 100644 --- a/src/Bicep.Core.Samples/DataSetsExtensions.cs +++ b/src/Bicep.Core.Samples/DataSetsExtensions.cs @@ -73,7 +73,7 @@ public static Mock CreateMockRegistryClients(Im { var target = publishInfo.Metadata.Target; - if (!dispatcher.TryGetArtifactReference(target, "module", RandomFileUri()).IsSuccess(out var @ref) || @ref is not OciArtifactReference targetReference) + if (!dispatcher.TryGetModuleReference(target, RandomFileUri()).IsSuccess(out var @ref) || @ref is not OciArtifactReference targetReference) { throw new InvalidOperationException($"Module '{moduleName}' has an invalid target reference '{target}'. Specify a reference to an OCI artifact."); } @@ -149,7 +149,7 @@ public static ITemplateSpecRepositoryFactory CreateMockTemplateSpecRepositoryFac foreach (var (moduleName, templateSpecInfo) in templateSpecs) { - if (!dispatcher.TryGetArtifactReference(templateSpecInfo.Metadata.Target, "module", RandomFileUri()).IsSuccess(out var @ref) || @ref is not TemplateSpecModuleReference reference) + if (!dispatcher.TryGetModuleReference(templateSpecInfo.Metadata.Target, RandomFileUri()).IsSuccess(out var @ref) || @ref is not TemplateSpecModuleReference reference) { throw new InvalidOperationException($"Module '{moduleName}' has an invalid target reference '{templateSpecInfo.Metadata.Target}'. Specify a reference to a template spec."); } @@ -191,7 +191,7 @@ public static async Task PublishModuleToRegistryAsync(IContainerRegistryClientFa .AddSingleton(featureProviderFactory) ).Construct(); - var targetReference = dispatcher.TryGetArtifactReference(target, "TODO", RandomFileUri()).IsSuccess(out var @ref) ? @ref + var targetReference = dispatcher.TryGetModuleReference(target, RandomFileUri()).IsSuccess(out var @ref) ? @ref : throw new InvalidOperationException($"Module '{moduleName}' has an invalid target reference '{target}'. Specify a reference to an OCI artifact."); var result = CompilationHelper.Compile(moduleSource); diff --git a/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs b/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs index bf935dba133..10d5a9962e6 100644 --- a/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs +++ b/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs @@ -991,7 +991,7 @@ public ErrorDiagnostic DirectAccessToCollectionNotSupported(IEnumerable? "BCP162", "Expected a loop item variable identifier or \"(\" at this location."); - public ErrorDiagnostic ScopeUnsupportedOnChildResource(string parentIdentifier) => new( + public ErrorDiagnostic ScopeUnsupportedOnChildResource() => new( TextSpan, "BCP164", $"A child resource's scope is computed based on the scope of its ancestor resource. This means that using the \"{LanguageConstants.ResourceScopePropertyName}\" property on a child resource is unsupported."); @@ -1761,7 +1761,7 @@ public ErrorDiagnostic IndexOutOfBounds(string typeName, long tupleLength, long var message = new StringBuilder("The provided index value of \"").Append(indexSought).Append("\" is not valid for type \"").Append(typeName).Append("\"."); if (tupleLength > 0) { - message.Append(" Indexes for this type must be between 0 and ").Append(tupleLength - 1).Append("."); + message.Append(" Indexes for this type must be between 0 and ").Append(tupleLength - 1).Append('.'); } return new(TextSpan, "BCP311", message.ToString()); diff --git a/src/Bicep.Core/Registry/ArtifactRegistry.cs b/src/Bicep.Core/Registry/ArtifactRegistry.cs index b606a6e079d..ce71ce9d571 100644 --- a/src/Bicep.Core/Registry/ArtifactRegistry.cs +++ b/src/Bicep.Core/Registry/ArtifactRegistry.cs @@ -29,7 +29,7 @@ public abstract class ArtifactRegistry : IArtifactRegistry where T : Artifact public abstract ResultWithDiagnostic TryGetLocalArtifactEntryPointUri(T reference); - public abstract ResultWithDiagnostic TryParseArtifactReference(string? aliasName, string artifactType, string reference, Uri parentModuleUri); + public abstract ResultWithDiagnostic TryParseArtifactReference(string? aliasName, string artifactType, string reference); public abstract string? TryGetDocumentationUri(T reference); diff --git a/src/Bicep.Core/Registry/IArtifactReferenceFactory.cs b/src/Bicep.Core/Registry/IArtifactReferenceFactory.cs index 68fc9a21a8a..d0c6f227786 100644 --- a/src/Bicep.Core/Registry/IArtifactReferenceFactory.cs +++ b/src/Bicep.Core/Registry/IArtifactReferenceFactory.cs @@ -15,5 +15,7 @@ public interface IArtifactReferenceFactory ResultWithDiagnostic TryGetArtifactReference(string reference, string artifactType, Uri parentModuleUri); + ResultWithDiagnostic TryGetModuleReference(string reference, Uri parentModuleUri); + ResultWithDiagnostic TryGetArtifactReference(IArtifactReferenceSyntax artifactDeclaration, Uri parentModuleUri); } diff --git a/src/Bicep.Core/Registry/IArtifactRegistry.cs b/src/Bicep.Core/Registry/IArtifactRegistry.cs index e487ba2e728..d0a883dbfb2 100644 --- a/src/Bicep.Core/Registry/IArtifactRegistry.cs +++ b/src/Bicep.Core/Registry/IArtifactRegistry.cs @@ -34,8 +34,7 @@ public interface IArtifactRegistry /// The alias name /// The unqualified artifact reference /// The artifact type. Either "module" or "provider" - /// The URI of the parent module - ResultWithDiagnostic TryParseArtifactReference(string? aliasName, string artifactType, string reference, Uri parentModuleUri); + ResultWithDiagnostic TryParseArtifactReference(string? aliasName, string artifactType, string reference); /// /// Returns true if the specified artifact is already cached in the local cache. diff --git a/src/Bicep.Core/Registry/ModuleDispatcher.cs b/src/Bicep.Core/Registry/ModuleDispatcher.cs index c32c795aab3..f39b8508e57 100644 --- a/src/Bicep.Core/Registry/ModuleDispatcher.cs +++ b/src/Bicep.Core/Registry/ModuleDispatcher.cs @@ -41,6 +41,10 @@ private ImmutableDictionary Registries(Uri parentModu public ImmutableArray AvailableSchemes(Uri parentModuleUri) => Registries(parentModuleUri).Keys.OrderBy(s => s).ToImmutableArray(); + public ResultWithDiagnostic TryGetModuleReference(string reference, Uri parentModuleUri) + => TryGetArtifactReference(reference, "module", parentModuleUri); + + public ResultWithDiagnostic TryGetArtifactReference(string reference, string artifactType, Uri parentModuleUri) { var registries = Registries(parentModuleUri); @@ -51,7 +55,7 @@ public ResultWithDiagnostic TryGetArtifactReference(string re // local path reference if (registries.TryGetValue(ModuleReferenceSchemes.Local, out var localRegistry)) { - return localRegistry.TryParseArtifactReference(null, "module", parts[0], parentModuleUri); + return localRegistry.TryParseArtifactReference(null, "module", parts[0]); } return new(x => x.UnknownModuleReferenceScheme(ModuleReferenceSchemes.Local, this.AvailableSchemes(parentModuleUri))); @@ -73,7 +77,7 @@ public ResultWithDiagnostic TryGetArtifactReference(string re // the scheme is recognized var rawValue = parts[1]; - return registry.TryParseArtifactReference(aliasName, artifactType, rawValue, parentModuleUri); + return registry.TryParseArtifactReference(aliasName, artifactType, rawValue); } // unknown scheme diff --git a/src/Bicep.Core/Registry/OciArtifactRegistry.cs b/src/Bicep.Core/Registry/OciArtifactRegistry.cs index 73d4ea3a8d0..d592180ff72 100644 --- a/src/Bicep.Core/Registry/OciArtifactRegistry.cs +++ b/src/Bicep.Core/Registry/OciArtifactRegistry.cs @@ -60,7 +60,7 @@ public override RegistryCapabilities GetCapabilities(OciArtifactReference refere return reference.Tag is null ? RegistryCapabilities.Default : RegistryCapabilities.Publish; } - public override ResultWithDiagnostic TryParseArtifactReference(string? aliasName, string artifactType, string reference, Uri parentModuleUri) + public override ResultWithDiagnostic TryParseArtifactReference(string? aliasName, string artifactType, string reference) { var type = artifactType switch {