From 9937570222a5c87d19ad5a7d54e934a48d2f2b88 Mon Sep 17 00:00:00 2001 From: Anthony Martin <38542602+anthony-c-martin@users.noreply.github.com> Date: Fri, 30 Aug 2024 10:45:43 -0400 Subject: [PATCH] Remove 'azTypesViaRegistry' feature --- docs/experimental-features.md | 3 --- .../examples/extensions.ff/bicepconfig.json | 3 +-- .../examples/extensions.prod/bicepconfig.json | 3 +-- .../AzTypesViaRegistryTests.cs | 26 ++++++++++++------- ...ntralizedProviderVersionManagementTests.cs | 5 +--- .../Extensibility/RadiusCompatibilityTests.cs | 2 +- .../ExtensionRegistryTests.cs | 19 ++------------ .../ConfigurationManagerTests.cs | 6 ----- .../Features/FeatureProviderOverrides.cs | 3 --- .../Features/OverriddenFeatureProvider.cs | 2 -- .../Utils/TestTypeHelper.cs | 2 +- .../ExperimentalFeaturesEnabled.cs | 1 - src/Bicep.Core/CoreResources.Designer.cs | 9 ------- src/Bicep.Core/CoreResources.resx | 3 --- .../Diagnostics/DiagnosticBuilder.cs | 4 --- src/Bicep.Core/Features/FeatureProvider.cs | 2 -- src/Bicep.Core/Features/IFeatureProvider.cs | 3 --- .../Semantics/Namespaces/AzNamespaceType.cs | 7 +---- .../Semantics/Namespaces/NamespaceProvider.cs | 19 ++++++-------- .../Namespaces/ThirdPartyNamespaceType.cs | 13 ++-------- .../Providers/Az/AzResourceTypeLoader.cs | 5 ++-- .../Providers/IResourceTypeProviderFactory.cs | 2 +- .../Providers/ResourceTypeProviderFactory.cs | 18 +++++++------ .../ThirdPartyResourceTypeLoader.cs | 6 ++--- .../schemas/bicepconfig.schema.json | 4 --- 25 files changed, 52 insertions(+), 118 deletions(-) diff --git a/docs/experimental-features.md b/docs/experimental-features.md index 49fee27501d..b3cc27b7428 100644 --- a/docs/experimental-features.md +++ b/docs/experimental-features.md @@ -11,9 +11,6 @@ The following features can be optionally enabled through your `bicepconfig.json` ### `assertions` Should be enabled in tandem with `testFramework` experimental feature flag for expected functionality. Allows you to author boolean assertions using the `assert` keyword comparing the actual value of a parameter, variable, or resource name to an expected value. Assert statements can only be written directly within the Bicep file whose resources they reference. For more information, see [Bicep Experimental Test Framework](https://github.com/Azure/bicep/issues/11967). -### `azTypesViaRegistry` -Requires `extensibility` to be enabled. If enabled, users are able to fetch the azure resource type definitions from an OCI Registry as a runtime dependency. To fetch the type definitions the following syntax can be used. For example `extension 'br:mcr.microsoft.com/bicep/extensions/az@1.0.0' as az`. - ### `extendableParamFiles` Enables the ability to extend bicepparam files from other bicepparam files. For more information, see [Extendable Bicep Params Files](./experimental/extendable-param-files.md). diff --git a/src/Bicep.Cli.E2eTests/src/examples/extensions.ff/bicepconfig.json b/src/Bicep.Cli.E2eTests/src/examples/extensions.ff/bicepconfig.json index f8dc2007ea7..90715aa8638 100644 --- a/src/Bicep.Cli.E2eTests/src/examples/extensions.ff/bicepconfig.json +++ b/src/Bicep.Cli.E2eTests/src/examples/extensions.ff/bicepconfig.json @@ -8,7 +8,6 @@ ] }, "experimentalFeaturesEnabled": { - "extensibility": true, - "azTypesViaRegistry": true + "extensibility": true } } diff --git a/src/Bicep.Cli.E2eTests/src/examples/extensions.prod/bicepconfig.json b/src/Bicep.Cli.E2eTests/src/examples/extensions.prod/bicepconfig.json index ef4b42eaa42..803ddef8166 100644 --- a/src/Bicep.Cli.E2eTests/src/examples/extensions.prod/bicepconfig.json +++ b/src/Bicep.Cli.E2eTests/src/examples/extensions.prod/bicepconfig.json @@ -4,7 +4,6 @@ "credentialPrecedence": ["AzureCLI"] }, "experimentalFeaturesEnabled": { - "extensibility": true, - "azTypesViaRegistry": true + "extensibility": true } } diff --git a/src/Bicep.Core.IntegrationTests/AzTypesViaRegistryTests.cs b/src/Bicep.Core.IntegrationTests/AzTypesViaRegistryTests.cs index c8d396e1833..1a8024b1085 100644 --- a/src/Bicep.Core.IntegrationTests/AzTypesViaRegistryTests.cs +++ b/src/Bicep.Core.IntegrationTests/AzTypesViaRegistryTests.cs @@ -6,6 +6,7 @@ using Bicep.Core.Configuration; using Bicep.Core.Diagnostics; using Bicep.Core.Semantics.Namespaces; +using Bicep.Core.TypeSystem.Providers; using Bicep.Core.UnitTests; using Bicep.Core.UnitTests.Assertions; using Bicep.Core.UnitTests.Mock; @@ -24,13 +25,23 @@ public class AzTypesViaRegistryTests : TestBase { private async Task GetServices() { - var indexJson = FileHelper.SaveResultFile(TestContext, "types/index.json", """{"resources": {}, "resourceFunctions": {}}"""); + var indexJson = FileHelper.SaveResultFile(TestContext, "types/index.json", """ +{ + "resources": {}, + "resourceFunctions": {}, + "settings": { + "name": "AzureResourceManager", + "version": "1.2.3", + "isSingleton": true + } +} +"""); var cacheRoot = FileHelper.GetUniqueTestOutputPath(TestContext); Directory.CreateDirectory(cacheRoot); var services = new ServiceBuilder() - .WithFeatureOverrides(new(ExtensibilityEnabled: true, AzTypesViaRegistryEnabled: true, CacheRootDirectory: cacheRoot)) + .WithFeatureOverrides(new(ExtensibilityEnabled: true, CacheRootDirectory: cacheRoot)) .WithContainerRegistryClientFactory(RegistryHelper.CreateOciClientForAzExtension()); await RegistryHelper.PublishAzExtension(services.Build(), indexJson); @@ -52,11 +63,8 @@ private async Task ServicesWithTestExtensionArtifact(ArtifactReg Directory.CreateDirectory(cacheRoot); return new ServiceBuilder() - .WithFeatureOverrides(new( - ExtensibilityEnabled: true, - AzTypesViaRegistryEnabled: true, - CacheRootDirectory: cacheRoot)) - .WithContainerRegistryClientFactory(clientFactory); + .WithFeatureOverrides(new(ExtensibilityEnabled: true, CacheRootDirectory: cacheRoot)) + .WithContainerRegistryClientFactory(clientFactory); } [TestMethod] @@ -68,7 +76,7 @@ public async Task Bicep_module_artifact_specified_in_extension_declaration_synta var clientFactory = RegistryHelper.CreateMockRegistryClients((testArtifact.RegistryAddress, testArtifact.RepositoryPath)).factoryMock; var services = new ServiceBuilder() .WithFileSystem(fsMock) - .WithFeatureOverrides(new(ExtensibilityEnabled: true, AzTypesViaRegistryEnabled: true)) + .WithFeatureOverrides(new(ExtensibilityEnabled: true)) .WithContainerRegistryClientFactory(clientFactory); await RegistryHelper.PublishModuleToRegistryAsync( @@ -143,7 +151,7 @@ public async Task Repository_not_found_in_registry( mockBlobClient.Object); var services = new ServiceBuilder() - .WithFeatureOverrides(new(ExtensibilityEnabled: true, AzTypesViaRegistryEnabled: true)) + .WithFeatureOverrides(new(ExtensibilityEnabled: true)) .WithContainerRegistryClientFactory(containerRegistryFactoryBuilder.Build().clientFactory); // ACT diff --git a/src/Bicep.Core.IntegrationTests/CentralizedProviderVersionManagementTests.cs b/src/Bicep.Core.IntegrationTests/CentralizedProviderVersionManagementTests.cs index c6eef2a82d6..58bde4c543c 100644 --- a/src/Bicep.Core.IntegrationTests/CentralizedProviderVersionManagementTests.cs +++ b/src/Bicep.Core.IntegrationTests/CentralizedProviderVersionManagementTests.cs @@ -13,10 +13,7 @@ namespace Bicep.Core.IntegrationTests [TestClass] public class CentralizedExtensionVersionManagementTests : TestBase { - private ServiceBuilder Services => new ServiceBuilder() - .WithFeatureOverrides(new( - ExtensibilityEnabled: true, - AzTypesViaRegistryEnabled: true)); + private ServiceBuilder Services => new ServiceBuilder().WithFeatureOverrides(new(ExtensibilityEnabled: true)); [TestMethod] [DynamicData(nameof(ExtensionsConfig_SupportForConfigManagedExtensionDeclarationSyntax_When_ExtensionIsBuiltIn_TestCases))] diff --git a/src/Bicep.Core.IntegrationTests/Extensibility/RadiusCompatibilityTests.cs b/src/Bicep.Core.IntegrationTests/Extensibility/RadiusCompatibilityTests.cs index 854c34e8643..143dd3588d7 100644 --- a/src/Bicep.Core.IntegrationTests/Extensibility/RadiusCompatibilityTests.cs +++ b/src/Bicep.Core.IntegrationTests/Extensibility/RadiusCompatibilityTests.cs @@ -18,7 +18,7 @@ private static ServiceBuilder GetServiceBuilder(IFileSystem fileSystem, string r var clientFactory = RegistryHelper.CreateMockRegistryClient(registryHost, repositoryPath); return new ServiceBuilder() - .WithFeatureOverrides(new(ExtensibilityEnabled: true, AzTypesViaRegistryEnabled: true)) + .WithFeatureOverrides(new(ExtensibilityEnabled: true)) .WithFileSystem(fileSystem) .WithContainerRegistryClientFactory(clientFactory); } diff --git a/src/Bicep.Core.IntegrationTests/ExtensionRegistryTests.cs b/src/Bicep.Core.IntegrationTests/ExtensionRegistryTests.cs index 8d1296eae7d..5bac3c1b630 100644 --- a/src/Bicep.Core.IntegrationTests/ExtensionRegistryTests.cs +++ b/src/Bicep.Core.IntegrationTests/ExtensionRegistryTests.cs @@ -21,8 +21,8 @@ namespace Bicep.Core.IntegrationTests; [TestClass] public class ExtensionRegistryTests : TestBase { - private static readonly FeatureProviderOverrides AllFeaturesEnabled = new(ExtensibilityEnabled: true, AzTypesViaRegistryEnabled: true); - private static readonly FeatureProviderOverrides AllFeaturesEnabledForLocalDeploy = new(ExtensibilityEnabled: true, LocalDeployEnabled: true, AzTypesViaRegistryEnabled: true); + private static readonly FeatureProviderOverrides AllFeaturesEnabled = new(ExtensibilityEnabled: true); + private static readonly FeatureProviderOverrides AllFeaturesEnabledForLocalDeploy = new(ExtensibilityEnabled: true, LocalDeployEnabled: true); [TestMethod] [TestCategory(BaselineHelper.BaselineTestCategory)] @@ -386,21 +386,6 @@ public async Task Using_interpolated_strings_in_extension_declaration_syntax_res result.Should().ContainDiagnostic("BCP303", DiagnosticLevel.Error, "String interpolation is unsupported for specifying the extension."); } - [TestMethod] - public async Task Cannot_import_az_without_dynamic_type_loading_enabled() - { - var services = await ExtensionTestHelper.GetServiceBuilderWithPublishedExtension(ThirdPartyTypeHelper.GetTestTypesTgz(), "mcr.microsoft.com/bicep/extension/az:1.2.3", AllFeaturesEnabled); - services = services.WithFeatureOverrides(new(ExtensibilityEnabled: true, AzTypesViaRegistryEnabled: false)); - - var result = await CompilationHelper.RestoreAndCompile(services, @" -extension 'br:mcr.microsoft.com/bicep/extension/az:1.2.3' -"); - result.Should().NotGenerateATemplate(); - result.Should().HaveDiagnostics([ - ("BCP399", DiagnosticLevel.Error, """Fetching az types from the registry requires enabling EXPERIMENTAL feature "azTypesViaRegistry".""") - ]); - } - [TestMethod] public async Task Missing_required_extension_configuration_blocks_compilation() { diff --git a/src/Bicep.Core.UnitTests/Configuration/ConfigurationManagerTests.cs b/src/Bicep.Core.UnitTests/Configuration/ConfigurationManagerTests.cs index 7f93ebd2212..9342c5ea950 100644 --- a/src/Bicep.Core.UnitTests/Configuration/ConfigurationManagerTests.cs +++ b/src/Bicep.Core.UnitTests/Configuration/ConfigurationManagerTests.cs @@ -106,7 +106,6 @@ public void GetBuiltInConfiguration_NoParameter_ReturnsBuiltInConfigurationWithA "legacyFormatter": false, "testFramework": false, "assertions": false, - "azTypesViaRegistry": false, "optionalModuleNames": false, "localDeploy": false, "resourceDerivedTypes": false, @@ -188,7 +187,6 @@ public void GetBuiltInConfiguration_DisableAllAnalyzers_ReturnsBuiltInConfigurat "legacyFormatter": false, "testFramework": false, "assertions": false, - "azTypesViaRegistry": false, "optionalModuleNames": false, "localDeploy": false, "resourceDerivedTypes": false, @@ -295,7 +293,6 @@ public void GetBuiltInConfiguration_DisableAnalyzers_ReturnsBuiltInConfiguration "legacyFormatter": false, "testFramework": false, "assertions": false, - "azTypesViaRegistry": false, "optionalModuleNames": false, "localDeploy": false, "resourceDerivedTypes": false, @@ -388,7 +385,6 @@ public void GetBuiltInConfiguration_EnableExperimentalFeature_ReturnsBuiltInConf LegacyFormatter: false, TestFramework: false, Assertions: false, - azTypesViaRegistry: false, OptionalModuleNames: false, LocalDeploy: false, ResourceDerivedTypes: false, @@ -474,7 +470,6 @@ public void GetBuiltInConfiguration_EnableExperimentalFeature_ReturnsBuiltInConf "legacyFormatter": false, "testFramework": false, "assertions": false, - "azTypesViaRegistry": false, "optionalModuleNames": false, "localDeploy": false, "resourceDerivedTypes": false, @@ -840,7 +835,6 @@ public void GetConfiguration_ValidCustomConfiguration_OverridesBuiltInConfigurat "legacyFormatter": false, "testFramework": false, "assertions": false, - "azTypesViaRegistry": false, "optionalModuleNames": false, "localDeploy": false, "resourceDerivedTypes": false, diff --git a/src/Bicep.Core.UnitTests/Features/FeatureProviderOverrides.cs b/src/Bicep.Core.UnitTests/Features/FeatureProviderOverrides.cs index 3ad25aa47c8..96a794fda6d 100644 --- a/src/Bicep.Core.UnitTests/Features/FeatureProviderOverrides.cs +++ b/src/Bicep.Core.UnitTests/Features/FeatureProviderOverrides.cs @@ -17,7 +17,6 @@ public record FeatureProviderOverrides( bool? LegacyFormatterEnabled = default, bool? TestFrameworkEnabled = default, bool? AssertsEnabled = default, - bool? AzTypesViaRegistryEnabled = default, bool? OptionalModuleNamesEnabled = default, bool? LocalDeployEnabled = default, bool? ResourceDerivedTypesEnabled = default, @@ -36,7 +35,6 @@ public FeatureProviderOverrides( bool? LegacyFormatterEnabled = default, bool? TestFrameworkEnabled = default, bool? AssertsEnabled = default, - bool? AzTypesViaRegistryEnabled = default, bool? OptionalModuleNamesEnabled = default, bool? LocalDeployEnabled = default, bool? ResourceDerivedTypesEnabled = default, @@ -54,7 +52,6 @@ public FeatureProviderOverrides( LegacyFormatterEnabled, TestFrameworkEnabled, AssertsEnabled, - AzTypesViaRegistryEnabled, OptionalModuleNamesEnabled, LocalDeployEnabled, ResourceDerivedTypesEnabled, diff --git a/src/Bicep.Core.UnitTests/Features/OverriddenFeatureProvider.cs b/src/Bicep.Core.UnitTests/Features/OverriddenFeatureProvider.cs index d56563339ef..0fc25cb6720 100644 --- a/src/Bicep.Core.UnitTests/Features/OverriddenFeatureProvider.cs +++ b/src/Bicep.Core.UnitTests/Features/OverriddenFeatureProvider.cs @@ -34,8 +34,6 @@ public OverriddenFeatureProvider(IFeatureProvider features, FeatureProviderOverr public bool AssertsEnabled => overrides.AssertsEnabled ?? features.AssertsEnabled; - public bool AzTypesViaRegistryEnabled => overrides.AzTypesViaRegistryEnabled ?? features.AzTypesViaRegistryEnabled; - public bool OptionalModuleNamesEnabled => overrides.OptionalModuleNamesEnabled ?? features.OptionalModuleNamesEnabled; public bool LocalDeployEnabled => overrides.LocalDeployEnabled ?? features.LocalDeployEnabled; diff --git a/src/Bicep.Core.UnitTests/Utils/TestTypeHelper.cs b/src/Bicep.Core.UnitTests/Utils/TestTypeHelper.cs index 34519ce38d6..de95510c41d 100644 --- a/src/Bicep.Core.UnitTests/Utils/TestTypeHelper.cs +++ b/src/Bicep.Core.UnitTests/Utils/TestTypeHelper.cs @@ -48,7 +48,7 @@ public static IResourceTypeLoader CreateResourceTypeLoaderWithTypes(IEnumerable< public static IResourceTypeProviderFactory CreateResourceTypeLoaderFactory(IResourceTypeProvider provider) { var factory = StrictMock.Of(); - factory.Setup(m => m.GetResourceTypeProvider(It.IsAny(), It.IsAny(), It.IsAny())).Returns(new ResultWithDiagnosticBuilder(provider)); + factory.Setup(m => m.GetResourceTypeProvider(It.IsAny(), It.IsAny())).Returns(new ResultWithDiagnosticBuilder(provider)); factory.Setup(m => m.GetBuiltInAzResourceTypesProvider()).Returns(provider); return factory.Object; } diff --git a/src/Bicep.Core/Configuration/ExperimentalFeaturesEnabled.cs b/src/Bicep.Core/Configuration/ExperimentalFeaturesEnabled.cs index d6a059ccc8b..ef157e0e8fe 100644 --- a/src/Bicep.Core/Configuration/ExperimentalFeaturesEnabled.cs +++ b/src/Bicep.Core/Configuration/ExperimentalFeaturesEnabled.cs @@ -16,7 +16,6 @@ public record ExperimentalFeaturesEnabled( bool LegacyFormatter, bool TestFramework, bool Assertions, - bool azTypesViaRegistry, bool OptionalModuleNames, bool LocalDeploy, bool ResourceDerivedTypes, diff --git a/src/Bicep.Core/CoreResources.Designer.cs b/src/Bicep.Core/CoreResources.Designer.cs index 9a866a14927..67eb8a5e41f 100644 --- a/src/Bicep.Core/CoreResources.Designer.cs +++ b/src/Bicep.Core/CoreResources.Designer.cs @@ -177,15 +177,6 @@ internal static string ExperimentalFeatureNames_Asserts { } } - /// - /// Looks up a localized string similar to Dynamic type loading. - /// - internal static string ExperimentalFeatureNames_AzTypesViaRegistry { - get { - return ResourceManager.GetString("ExperimentalFeatureNames_AzTypesViaRegistry", resourceCulture); - } - } - /// /// Looks up a localized string similar to Extensibility. /// diff --git a/src/Bicep.Core/CoreResources.resx b/src/Bicep.Core/CoreResources.resx index 8509bb101cd..bd718628cff 100644 --- a/src/Bicep.Core/CoreResources.resx +++ b/src/Bicep.Core/CoreResources.resx @@ -484,9 +484,6 @@ Asserts - - Dynamic type loading - Extensibility diff --git a/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs b/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs index 0b844abb5a4..9293fbe35c7 100644 --- a/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs +++ b/src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs @@ -1774,10 +1774,6 @@ public Diagnostic InvalidExtension_NotABuiltInExtension(Uri? configFileUri, stri "BCP398", $"""Extension {name} is incorrectly configured in the {BuildBicepConfigurationClause(configFileUri)}. It is configured as built-in in the "{RootConfiguration.ExtensionsKey}" section, but no built-in extension exists."""); - public Diagnostic FetchingAzTypesRequiresExperimentalFeature() => CoreError( - "BCP399", - $"Fetching az types from the registry requires enabling EXPERIMENTAL feature \"{nameof(ExperimentalFeaturesEnabled.azTypesViaRegistry)}\"."); - public Diagnostic SpreadOperatorUnsupportedInLocation(SpreadExpressionSyntax spread) => CoreError( "BCP401", $"The spread operator \"{spread.Ellipsis.Text}\" is not permitted in this location."); diff --git a/src/Bicep.Core/Features/FeatureProvider.cs b/src/Bicep.Core/Features/FeatureProvider.cs index e78473bd135..7da9102e4b5 100644 --- a/src/Bicep.Core/Features/FeatureProvider.cs +++ b/src/Bicep.Core/Features/FeatureProvider.cs @@ -38,8 +38,6 @@ public FeatureProvider(RootConfiguration configuration) public static TraceVerbosity TracingVerbosity => ReadEnumEnvVar("BICEP_TRACING_VERBOSITY", TraceVerbosity.Basic); - public bool AzTypesViaRegistryEnabled => configuration.ExperimentalFeaturesEnabled.azTypesViaRegistry; - public bool OptionalModuleNamesEnabled => configuration.ExperimentalFeaturesEnabled.OptionalModuleNames; public bool LocalDeployEnabled => configuration.ExperimentalFeaturesEnabled.LocalDeploy; diff --git a/src/Bicep.Core/Features/IFeatureProvider.cs b/src/Bicep.Core/Features/IFeatureProvider.cs index 566cb512383..b07d77bf392 100644 --- a/src/Bicep.Core/Features/IFeatureProvider.cs +++ b/src/Bicep.Core/Features/IFeatureProvider.cs @@ -17,8 +17,6 @@ public interface IFeatureProvider bool SourceMappingEnabled { get; } - bool AzTypesViaRegistryEnabled { get; } - bool LegacyFormatterEnabled { get; } bool TestFrameworkEnabled { get; } @@ -47,7 +45,6 @@ public interface IFeatureProvider (ExtensibilityEnabled, CoreResources.ExperimentalFeatureNames_Extensibility, true, true), (ResourceTypedParamsAndOutputsEnabled, CoreResources.ExperimentalFeatureNames_ResourceTypedParamsAndOutputs, true, false), (SourceMappingEnabled, CoreResources.ExperimentalFeatureNames_SourceMapping, true, false), - (AzTypesViaRegistryEnabled, CoreResources.ExperimentalFeatureNames_AzTypesViaRegistry, true, false), (TestFrameworkEnabled, CoreResources.ExperimentalFeatureNames_TestFramework, false, false), (AssertsEnabled, CoreResources.ExperimentalFeatureNames_Asserts, true, true), (OptionalModuleNamesEnabled, CoreResources.ExperimentalFeatureNames_OptionalModuleNames, true, false), diff --git a/src/Bicep.Core/Semantics/Namespaces/AzNamespaceType.cs b/src/Bicep.Core/Semantics/Namespaces/AzNamespaceType.cs index fe603d85b40..42f666b1220 100644 --- a/src/Bicep.Core/Semantics/Namespaces/AzNamespaceType.cs +++ b/src/Bicep.Core/Semantics/Namespaces/AzNamespaceType.cs @@ -525,12 +525,7 @@ public static NamespaceType Create(string? aliasName, ResourceScope scope, IReso { return new NamespaceType( aliasName ?? BuiltInName, - new NamespaceSettings( - IsSingleton: true, - BicepExtensionName: BuiltInName, - ConfigurationType: null, - TemplateExtensionName: "AzureResourceManager", - TemplateExtensionVersion: EmbeddedAzExtensionVersion), + Settings, ImmutableArray.Empty, Overloads.Where(x => x.IsVisible(scope, sourceFileKind)).Select(x => x.Value), ImmutableArray.Empty, diff --git a/src/Bicep.Core/Semantics/Namespaces/NamespaceProvider.cs b/src/Bicep.Core/Semantics/Namespaces/NamespaceProvider.cs index b59160d4458..abc410958ac 100644 --- a/src/Bicep.Core/Semantics/Namespaces/NamespaceProvider.cs +++ b/src/Bicep.Core/Semantics/Namespaces/NamespaceProvider.cs @@ -4,6 +4,7 @@ using System.Collections.Immutable; using System.Diagnostics; using System.Net.Http.Headers; +using System.Security.Cryptography; using Bicep.Core.Configuration; using Bicep.Core.Diagnostics; using Bicep.Core.Extensions; @@ -13,6 +14,8 @@ using Bicep.Core.Syntax.Visitors; using Bicep.Core.TypeSystem; using Bicep.Core.TypeSystem.Providers; +using Bicep.Core.TypeSystem.Providers.Az; +using Bicep.Core.TypeSystem.Providers.ThirdParty; using Bicep.Core.TypeSystem.Types; using Bicep.Core.Workspaces; @@ -117,7 +120,7 @@ private TypeSymbol GetNamespaceType( if (artifactFileLookup.ArtifactLookup.TryGetValue(syntax, out var artifact)) { var aliasName = syntax.Alias?.IdentifierName; - if (GetNamespaceTypeForArtifact(features, artifact, sourceFile, targetScope, aliasName).IsSuccess(out var namespaceType, out var errorBuilder)) + if (GetNamespaceTypeForArtifact(artifact, sourceFile, targetScope, aliasName).IsSuccess(out var namespaceType, out var errorBuilder)) { return namespaceType; } @@ -149,7 +152,7 @@ protected virtual TypeSymbol GetNamespaceTypeForConfigManagedExtension( if (artifact is { }) { // not a built-in extension - if (GetNamespaceTypeForArtifact(features, artifact, sourceFile, targetScope, aliasName).IsSuccess(out var namespaceType, out var errorBuilder)) + if (GetNamespaceTypeForArtifact(artifact, sourceFile, targetScope, aliasName).IsSuccess(out var namespaceType, out var errorBuilder)) { return namespaceType; } @@ -181,25 +184,19 @@ protected virtual TypeSymbol GetNamespaceTypeForConfigManagedExtension( return ErrorType.Create(diagBuilder.InvalidExtension_NotABuiltInExtension(rootConfig.ConfigFileUri, extensionName)); } - private ResultWithDiagnosticBuilder GetNamespaceTypeForArtifact(IFeatureProvider features, ArtifactResolutionInfo artifact, BicepSourceFile sourceFile, ResourceScope targetScope, string? aliasName) + private ResultWithDiagnosticBuilder GetNamespaceTypeForArtifact(ArtifactResolutionInfo artifact, BicepSourceFile sourceFile, ResourceScope targetScope, string? aliasName) { if (!artifact.Result.IsSuccess(out var typesTgzUri, out var errorBuilder)) { return new(errorBuilder); } - var useAzLoader = artifact.Reference is OciArtifactReference ociArtifact && ociArtifact.Repository.EndsWith("/az"); - if (useAzLoader && !features.AzTypesViaRegistryEnabled) - { - return new(x => x.FetchingAzTypesRequiresExperimentalFeature()); - } - - if (!resourceTypeProviderFactory.GetResourceTypeProvider(artifact.Reference, typesTgzUri, useAzLoader: useAzLoader).IsSuccess(out var typeProvider, out errorBuilder)) + if (!resourceTypeProviderFactory.GetResourceTypeProvider(artifact.Reference, typesTgzUri).IsSuccess(out var typeProvider, out errorBuilder)) { return new(errorBuilder); } - if (useAzLoader) + if (typeProvider is AzResourceTypeProvider) { return new(AzNamespaceType.Create(aliasName, targetScope, typeProvider, sourceFile.FileKind)); } diff --git a/src/Bicep.Core/Semantics/Namespaces/ThirdPartyNamespaceType.cs b/src/Bicep.Core/Semantics/Namespaces/ThirdPartyNamespaceType.cs index ef09d53b473..c3563ba3a4a 100644 --- a/src/Bicep.Core/Semantics/Namespaces/ThirdPartyNamespaceType.cs +++ b/src/Bicep.Core/Semantics/Namespaces/ThirdPartyNamespaceType.cs @@ -11,17 +11,10 @@ namespace Bicep.Core.Semantics.Namespaces { public static class ThirdPartyNamespaceType { - public static NamespaceSettings Settings { get; } = new( - IsSingleton: true, - BicepExtensionName: string.Empty, - ConfigurationType: null, - TemplateExtensionName: string.Empty, - TemplateExtensionVersion: string.Empty); - public static NamespaceType Create(string? aliasName, IResourceTypeProvider resourceTypeProvider, ArtifactReference? artifact) { - // NamespaceConfig is not null - if (resourceTypeProvider is ThirdPartyResourceTypeProvider thirdPartyProvider && thirdPartyProvider.GetNamespaceConfiguration() is NamespaceConfiguration namespaceConfig && namespaceConfig != null) + if (resourceTypeProvider is ThirdPartyResourceTypeProvider thirdPartyProvider && + thirdPartyProvider.GetNamespaceConfiguration() is NamespaceConfiguration namespaceConfig) { return new NamespaceType( aliasName ?? namespaceConfig.Name, @@ -39,9 +32,7 @@ public static NamespaceType Create(string? aliasName, IResourceTypeProvider reso artifact); } - // NamespaceConfig is required to be set for 3PProviders throw new ArgumentException($"Please provide the following required Settings properties: Name, Version, & IsSingleton."); - } } } diff --git a/src/Bicep.Core/TypeSystem/Providers/Az/AzResourceTypeLoader.cs b/src/Bicep.Core/TypeSystem/Providers/Az/AzResourceTypeLoader.cs index add52230965..5fb3035c9a7 100644 --- a/src/Bicep.Core/TypeSystem/Providers/Az/AzResourceTypeLoader.cs +++ b/src/Bicep.Core/TypeSystem/Providers/Az/AzResourceTypeLoader.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Collections.Immutable; using Azure.Bicep.Types; +using Azure.Bicep.Types.Index; using Bicep.Core.Extensions; using Bicep.Core.Resources; using Bicep.Core.TypeSystem.Types; @@ -15,11 +16,11 @@ public class AzResourceTypeLoader : IResourceTypeLoader private readonly ImmutableDictionary availableTypes; private readonly ImmutableDictionary>> availableFunctions; - public AzResourceTypeLoader(ITypeLoader typeLoader) + public AzResourceTypeLoader(ITypeLoader typeLoader, TypeIndex? typeIndex = null) { this.typeLoader = typeLoader; resourceTypeFactory = new AzResourceTypeFactory(); - var indexedTypes = typeLoader.LoadTypeIndex(); + var indexedTypes = typeIndex ?? typeLoader.LoadTypeIndex(); availableTypes = indexedTypes.Resources.ToImmutableDictionary( kvp => ResourceTypeReference.Parse(kvp.Key), kvp => kvp.Value); diff --git a/src/Bicep.Core/TypeSystem/Providers/IResourceTypeProviderFactory.cs b/src/Bicep.Core/TypeSystem/Providers/IResourceTypeProviderFactory.cs index fb4635ff955..1c96781ac0a 100644 --- a/src/Bicep.Core/TypeSystem/Providers/IResourceTypeProviderFactory.cs +++ b/src/Bicep.Core/TypeSystem/Providers/IResourceTypeProviderFactory.cs @@ -8,7 +8,7 @@ namespace Bicep.Core.TypeSystem.Providers { public interface IResourceTypeProviderFactory { - ResultWithDiagnosticBuilder GetResourceTypeProvider(ArtifactReference? artifactReference, Uri typesTgzUri, bool useAzLoader); + ResultWithDiagnosticBuilder GetResourceTypeProvider(ArtifactReference? artifactReference, Uri typesTgzUri); IResourceTypeProvider GetBuiltInAzResourceTypesProvider(); } diff --git a/src/Bicep.Core/TypeSystem/Providers/ResourceTypeProviderFactory.cs b/src/Bicep.Core/TypeSystem/Providers/ResourceTypeProviderFactory.cs index dd1d671000b..f2a85ccecb2 100644 --- a/src/Bicep.Core/TypeSystem/Providers/ResourceTypeProviderFactory.cs +++ b/src/Bicep.Core/TypeSystem/Providers/ResourceTypeProviderFactory.cs @@ -17,8 +17,7 @@ namespace Bicep.Core.TypeSystem.Providers { public class ResourceTypeProviderFactory : IResourceTypeProviderFactory { - private record ResourceTypeLoaderKey(Uri TypesTgzUri, bool UseAzLoader); - private readonly ConcurrentDictionary> cachedResourceTypeLoaders = new(); + private readonly ConcurrentDictionary> cachedResourceTypeLoaders = new(); private readonly IFileSystem fileSystem; public ResourceTypeProviderFactory(IFileSystem fileSystem) @@ -26,22 +25,25 @@ public ResourceTypeProviderFactory(IFileSystem fileSystem) this.fileSystem = fileSystem; } - public ResultWithDiagnosticBuilder GetResourceTypeProvider(ArtifactReference? artifactReference, Uri typesTgzUri, bool useAzLoader) + public ResultWithDiagnosticBuilder GetResourceTypeProvider(ArtifactReference? artifactReference, Uri typesTgzUri) { - var key = new ResourceTypeLoaderKey(typesTgzUri, useAzLoader); // TODO invalidate this cache on module force restore - return cachedResourceTypeLoaders.GetOrAdd(key, _ => + return cachedResourceTypeLoaders.GetOrAdd(typesTgzUri, _ => { try { using var fileStream = fileSystem.File.OpenRead(typesTgzUri.LocalPath); var typesLoader = OciTypeLoader.FromStream(fileStream); - if (key.UseAzLoader) + var typeIndex = typesLoader.LoadTypeIndex(); + var useAzLoader = typeIndex.Settings?.Name == AzNamespaceType.Settings.TemplateExtensionName; + + if (useAzLoader) { - return new(new AzResourceTypeProvider(new AzResourceTypeLoader(typesLoader))); + return new(new AzResourceTypeProvider(new AzResourceTypeLoader(typesLoader, typeIndex))); } - return new(new ThirdPartyResourceTypeProvider(new ThirdPartyResourceTypeLoader(typesLoader))); + + return new(new ThirdPartyResourceTypeProvider(new ThirdPartyResourceTypeLoader(typesLoader, typeIndex))); } catch (Exception ex) { diff --git a/src/Bicep.Core/TypeSystem/Providers/ThirdParty/ThirdPartyResourceTypeLoader.cs b/src/Bicep.Core/TypeSystem/Providers/ThirdParty/ThirdPartyResourceTypeLoader.cs index e0b1d24ee03..0602ee1f160 100644 --- a/src/Bicep.Core/TypeSystem/Providers/ThirdParty/ThirdPartyResourceTypeLoader.cs +++ b/src/Bicep.Core/TypeSystem/Providers/ThirdParty/ThirdPartyResourceTypeLoader.cs @@ -18,11 +18,11 @@ public record NamespaceConfiguration(string Name, string Version, bool IsSinglet private readonly TypeSettings? typeSettings; private readonly CrossFileTypeReference? fallbackResourceType; - public ThirdPartyResourceTypeLoader(ITypeLoader typeLoader) + public ThirdPartyResourceTypeLoader(ITypeLoader typeLoader, TypeIndex? typeIndex = null) { this.typeLoader = typeLoader; resourceTypeFactory = new ExtensibilityResourceTypeFactory(); - var indexedTypes = typeLoader.LoadTypeIndex(); + var indexedTypes = typeIndex ?? typeLoader.LoadTypeIndex(); availableTypes = indexedTypes.Resources.ToImmutableDictionary( kvp => ResourceTypeReference.Parse(kvp.Key), kvp => kvp.Value); @@ -56,7 +56,7 @@ public ResourceTypeComponents LoadType(ResourceTypeReference reference) return null; } - public NamespaceConfiguration? LoadNamespaceConfiguration() + public NamespaceConfiguration LoadNamespaceConfiguration() { if (typeSettings == null) { diff --git a/src/vscode-bicep/schemas/bicepconfig.schema.json b/src/vscode-bicep/schemas/bicepconfig.schema.json index 0225799162b..6afdf5475bd 100644 --- a/src/vscode-bicep/schemas/bicepconfig.schema.json +++ b/src/vscode-bicep/schemas/bicepconfig.schema.json @@ -797,10 +797,6 @@ "type": "boolean", "description": "Allows you to author boolean assertions using the assert keyword. Should be enabled in tandem with 'testFramework'. See https://aka.ms/bicep/experimental-features#assertions" }, - "azTypesViaRegistry": { - "description": "Enables dynamic type loading for resource type providers. See https://aka.ms/bicep/experimental-features#aztypesviaregistry", - "type": "boolean" - }, "localDeploy": { "type": "boolean", "description": "Enabling this feature turns on support for local Bicep deployments. See https://aka.ms/bicep/experimental-features#localdeploy"