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 40d70c0
Show file tree
Hide file tree
Showing 26 changed files with 59 additions and 122 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
}
}
33 changes: 22 additions & 11 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 @@ -22,15 +23,28 @@ namespace Bicep.Core.IntegrationTests
[TestClass]
public class AzTypesViaRegistryTests : TestBase
{
private static readonly string EmptyIndexJson = """
{
"resources": {},
"resourceFunctions": {},
"settings": {
"name": "AzureResourceManager",
"version": "1.2.3",
"isSingleton": true
}
}
""";


private async Task<ServiceBuilder> GetServices()
{
var indexJson = FileHelper.SaveResultFile(TestContext, "types/index.json", """{"resources": {}, "resourceFunctions": {}}""");
var indexJson = FileHelper.SaveResultFile(TestContext, "types/index.json", EmptyIndexJson);

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 +66,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 +79,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 +154,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 Expand Up @@ -271,7 +282,7 @@ public async Task Az_namespace_can_be_loaded_dynamically_using_extension_configu
"1.0.0-fake");
var services = await ServicesWithTestExtensionArtifact(
artifactRegistryAddress,
ThirdPartyTypeHelper.GetTypesTgzBytesFromFiles(("index.json", """{"resources": {}, "resourceFunctions": {}}""")));
ThirdPartyTypeHelper.GetTypesTgzBytesFromFiles(("index.json", EmptyIndexJson)));
services = services.WithConfigurationPatch(c => c.WithExtensions($$"""
{
"az": "{{artifactRegistryAddress.ToSpecificationString(':')}}"
Expand All @@ -284,7 +295,7 @@ extension az
//ASSERT
result.Should().GenerateATemplate();
result.Template.Should().NotBeNull();
result.Template.Should().HaveValueAtPath("$.imports.az.version", AzNamespaceType.EmbeddedAzExtensionVersion);
result.Template.Should().HaveValueAtPath("$.imports.az.version", AzNamespaceType.Settings.TemplateExtensionVersion);
}
}
}
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 @@ -31,7 +31,7 @@ public async Task ExtensionNameAndVersionAreUsedAsCacheKeys()
var (clientFactory, _) = RegistryHelper.CreateMockRegistryClients(repositoryNames.Select(name => (registry, $"{repositoryPath}/{name}")).ToArray());

var services = new ServiceBuilder()
.WithFeatureOverrides(new(TestContext, ExtensibilityEnabled: true, AzTypesViaRegistryEnabled: true))
.WithFeatureOverrides(new(TestContext, ExtensibilityEnabled: true))
.WithContainerRegistryClientFactory(clientFactory);

foreach (var repoName in repositoryNames)
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
9 changes: 2 additions & 7 deletions src/Bicep.Core/Semantics/Namespaces/AzNamespaceType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static class AzNamespaceType
{
public const string BuiltInName = "az";
public const string GetSecretFunctionName = "getSecret";
public static readonly string EmbeddedAzExtensionVersion = typeof(AzTypeLoader).Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version
private static readonly string EmbeddedAzExtensionVersion = typeof(AzTypeLoader).Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version
?? throw new UnreachableException("The 'Azure.Bicep.Types.Az' assembly should always have a file version attribute.");

private static readonly Lazy<IResourceTypeProvider> TypeProviderLazy
Expand Down 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
Loading

0 comments on commit 40d70c0

Please sign in to comment.