Skip to content

Commit

Permalink
Remove 'azTypesViaRegistry' feature
Browse files Browse the repository at this point in the history
  • Loading branch information
anthony-c-martin committed Aug 30, 2024
1 parent 451c860 commit 9937570
Show file tree
Hide file tree
Showing 25 changed files with 52 additions and 118 deletions.
3 changes: 0 additions & 3 deletions docs/experimental-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]' 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).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
]
},
"experimentalFeaturesEnabled": {
"extensibility": true,
"azTypesViaRegistry": true
"extensibility": true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"credentialPrecedence": ["AzureCLI"]
},
"experimentalFeaturesEnabled": {
"extensibility": true,
"azTypesViaRegistry": true
"extensibility": true
}
}
26 changes: 17 additions & 9 deletions src/Bicep.Core.IntegrationTests/AzTypesViaRegistryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,13 +25,23 @@ public class AzTypesViaRegistryTests : TestBase
{
private async Task<ServiceBuilder> 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);
Expand All @@ -52,11 +63,8 @@ private async Task<ServiceBuilder> 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]
Expand All @@ -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(
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
19 changes: 2 additions & 17 deletions src/Bicep.Core.IntegrationTests/ExtensionRegistryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ public void GetBuiltInConfiguration_NoParameter_ReturnsBuiltInConfigurationWithA
"legacyFormatter": false,
"testFramework": false,
"assertions": false,
"azTypesViaRegistry": false,
"optionalModuleNames": false,
"localDeploy": false,
"resourceDerivedTypes": false,
Expand Down Expand Up @@ -188,7 +187,6 @@ public void GetBuiltInConfiguration_DisableAllAnalyzers_ReturnsBuiltInConfigurat
"legacyFormatter": false,
"testFramework": false,
"assertions": false,
"azTypesViaRegistry": false,
"optionalModuleNames": false,
"localDeploy": false,
"resourceDerivedTypes": false,
Expand Down Expand Up @@ -295,7 +293,6 @@ public void GetBuiltInConfiguration_DisableAnalyzers_ReturnsBuiltInConfiguration
"legacyFormatter": false,
"testFramework": false,
"assertions": false,
"azTypesViaRegistry": false,
"optionalModuleNames": false,
"localDeploy": false,
"resourceDerivedTypes": false,
Expand Down Expand Up @@ -388,7 +385,6 @@ public void GetBuiltInConfiguration_EnableExperimentalFeature_ReturnsBuiltInConf
LegacyFormatter: false,
TestFramework: false,
Assertions: false,
azTypesViaRegistry: false,
OptionalModuleNames: false,
LocalDeploy: false,
ResourceDerivedTypes: false,
Expand Down Expand Up @@ -474,7 +470,6 @@ public void GetBuiltInConfiguration_EnableExperimentalFeature_ReturnsBuiltInConf
"legacyFormatter": false,
"testFramework": false,
"assertions": false,
"azTypesViaRegistry": false,
"optionalModuleNames": false,
"localDeploy": false,
"resourceDerivedTypes": false,
Expand Down Expand Up @@ -840,7 +835,6 @@ public void GetConfiguration_ValidCustomConfiguration_OverridesBuiltInConfigurat
"legacyFormatter": false,
"testFramework": false,
"assertions": false,
"azTypesViaRegistry": false,
"optionalModuleNames": false,
"localDeploy": false,
"resourceDerivedTypes": false,
Expand Down
3 changes: 0 additions & 3 deletions src/Bicep.Core.UnitTests/Features/FeatureProviderOverrides.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -54,7 +52,6 @@ public FeatureProviderOverrides(
LegacyFormatterEnabled,
TestFrameworkEnabled,
AssertsEnabled,
AzTypesViaRegistryEnabled,
OptionalModuleNamesEnabled,
LocalDeployEnabled,
ResourceDerivedTypesEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Bicep.Core.UnitTests/Utils/TestTypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static IResourceTypeLoader CreateResourceTypeLoaderWithTypes(IEnumerable<
public static IResourceTypeProviderFactory CreateResourceTypeLoaderFactory(IResourceTypeProvider provider)
{
var factory = StrictMock.Of<IResourceTypeProviderFactory>();
factory.Setup(m => m.GetResourceTypeProvider(It.IsAny<ArtifactReference?>(), It.IsAny<Uri>(), It.IsAny<bool>())).Returns(new ResultWithDiagnosticBuilder<IResourceTypeProvider>(provider));
factory.Setup(m => m.GetResourceTypeProvider(It.IsAny<ArtifactReference?>(), It.IsAny<Uri>())).Returns(new ResultWithDiagnosticBuilder<IResourceTypeProvider>(provider));
factory.Setup(m => m.GetBuiltInAzResourceTypesProvider()).Returns(provider);
return factory.Object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public record ExperimentalFeaturesEnabled(
bool LegacyFormatter,
bool TestFramework,
bool Assertions,
bool azTypesViaRegistry,
bool OptionalModuleNames,
bool LocalDeploy,
bool ResourceDerivedTypes,
Expand Down
9 changes: 0 additions & 9 deletions src/Bicep.Core/CoreResources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions src/Bicep.Core/CoreResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,6 @@
<data name="ExperimentalFeatureNames_Asserts" xml:space="preserve">
<value>Asserts</value>
</data>
<data name="ExperimentalFeatureNames_AzTypesViaRegistry" xml:space="preserve">
<value>Dynamic type loading</value>
</data>
<data name="ExperimentalFeatureNames_Extensibility" xml:space="preserve">
<value>Extensibility</value>
</data>
Expand Down
4 changes: 0 additions & 4 deletions src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
2 changes: 0 additions & 2 deletions src/Bicep.Core/Features/FeatureProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions src/Bicep.Core/Features/IFeatureProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public interface IFeatureProvider

bool SourceMappingEnabled { get; }

bool AzTypesViaRegistryEnabled { get; }

bool LegacyFormatterEnabled { get; }

bool TestFrameworkEnabled { get; }
Expand Down Expand Up @@ -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),
Expand Down
7 changes: 1 addition & 6 deletions src/Bicep.Core/Semantics/Namespaces/AzNamespaceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeProperty>.Empty,
Overloads.Where(x => x.IsVisible(scope, sourceFileKind)).Select(x => x.Value),
ImmutableArray<BannedFunction>.Empty,
Expand Down
19 changes: 8 additions & 11 deletions src/Bicep.Core/Semantics/Namespaces/NamespaceProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -181,25 +184,19 @@ protected virtual TypeSymbol GetNamespaceTypeForConfigManagedExtension(
return ErrorType.Create(diagBuilder.InvalidExtension_NotABuiltInExtension(rootConfig.ConfigFileUri, extensionName));
}

private ResultWithDiagnosticBuilder<NamespaceType> GetNamespaceTypeForArtifact(IFeatureProvider features, ArtifactResolutionInfo artifact, BicepSourceFile sourceFile, ResourceScope targetScope, string? aliasName)
private ResultWithDiagnosticBuilder<NamespaceType> 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));
}
Expand Down
Loading

0 comments on commit 9937570

Please sign in to comment.