diff --git a/.vscode/cspell.json b/.vscode/cspell.json index 470cebeef2cf..7abf54695e50 100644 --- a/.vscode/cspell.json +++ b/.vscode/cspell.json @@ -74,6 +74,7 @@ "cpus", "cref", "Dapr", + "decompile", "deduplication", "deletesas", "deserializable", diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/Azure.ResourceManager.Resources.Bicep.sln b/sdk/resources/Azure.ResourceManager.Resources.Bicep/Azure.ResourceManager.Resources.Bicep.sln new file mode 100644 index 000000000000..fc77d7edcb48 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/Azure.ResourceManager.Resources.Bicep.sln @@ -0,0 +1,65 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30309.148 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{C4398841-2364-4283-9193-6436A82922AA}") = "Azure.ResourceManager.Resources.Bicep", "src\Azure.ResourceManager.Resources.Bicep.csproj", "{67A00D95-333C-481C-8F00-C5E096E6AEB2}" +EndProject +Project("{C4398841-2364-4283-9193-6436A82922AA}") = "Azure.ResourceManager.Resources.Bicep.Tests", "tests\Azure.ResourceManager.Resources.Bicep.Tests.csproj", "{FFDAD11E-3374-405A-878A-853F23D8C501}" +EndProject +Project("{C4398841-2364-4283-9193-6436A82922AA}") = "Azure.ResourceManager.Resources.Bicep.Samples", "samples\Azure.ResourceManager.Resources.Bicep.Samples.csproj", "{597D41E8-3180-41D3-9B87-B16908E85E15}" +EndProject +Global + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {3E85CC71-2C11-4582-95B4-1363982FBC1E} + EndGlobalSection + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Debug|x64.ActiveCfg = Debug|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Debug|x64.Build.0 = Debug|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Debug|x86.ActiveCfg = Debug|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Debug|x86.Build.0 = Debug|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Release|Any CPU.Build.0 = Release|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Release|x64.ActiveCfg = Release|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Release|x64.Build.0 = Release|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Release|x86.ActiveCfg = Release|Any CPU + {67A00D95-333C-481C-8F00-C5E096E6AEB2}.Release|x86.Build.0 = Release|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Debug|x64.ActiveCfg = Debug|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Debug|x64.Build.0 = Debug|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Debug|x86.ActiveCfg = Debug|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Debug|x86.Build.0 = Debug|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Release|Any CPU.Build.0 = Release|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Release|x64.ActiveCfg = Release|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Release|x64.Build.0 = Release|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Release|x86.ActiveCfg = Release|Any CPU + {FFDAD11E-3374-405A-878A-853F23D8C501}.Release|x86.Build.0 = Release|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Debug|Any CPU.Build.0 = Debug|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Debug|x64.ActiveCfg = Debug|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Debug|x64.Build.0 = Debug|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Debug|x86.ActiveCfg = Debug|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Debug|x86.Build.0 = Debug|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Release|Any CPU.ActiveCfg = Release|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Release|Any CPU.Build.0 = Release|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Release|x64.ActiveCfg = Release|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Release|x64.Build.0 = Release|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Release|x86.ActiveCfg = Release|Any CPU + {597D41E8-3180-41D3-9B87-B16908E85E15}.Release|x86.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/CHANGELOG.md b/sdk/resources/Azure.ResourceManager.Resources.Bicep/CHANGELOG.md new file mode 100644 index 000000000000..1a85987a15b9 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/CHANGELOG.md @@ -0,0 +1,19 @@ +# Release History + +## 1.0.0-beta.1 (Unreleased) + + + +### Features Added + +This package follows the [new Azure SDK guidelines](https://azure.github.io/azure-sdk/general_introduction.html), and provides many core capabilities: + + - Support MSAL.NET, Azure.Identity is out of box for supporting MSAL.NET. + - Support [OpenTelemetry](https://opentelemetry.io/) for distributed tracing. + - HTTP pipeline with custom policies. + - Better error-handling. + - Support uniform telemetry across all languages. + +This package is a Public Preview version, so expect incompatible changes in subsequent releases as we improve the product. To provide feedback, submit an issue in our [Azure SDK for .NET GitHub repo](https://github.com/Azure/azure-sdk-for-net/issues). + +> NOTE: For more information about unified authentication, please refer to [Microsoft Azure Identity documentation for .NET](https://docs.microsoft.com//dotnet/api/overview/azure/identity-readme?view=azure-dotnet). \ No newline at end of file diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/Directory.Build.props b/sdk/resources/Azure.ResourceManager.Resources.Bicep/Directory.Build.props new file mode 100644 index 000000000000..1a9611bd4924 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/Directory.Build.props @@ -0,0 +1,6 @@ + + + + diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/README.md b/sdk/resources/Azure.ResourceManager.Resources.Bicep/README.md new file mode 100644 index 000000000000..018b94a8403a --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/README.md @@ -0,0 +1,80 @@ +# Microsoft Azure Bicep management client library for .NET + +**[Describe the service briefly first.]** + +This library follows the [new Azure SDK guidelines](https://azure.github.io/azure-sdk/general_introduction.html), and provides many core capabilities: + + - Support MSAL.NET, Azure.Identity is out of box for supporting MSAL.NET. + - Support [OpenTelemetry](https://opentelemetry.io/) for distributed tracing. + - HTTP pipeline with custom policies. + - Better error-handling. + - Support uniform telemetry across all languages. + +## Getting started + +### Install the package + +Install the Microsoft Azure Bicep management library for .NET with [NuGet](https://www.nuget.org/): + +```dotnetcli +dotnet add package Azure.ResourceManager.Resources.Bicep --prerelease +``` + +### Prerequisites + +* You must have an [Microsoft Azure subscription](https://azure.microsoft.com/free/dotnet/). + +### Authenticate the Client + +To create an authenticated client and start interacting with Microsoft Azure resources, see the [quickstart guide here](https://github.com/Azure/azure-sdk-for-net/blob/main/doc/dev/mgmt_quickstart.md). + +## Key concepts + +Key concepts of the Microsoft Azure SDK for .NET can be found [here](https://azure.github.io/azure-sdk/dotnet_introduction.html) + +## Documentation + +Documentation is available to help you learn how to use this package: + +- [Quickstart](https://github.com/Azure/azure-sdk-for-net/blob/main/doc/dev/mgmt_quickstart.md). +- [API References](https://docs.microsoft.com/dotnet/api/?view=azure-dotnet). +- [Authentication](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/identity/Azure.Identity/README.md). + +## Examples + +Code samples for using the management library for .NET can be found in the following locations +- [.NET Management Library Code Samples](https://aka.ms/azuresdk-net-mgmt-samples) + +## Troubleshooting + +- File an issue via [GitHub Issues](https://github.com/Azure/azure-sdk-for-net/issues). +- Check [previous questions](https://stackoverflow.com/questions/tagged/azure+.net) or ask new ones on Stack Overflow using Azure and .NET tags. + +## Next steps + +For more information about Microsoft Azure SDK, see [this website](https://azure.github.io/azure-sdk/). + +## Contributing + +For details on contributing to this repository, see the [contributing +guide][cg]. + +This project welcomes contributions and suggestions. Most contributions +require you to agree to a Contributor License Agreement (CLA) declaring +that you have the right to, and actually do, grant us the rights to use +your contribution. For details, visit . + +When you submit a pull request, a CLA-bot will automatically determine +whether you need to provide a CLA and decorate the PR appropriately +(for example, label, comment). Follow the instructions provided by the +bot. You'll only need to do this action once across all repositories +using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct][coc]. For +more information, see the [Code of Conduct FAQ][coc_faq] or contact + with any other questions or comments. + + +[cg]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/resourcemanager/Azure.ResourceManager/docs/CONTRIBUTING.md +[coc]: https://opensource.microsoft.com/codeofconduct/ +[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/ \ No newline at end of file diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/api/Azure.ResourceManager.Resources.Bicep.net8.0.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/api/Azure.ResourceManager.Resources.Bicep.net8.0.cs new file mode 100644 index 000000000000..270df432f129 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/api/Azure.ResourceManager.Resources.Bicep.net8.0.cs @@ -0,0 +1,66 @@ +namespace Azure.ResourceManager.Resources.Bicep +{ + public partial class AzureResourceManagerResourcesBicepContext : System.ClientModel.Primitives.ModelReaderWriterContext + { + internal AzureResourceManagerResourcesBicepContext() { } + public static Azure.ResourceManager.Resources.Bicep.AzureResourceManagerResourcesBicepContext Default { get { throw null; } } + protected override bool TryGetTypeBuilderCore(System.Type type, out System.ClientModel.Primitives.ModelReaderWriterTypeBuilder builder) { throw null; } + } + public static partial class ResourcesBicepExtensions + { + public static Azure.Response BicepDecompileOperationGroup(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task> BicepDecompileOperationGroupAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } +} +namespace Azure.ResourceManager.Resources.Bicep.Mocking +{ + public partial class MockableResourcesBicepSubscriptionResource : Azure.ResourceManager.ArmResource + { + protected MockableResourcesBicepSubscriptionResource() { } + public virtual Azure.Response BicepDecompileOperationGroup(Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> BicepDecompileOperationGroupAsync(Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } +} +namespace Azure.ResourceManager.Resources.Bicep.Models +{ + public static partial class ArmResourcesBicepModelFactory + { + public static Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationSuccessResponse DecompileOperationSuccessResponse(System.Collections.Generic.IEnumerable files = null, string entryPoint = null) { throw null; } + public static Azure.ResourceManager.Resources.Bicep.Models.FileDefinition FileDefinition(string path = null, string contents = null) { throw null; } + } + public partial class DecompileOperationContent : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public DecompileOperationContent(string template) { } + public string Template { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class DecompileOperationSuccessResponse : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal DecompileOperationSuccessResponse() { } + public string EntryPoint { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Files { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationSuccessResponse System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationSuccessResponse System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class FileDefinition : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal FileDefinition() { } + public string Contents { get { throw null; } } + public string Path { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.FileDefinition System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.FileDefinition System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/api/Azure.ResourceManager.Resources.Bicep.netstandard2.0.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/api/Azure.ResourceManager.Resources.Bicep.netstandard2.0.cs new file mode 100644 index 000000000000..270df432f129 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/api/Azure.ResourceManager.Resources.Bicep.netstandard2.0.cs @@ -0,0 +1,66 @@ +namespace Azure.ResourceManager.Resources.Bicep +{ + public partial class AzureResourceManagerResourcesBicepContext : System.ClientModel.Primitives.ModelReaderWriterContext + { + internal AzureResourceManagerResourcesBicepContext() { } + public static Azure.ResourceManager.Resources.Bicep.AzureResourceManagerResourcesBicepContext Default { get { throw null; } } + protected override bool TryGetTypeBuilderCore(System.Type type, out System.ClientModel.Primitives.ModelReaderWriterTypeBuilder builder) { throw null; } + } + public static partial class ResourcesBicepExtensions + { + public static Azure.Response BicepDecompileOperationGroup(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public static System.Threading.Tasks.Task> BicepDecompileOperationGroupAsync(this Azure.ResourceManager.Resources.SubscriptionResource subscriptionResource, Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } +} +namespace Azure.ResourceManager.Resources.Bicep.Mocking +{ + public partial class MockableResourcesBicepSubscriptionResource : Azure.ResourceManager.ArmResource + { + protected MockableResourcesBicepSubscriptionResource() { } + public virtual Azure.Response BicepDecompileOperationGroup(Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> BicepDecompileOperationGroupAsync(Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent content, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } +} +namespace Azure.ResourceManager.Resources.Bicep.Models +{ + public static partial class ArmResourcesBicepModelFactory + { + public static Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationSuccessResponse DecompileOperationSuccessResponse(System.Collections.Generic.IEnumerable files = null, string entryPoint = null) { throw null; } + public static Azure.ResourceManager.Resources.Bicep.Models.FileDefinition FileDefinition(string path = null, string contents = null) { throw null; } + } + public partial class DecompileOperationContent : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + public DecompileOperationContent(string template) { } + public string Template { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationContent System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class DecompileOperationSuccessResponse : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal DecompileOperationSuccessResponse() { } + public string EntryPoint { get { throw null; } } + public System.Collections.Generic.IReadOnlyList Files { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationSuccessResponse System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationSuccessResponse System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } + public partial class FileDefinition : System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal FileDefinition() { } + public string Contents { get { throw null; } } + public string Path { get { throw null; } } + protected virtual void JsonModelWriteCore(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.FileDefinition System.ClientModel.Primitives.IJsonModel.Create(ref System.Text.Json.Utf8JsonReader reader, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + void System.ClientModel.Primitives.IJsonModel.Write(System.Text.Json.Utf8JsonWriter writer, System.ClientModel.Primitives.ModelReaderWriterOptions options) { } + Azure.ResourceManager.Resources.Bicep.Models.FileDefinition System.ClientModel.Primitives.IPersistableModel.Create(System.BinaryData data, System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + string System.ClientModel.Primitives.IPersistableModel.GetFormatFromOptions(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + System.BinaryData System.ClientModel.Primitives.IPersistableModel.Write(System.ClientModel.Primitives.ModelReaderWriterOptions options) { throw null; } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/assets.json b/sdk/resources/Azure.ResourceManager.Resources.Bicep/assets.json new file mode 100644 index 000000000000..609258334939 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/assets.json @@ -0,0 +1,6 @@ +{ + "AssetsRepo": "Azure/azure-sdk-assets", + "AssetsRepoPrefixPath": "net", + "TagPrefix": "net/bicep/Azure.ResourceManager.Resources.Bicep", + "Tag": "net/bicep/Azure.ResourceManager.Resources.Bicep_f735123855" +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/samples/Azure.ResourceManager.Resources.Bicep.Samples.csproj b/sdk/resources/Azure.ResourceManager.Resources.Bicep/samples/Azure.ResourceManager.Resources.Bicep.Samples.csproj new file mode 100644 index 000000000000..c53e3fa6782d --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/samples/Azure.ResourceManager.Resources.Bicep.Samples.csproj @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs new file mode 100644 index 000000000000..e08ff58feaf3 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/samples/Generated/Samples/Sample_SubscriptionResourceExtensions.cs @@ -0,0 +1,44 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager.Resources.Bicep.Models; +using NUnit.Framework; + +namespace Azure.ResourceManager.Resources.Bicep.Samples +{ + public partial class Sample_SubscriptionResourceExtensions + { + [Test] + [Ignore("Only validating compilation of examples")] + public async Task BicepDecompileOperationGroup_DecompileAnARMJsonTemplateIntoABicepFile() + { + // Generated from example definition: 2023-11-01/DecompileBicep.json + // this example is just showing the usage of "DecompileOperationGroup_Bicep" operation, for the dependent resources, they will have to be created separately. + + // get your azure access token, for more details of how Azure SDK get your access token, please refer to https://learn.microsoft.com/en-us/dotnet/azure/sdk/authentication?tabs=command-line + TokenCredential cred = new DefaultAzureCredential(); + // authenticate your client + ArmClient client = new ArmClient(cred); + + // this example assumes you already have this SubscriptionResource created on azure + // for more information of creating SubscriptionResource, please refer to the document of SubscriptionResource + string subscriptionId = "00000000-0000-0000-0000-000000000000"; + ResourceIdentifier subscriptionResourceId = SubscriptionResource.CreateResourceIdentifier(subscriptionId); + SubscriptionResource subscriptionResource = client.GetSubscriptionResource(subscriptionResourceId); + + // invoke the operation + DecompileOperationContent content = new DecompileOperationContent("{\r\n \"$schema\": \"https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#\",\r\n \"contentVersion\": \"1.0.0.0\",\r\n \"metadata\": {\r\n \"_generator\": {\r\n \"name\": \"bicep\",\r\n \"version\": \"0.15.31.15270\",\r\n \"templateHash\": \"9249505596133208719\"\r\n }\r\n },\r\n \"parameters\": {\r\n \"storageAccountName\": {\r\n \"type\": \"string\"\r\n }\r\n },\r\n \"resources\": []\r\n}"); + DecompileOperationSuccessResponse result = await subscriptionResource.BicepDecompileOperationGroupAsync(content); + + Console.WriteLine($"Succeeded: {result}"); + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Azure.ResourceManager.Resources.Bicep.csproj b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Azure.ResourceManager.Resources.Bicep.csproj new file mode 100644 index 000000000000..8f6dd26a6a3e --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Azure.ResourceManager.Resources.Bicep.csproj @@ -0,0 +1,8 @@ + + + 1.0.0-beta.1 + Azure.ResourceManager.Resources.Bicep + Azure Resource Manager client SDK for Azure resource provider Bicep. + azure;management;arm;resource manager;bicep + + diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/ArmResourcesBicepModelFactory.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/ArmResourcesBicepModelFactory.cs new file mode 100644 index 000000000000..8515357ce921 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/ArmResourcesBicepModelFactory.cs @@ -0,0 +1,37 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.ResourceManager.Resources.Bicep.Models +{ + /// Model factory for models. + public static partial class ArmResourcesBicepModelFactory + { + /// Initializes a new instance of . + /// An array of key-value pairs containing the entryPoint string as the key for the Bicep file decompiled from the ARM json template. + /// The file path to the main Bicep file generated from the decompiled ARM json template. + /// A new instance for mocking. + public static DecompileOperationSuccessResponse DecompileOperationSuccessResponse(IEnumerable files = null, string entryPoint = null) + { + files ??= new List(); + + return new DecompileOperationSuccessResponse(files?.ToList(), entryPoint, serializedAdditionalRawData: null); + } + + /// Initializes a new instance of . + /// The file path of the Bicep file. + /// The contents of the Bicep file. + /// A new instance for mocking. + public static FileDefinition FileDefinition(string path = null, string contents = null) + { + return new FileDefinition(path, contents, serializedAdditionalRawData: null); + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Extensions/MockableResourcesBicepSubscriptionResource.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Extensions/MockableResourcesBicepSubscriptionResource.cs new file mode 100644 index 000000000000..cd5e1b8fad32 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Extensions/MockableResourcesBicepSubscriptionResource.cs @@ -0,0 +1,120 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager.Resources.Bicep.Models; + +namespace Azure.ResourceManager.Resources.Bicep.Mocking +{ + /// A class to add extension methods to SubscriptionResource. + public partial class MockableResourcesBicepSubscriptionResource : ArmResource + { + private ClientDiagnostics _decompileOperationGroupClientDiagnostics; + private DecompileOperationGroupRestOperations _decompileOperationGroupRestClient; + + /// Initializes a new instance of the class for mocking. + protected MockableResourcesBicepSubscriptionResource() + { + } + + /// Initializes a new instance of the class. + /// The client parameters to use in these operations. + /// The identifier of the resource that is the target of operations. + internal MockableResourcesBicepSubscriptionResource(ArmClient client, ResourceIdentifier id) : base(client, id) + { + } + + private ClientDiagnostics DecompileOperationGroupClientDiagnostics => _decompileOperationGroupClientDiagnostics ??= new ClientDiagnostics("Azure.ResourceManager.Resources.Bicep", ProviderConstants.DefaultProviderNamespace, Diagnostics); + private DecompileOperationGroupRestOperations DecompileOperationGroupRestClient => _decompileOperationGroupRestClient ??= new DecompileOperationGroupRestOperations(Pipeline, Diagnostics.ApplicationId, Endpoint); + + private string GetApiVersionOrNull(ResourceType resourceType) + { + TryGetApiVersion(resourceType, out string apiVersion); + return apiVersion; + } + + /// + /// Decompiles an ARM json template into a Bicep template + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.Resources/decompileBicep + /// + /// + /// Operation Id + /// DecompileOperationGroup_Bicep + /// + /// + /// Default Api Version + /// 2023-11-01 + /// + /// + /// + /// The request body. + /// The cancellation token to use. + /// is null. + public virtual async Task> BicepDecompileOperationGroupAsync(DecompileOperationContent content, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = DecompileOperationGroupClientDiagnostics.CreateScope("MockableResourcesBicepSubscriptionResource.BicepDecompileOperationGroup"); + scope.Start(); + try + { + var response = await DecompileOperationGroupRestClient.BicepAsync(Id.SubscriptionId, content, cancellationToken).ConfigureAwait(false); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Decompiles an ARM json template into a Bicep template + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.Resources/decompileBicep + /// + /// + /// Operation Id + /// DecompileOperationGroup_Bicep + /// + /// + /// Default Api Version + /// 2023-11-01 + /// + /// + /// + /// The request body. + /// The cancellation token to use. + /// is null. + public virtual Response BicepDecompileOperationGroup(DecompileOperationContent content, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = DecompileOperationGroupClientDiagnostics.CreateScope("MockableResourcesBicepSubscriptionResource.BicepDecompileOperationGroup"); + scope.Start(); + try + { + var response = DecompileOperationGroupRestClient.Bicep(Id.SubscriptionId, content, cancellationToken); + return response; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Extensions/ResourcesBicepExtensions.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Extensions/ResourcesBicepExtensions.cs new file mode 100644 index 000000000000..9e5c194b6079 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Extensions/ResourcesBicepExtensions.cs @@ -0,0 +1,88 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading; +using System.Threading.Tasks; +using Azure.ResourceManager.Resources.Bicep.Mocking; +using Azure.ResourceManager.Resources.Bicep.Models; + +namespace Azure.ResourceManager.Resources.Bicep +{ + /// A class to add extension methods to Azure.ResourceManager.Resources.Bicep. + public static partial class ResourcesBicepExtensions + { + private static MockableResourcesBicepSubscriptionResource GetMockableResourcesBicepSubscriptionResource(ArmResource resource) + { + return resource.GetCachedClient(client => new MockableResourcesBicepSubscriptionResource(client, resource.Id)); + } + + /// + /// Decompiles an ARM json template into a Bicep template + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.Resources/decompileBicep + /// + /// + /// Operation Id + /// DecompileOperationGroup_Bicep + /// + /// + /// Default Api Version + /// 2023-11-01 + /// + /// + /// + /// Mocking + /// To mock this method, please mock instead. + /// + /// + /// The instance the method will execute against. + /// The request body. + /// The cancellation token to use. + /// or is null. + public static async Task> BicepDecompileOperationGroupAsync(this SubscriptionResource subscriptionResource, DecompileOperationContent content, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); + + return await GetMockableResourcesBicepSubscriptionResource(subscriptionResource).BicepDecompileOperationGroupAsync(content, cancellationToken).ConfigureAwait(false); + } + + /// + /// Decompiles an ARM json template into a Bicep template + /// + /// + /// Request Path + /// /subscriptions/{subscriptionId}/providers/Microsoft.Resources/decompileBicep + /// + /// + /// Operation Id + /// DecompileOperationGroup_Bicep + /// + /// + /// Default Api Version + /// 2023-11-01 + /// + /// + /// + /// Mocking + /// To mock this method, please mock instead. + /// + /// + /// The instance the method will execute against. + /// The request body. + /// The cancellation token to use. + /// or is null. + public static Response BicepDecompileOperationGroup(this SubscriptionResource subscriptionResource, DecompileOperationContent content, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(subscriptionResource, nameof(subscriptionResource)); + + return GetMockableResourcesBicepSubscriptionResource(subscriptionResource).BicepDecompileOperationGroup(content, cancellationToken); + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/Argument.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/Argument.cs new file mode 100644 index 000000000000..3c71aa52958b --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/Argument.cs @@ -0,0 +1,129 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Resources.Bicep +{ + internal static class Argument + { + public static void AssertNotNull(T value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNull(T? value, string name) + where T : struct + { + if (!value.HasValue) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNullOrEmpty(IEnumerable value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value is ICollection collectionOfT && collectionOfT.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + if (value is ICollection collection && collection.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + using IEnumerator e = value.GetEnumerator(); + if (!e.MoveNext()) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + } + + public static void AssertNotNullOrEmpty(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", name); + } + } + + public static void AssertNotNullOrWhiteSpace(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name); + } + } + + public static void AssertNotDefault(ref T value, string name) + where T : struct, IEquatable + { + if (value.Equals(default)) + { + throw new ArgumentException("Value cannot be empty.", name); + } + } + + public static void AssertInRange(T value, T minimum, T maximum, string name) + where T : notnull, IComparable + { + if (minimum.CompareTo(value) > 0) + { + throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed."); + } + if (maximum.CompareTo(value) < 0) + { + throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed."); + } + } + + public static void AssertEnumDefined(Type enumType, object value, string name) + { + if (!Enum.IsDefined(enumType, value)) + { + throw new ArgumentException($"Value not defined for {enumType.FullName}.", name); + } + } + + public static T CheckNotNull(T value, string name) + where T : class + { + AssertNotNull(value, name); + return value; + } + + public static string CheckNotNullOrEmpty(string value, string name) + { + AssertNotNullOrEmpty(value, name); + return value; + } + + public static void AssertNull(T value, string name, string message = null) + { + if (value != null) + { + throw new ArgumentException(message ?? "Value must be null.", name); + } + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/ChangeTrackingDictionary.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/ChangeTrackingDictionary.cs new file mode 100644 index 000000000000..87acdd6380e1 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/ChangeTrackingDictionary.cs @@ -0,0 +1,167 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Resources.Bicep +{ + internal class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary where TKey : notnull + { + private IDictionary _innerDictionary; + + public ChangeTrackingDictionary() + { + } + + public ChangeTrackingDictionary(IDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(dictionary); + } + + public ChangeTrackingDictionary(IReadOnlyDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(); + foreach (var pair in dictionary) + { + _innerDictionary.Add(pair); + } + } + + public bool IsUndefined => _innerDictionary == null; + + public int Count => IsUndefined ? 0 : EnsureDictionary().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly; + + public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys; + + public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values; + + public TValue this[TKey key] + { + get + { + if (IsUndefined) + { + throw new KeyNotFoundException(nameof(key)); + } + return EnsureDictionary()[key]; + } + set + { + EnsureDictionary()[key] = value; + } + } + + IEnumerable IReadOnlyDictionary.Keys => Keys; + + IEnumerable IReadOnlyDictionary.Values => Values; + + public IEnumerator> GetEnumerator() + { + if (IsUndefined) + { + IEnumerator> enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureDictionary().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + EnsureDictionary().Add(item); + } + + public void Clear() + { + EnsureDictionary().Clear(); + } + + public bool Contains(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int index) + { + if (IsUndefined) + { + return; + } + EnsureDictionary().CopyTo(array, index); + } + + public bool Remove(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(item); + } + + public void Add(TKey key, TValue value) + { + EnsureDictionary().Add(key, value); + } + + public bool ContainsKey(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().ContainsKey(key); + } + + public bool Remove(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(key); + } + + public bool TryGetValue(TKey key, out TValue value) + { + if (IsUndefined) + { + value = default; + return false; + } + return EnsureDictionary().TryGetValue(key, out value); + } + + public IDictionary EnsureDictionary() + { + return _innerDictionary ??= new Dictionary(); + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/ChangeTrackingList.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/ChangeTrackingList.cs new file mode 100644 index 000000000000..cfab02b1951d --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/ChangeTrackingList.cs @@ -0,0 +1,153 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.ResourceManager.Resources.Bicep +{ + internal class ChangeTrackingList : IList, IReadOnlyList + { + private IList _innerList; + + public ChangeTrackingList() + { + } + + public ChangeTrackingList(IList innerList) + { + if (innerList != null) + { + _innerList = innerList; + } + } + + public ChangeTrackingList(IReadOnlyList innerList) + { + if (innerList != null) + { + _innerList = innerList.ToList(); + } + } + + public bool IsUndefined => _innerList == null; + + public int Count => IsUndefined ? 0 : EnsureList().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly; + + public T this[int index] + { + get + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + return EnsureList()[index]; + } + set + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList()[index] = value; + } + } + + public void Reset() + { + _innerList = null; + } + + public IEnumerator GetEnumerator() + { + if (IsUndefined) + { + IEnumerator enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureList().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(T item) + { + EnsureList().Add(item); + } + + public void Clear() + { + EnsureList().Clear(); + } + + public bool Contains(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Contains(item); + } + + public void CopyTo(T[] array, int arrayIndex) + { + if (IsUndefined) + { + return; + } + EnsureList().CopyTo(array, arrayIndex); + } + + public bool Remove(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Remove(item); + } + + public int IndexOf(T item) + { + if (IsUndefined) + { + return -1; + } + return EnsureList().IndexOf(item); + } + + public void Insert(int index, T item) + { + EnsureList().Insert(index, item); + } + + public void RemoveAt(int index) + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList().RemoveAt(index); + } + + public IList EnsureList() + { + return _innerList ??= new List(); + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/ModelSerializationExtensions.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/ModelSerializationExtensions.cs new file mode 100644 index 000000000000..d4c6b841f345 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/ModelSerializationExtensions.cs @@ -0,0 +1,425 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.Text.Json; +using System.Xml; +using Azure.Core; +using Azure.ResourceManager.Models; + +namespace Azure.ResourceManager.Resources.Bicep +{ + internal static class ModelSerializationExtensions + { + internal static readonly JsonDocumentOptions JsonDocumentOptions = new JsonDocumentOptions { MaxDepth = 256 }; + internal static readonly ModelReaderWriterOptions WireOptions = new ModelReaderWriterOptions("W"); + internal static readonly BinaryData SentinelValue = BinaryData.FromBytes("\"__EMPTY__\""u8.ToArray()); + internal static readonly JsonSerializerOptions Options = new JsonSerializerOptions { Converters = { new JsonModelConverter(WireOptions, AzureResourceManagerResourcesBicepContext.Default) } }; + internal static readonly JsonSerializerOptions OptionsUseManagedServiceIdentityV3 = new JsonSerializerOptions { Converters = { new JsonModelConverter(WireOptions, AzureResourceManagerResourcesBicepContext.Default), new ResourceManager.Models.ManagedServiceIdentityTypeV3Converter() } }; + + public static object GetObject(this JsonElement element) + { + switch (element.ValueKind) + { + case JsonValueKind.String: + return element.GetString(); + case JsonValueKind.Number: + if (element.TryGetInt32(out int intValue)) + { + return intValue; + } + if (element.TryGetInt64(out long longValue)) + { + return longValue; + } + return element.GetDouble(); + case JsonValueKind.True: + return true; + case JsonValueKind.False: + return false; + case JsonValueKind.Undefined: + case JsonValueKind.Null: + return null; + case JsonValueKind.Object: + var dictionary = new Dictionary(); + foreach (var jsonProperty in element.EnumerateObject()) + { + dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject()); + } + return dictionary; + case JsonValueKind.Array: + var list = new List(); + foreach (var item in element.EnumerateArray()) + { + list.Add(item.GetObject()); + } + return list.ToArray(); + default: + throw new NotSupportedException($"Not supported value kind {element.ValueKind}"); + } + } + + public static byte[] GetBytesFromBase64(this JsonElement element, string format) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + + return format switch + { + "U" => TypeFormatters.FromBase64UrlString(element.GetRequiredString()), + "D" => element.GetBytesFromBase64(), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + } + + public static DateTimeOffset GetDateTimeOffset(this JsonElement element, string format) => format switch + { + "U" when element.ValueKind == JsonValueKind.Number => DateTimeOffset.FromUnixTimeSeconds(element.GetInt64()), + _ => TypeFormatters.ParseDateTimeOffset(element.GetString(), format) + }; + + public static TimeSpan GetTimeSpan(this JsonElement element, string format) => TypeFormatters.ParseTimeSpan(element.GetString(), format); + + public static char GetChar(this JsonElement element) + { + if (element.ValueKind == JsonValueKind.String) + { + var text = element.GetString(); + if (text == null || text.Length != 1) + { + throw new NotSupportedException($"Cannot convert \"{text}\" to a char"); + } + return text[0]; + } + else + { + throw new NotSupportedException($"Cannot convert {element.ValueKind} to a char"); + } + } + + [Conditional("DEBUG")] + public static void ThrowNonNullablePropertyIsNull(this JsonProperty property) + { + throw new JsonException($"A property '{property.Name}' defined as non-nullable but received as null from the service. This exception only happens in DEBUG builds of the library and would be ignored in the release build"); + } + + public static string GetRequiredString(this JsonElement element) + { + var value = element.GetString(); + if (value == null) + { + throw new InvalidOperationException($"The requested operation requires an element of type 'String', but the target element has type '{element.ValueKind}'."); + } + return value; + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTime value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, char value) + { + writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); + } + + public static void WriteBase64StringValue(this Utf8JsonWriter writer, byte[] value, string format) + { + if (value == null) + { + writer.WriteNullValue(); + return; + } + switch (format) + { + case "U": + writer.WriteStringValue(TypeFormatters.ToBase64UrlString(value)); + break; + case "D": + writer.WriteBase64StringValue(value); + break; + default: + throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)); + } + } + + public static void WriteNumberValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + if (format != "U") + { + throw new ArgumentOutOfRangeException(nameof(format), "Only 'U' format is supported when writing a DateTimeOffset as a Number."); + } + writer.WriteNumberValue(value.ToUnixTimeSeconds()); + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, T value, ModelReaderWriterOptions options = null) + { + switch (value) + { + case null: + writer.WriteNullValue(); + break; + case IJsonModel jsonModel: + jsonModel.Write(writer, options ?? WireOptions); + break; + case IUtf8JsonSerializable serializable: + serializable.Write(writer); + break; + case byte[] bytes: + writer.WriteBase64StringValue(bytes); + break; + case BinaryData bytes0: + writer.WriteBase64StringValue(bytes0); + break; + case JsonElement json: + json.WriteTo(writer); + break; + case int i: + writer.WriteNumberValue(i); + break; + case decimal d: + writer.WriteNumberValue(d); + break; + case double d0: + if (double.IsNaN(d0)) + { + writer.WriteStringValue("NaN"); + } + else + { + writer.WriteNumberValue(d0); + } + break; + case float f: + writer.WriteNumberValue(f); + break; + case long l: + writer.WriteNumberValue(l); + break; + case string s: + writer.WriteStringValue(s); + break; + case bool b: + writer.WriteBooleanValue(b); + break; + case Guid g: + writer.WriteStringValue(g); + break; + case DateTimeOffset dateTimeOffset: + writer.WriteStringValue(dateTimeOffset, "O"); + break; + case DateTime dateTime: + writer.WriteStringValue(dateTime, "O"); + break; + case IEnumerable> enumerable: + writer.WriteStartObject(); + foreach (var pair in enumerable) + { + writer.WritePropertyName(pair.Key); + writer.WriteObjectValue(pair.Value, options); + } + writer.WriteEndObject(); + break; + case IEnumerable objectEnumerable: + writer.WriteStartArray(); + foreach (var item in objectEnumerable) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + break; + case TimeSpan timeSpan: + writer.WriteStringValue(timeSpan, "P"); + break; + default: + throw new NotSupportedException($"Not supported type {value.GetType()}"); + } + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, object value, ModelReaderWriterOptions options = null) + { + writer.WriteObjectValue(value, options); + } + + internal static bool IsSentinelValue(BinaryData value) + { + ReadOnlySpan sentinelSpan = SentinelValue.ToMemory().Span; + ReadOnlySpan valueSpan = value.ToMemory().Span; + return sentinelSpan.SequenceEqual(valueSpan); + } + + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "By passing in the JsonSerializerOptions with a reference to AzureResourceManagerCosmosDBContext.Default we are certain there is no AOT compat issue.")] + [UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "By passing in the JsonSerializerOptions with a reference to AzureResourceManagerCosmosDBContext.Default we are certain there is no AOT compat issue.")] + public static T JsonDeserialize(string json, JsonSerializerOptions options) + { + return JsonSerializer.Deserialize(json, options); + } + + [UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "By passing in the JsonSerializerOptions with a reference to AzureResourceManagerCosmosDBContext.Default we are certain there is no AOT compat issue.")] + [UnconditionalSuppressMessage("Trimming", "IL3050", Justification = "By passing in the JsonSerializerOptions with a reference to AzureResourceManagerCosmosDBContext.Default we are certain there is no AOT compat issue.")] + public static void JsonSerialize(Utf8JsonWriter writer, T data, JsonSerializerOptions options) + { + JsonSerializer.Serialize(writer, data, options); + } + + internal static class TypeFormatters + { + private const string RoundtripZFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; + public const string DefaultNumberFormat = "G"; + + public static string ToString(bool value) => value ? "true" : "false"; + + public static string ToString(DateTime value, string format) => value.Kind switch + { + DateTimeKind.Utc => ToString((DateTimeOffset)value, format), + _ => throw new NotSupportedException($"DateTime {value} has a Kind of {value.Kind}. Azure SDK requires it to be UTC. You can call DateTime.SpecifyKind to change Kind property value to DateTimeKind.Utc.") + }; + + public static string ToString(DateTimeOffset value, string format) => format switch + { + "D" => value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), + "U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), + "O" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "o" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "R" => value.ToString("r", CultureInfo.InvariantCulture), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(TimeSpan value, string format) => format switch + { + "P" => XmlConvert.ToString(value), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(byte[] value, string format) => format switch + { + "U" => ToBase64UrlString(value), + "D" => Convert.ToBase64String(value), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + + public static string ToBase64UrlString(byte[] value) + { + int numWholeOrPartialInputBlocks = checked(value.Length + 2) / 3; + int size = checked(numWholeOrPartialInputBlocks * 4); + char[] output = new char[size]; + + int numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0); + + int i = 0; + for (; i < numBase64Chars; i++) + { + char ch = output[i]; + if (ch == '+') + { + output[i] = '-'; + } + else + { + if (ch == '/') + { + output[i] = '_'; + } + else + { + if (ch == '=') + { + break; + } + } + } + } + + return new string(output, 0, i); + } + + public static byte[] FromBase64UrlString(string value) + { + int paddingCharsToAdd = (value.Length % 4) switch + { + 0 => 0, + 2 => 2, + 3 => 1, + _ => throw new InvalidOperationException("Malformed input") + }; + char[] output = new char[(value.Length + paddingCharsToAdd)]; + int i = 0; + for (; i < value.Length; i++) + { + char ch = value[i]; + if (ch == '-') + { + output[i] = '+'; + } + else + { + if (ch == '_') + { + output[i] = '/'; + } + else + { + output[i] = ch; + } + } + } + + for (; i < output.Length; i++) + { + output[i] = '='; + } + + return Convert.FromBase64CharArray(output, 0, output.Length); + } + + public static DateTimeOffset ParseDateTimeOffset(string value, string format) => format switch + { + "U" => DateTimeOffset.FromUnixTimeSeconds(long.Parse(value, CultureInfo.InvariantCulture)), + _ => DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) + }; + + public static TimeSpan ParseTimeSpan(string value, string format) => format switch + { + "P" => XmlConvert.ToTimeSpan(value), + _ => TimeSpan.ParseExact(value, format, CultureInfo.InvariantCulture) + }; + + public static string ConvertToString(object value, string format = null) => value switch + { + null => "null", + string s => s, + bool b => ToString(b), + int or float or double or long or decimal => ((IFormattable)value).ToString(DefaultNumberFormat, CultureInfo.InvariantCulture), + byte[] b0 when format != null => ToString(b0, format), + IEnumerable s0 => string.Join(",", s0), + DateTimeOffset dateTime when format != null => ToString(dateTime, format), + TimeSpan timeSpan when format != null => ToString(timeSpan, format), + TimeSpan timeSpan0 => XmlConvert.ToString(timeSpan0), + Guid guid => guid.ToString(), + BinaryData binaryData => ConvertToString(binaryData.ToArray(), format), + _ => value.ToString() + }; + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/Optional.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/Optional.cs new file mode 100644 index 000000000000..4e82453f1cde --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/Optional.cs @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; + +namespace Azure.ResourceManager.Resources.Bicep +{ + internal static class Optional + { + public static bool IsCollectionDefined(IEnumerable collection) + { + return !(collection is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined); + } + + public static bool IsCollectionDefined(IDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsCollectionDefined(IReadOnlyDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsDefined(T? value) + where T : struct + { + return value.HasValue; + } + + public static bool IsDefined(object value) + { + return value != null; + } + + public static bool IsDefined(JsonElement value) + { + return value.ValueKind != JsonValueKind.Undefined; + } + + public static bool IsDefined(string value) + { + return value != null; + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/Utf8JsonRequestContent.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/Utf8JsonRequestContent.cs new file mode 100644 index 000000000000..8a048370d4bf --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Internal/Utf8JsonRequestContent.cs @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; + +namespace Azure.ResourceManager.Resources.Bicep +{ + internal class Utf8JsonRequestContent : RequestContent + { + private readonly MemoryStream _stream; + private readonly RequestContent _content; + + public Utf8JsonRequestContent() + { + _stream = new MemoryStream(); + _content = Create(_stream); + JsonWriter = new Utf8JsonWriter(_stream); + } + + public Utf8JsonWriter JsonWriter { get; } + + public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default) + { + await JsonWriter.FlushAsync().ConfigureAwait(false); + await _content.WriteToAsync(stream, cancellationToken).ConfigureAwait(false); + } + + public override void WriteTo(Stream stream, CancellationToken cancellationToken = default) + { + JsonWriter.Flush(); + _content.WriteTo(stream, cancellationToken); + } + + public override bool TryComputeLength(out long length) + { + length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; + return true; + } + + public override void Dispose() + { + JsonWriter.Dispose(); + _content.Dispose(); + _stream.Dispose(); + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/AzureResourceManagerResourcesBicepContext.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/AzureResourceManagerResourcesBicepContext.cs new file mode 100644 index 000000000000..96030b892b35 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/AzureResourceManagerResourcesBicepContext.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.ClientModel.Primitives; + +namespace Azure.ResourceManager.Resources.Bicep +{ + /// + /// Context class which will be filled in by the System.ClientModel.SourceGeneration. + /// For more information see 'https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/System.ClientModel/src/docs/ModelReaderWriterContext.md' + /// + public partial class AzureResourceManagerResourcesBicepContext : ModelReaderWriterContext + { + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationContent.Serialization.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationContent.Serialization.cs new file mode 100644 index 000000000000..e9c450dac6ca --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationContent.Serialization.cs @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Resources.Bicep.Models +{ + public partial class DecompileOperationContent : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DecompileOperationContent)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("template"u8); + writer.WriteStringValue(Template); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + DecompileOperationContent IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DecompileOperationContent)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeDecompileOperationContent(document.RootElement, options); + } + + internal static DecompileOperationContent DeserializeDecompileOperationContent(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string template = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("template"u8)) + { + template = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new DecompileOperationContent(template, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, AzureResourceManagerResourcesBicepContext.Default); + default: + throw new FormatException($"The model {nameof(DecompileOperationContent)} does not support writing '{options.Format}' format."); + } + } + + DecompileOperationContent IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeDecompileOperationContent(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(DecompileOperationContent)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationContent.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationContent.cs new file mode 100644 index 000000000000..ecd6e8c9b6bd --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationContent.cs @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Resources.Bicep.Models +{ + /// The body of the request for the decompileBicep operation. + public partial class DecompileOperationContent + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// The ARM json template to be decompiled into a Bicep file. + /// is null. + public DecompileOperationContent(string template) + { + Argument.AssertNotNull(template, nameof(template)); + + Template = template; + } + + /// Initializes a new instance of . + /// The ARM json template to be decompiled into a Bicep file. + /// Keeps track of any properties unknown to the library. + internal DecompileOperationContent(string template, IDictionary serializedAdditionalRawData) + { + Template = template; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal DecompileOperationContent() + { + } + + /// The ARM json template to be decompiled into a Bicep file. + public string Template { get; } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationSuccessResponse.Serialization.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationSuccessResponse.Serialization.cs new file mode 100644 index 000000000000..6ae5e7dad62e --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationSuccessResponse.Serialization.cs @@ -0,0 +1,144 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Resources.Bicep.Models +{ + public partial class DecompileOperationSuccessResponse : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DecompileOperationSuccessResponse)} does not support writing '{format}' format."); + } + + writer.WritePropertyName("files"u8); + writer.WriteStartArray(); + foreach (var item in Files) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + writer.WritePropertyName("entryPoint"u8); + writer.WriteStringValue(EntryPoint); + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + DecompileOperationSuccessResponse IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(DecompileOperationSuccessResponse)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeDecompileOperationSuccessResponse(document.RootElement, options); + } + + internal static DecompileOperationSuccessResponse DeserializeDecompileOperationSuccessResponse(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList files = default; + string entryPoint = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("files"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(FileDefinition.DeserializeFileDefinition(item, options)); + } + files = array; + continue; + } + if (property.NameEquals("entryPoint"u8)) + { + entryPoint = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new DecompileOperationSuccessResponse(files, entryPoint, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, AzureResourceManagerResourcesBicepContext.Default); + default: + throw new FormatException($"The model {nameof(DecompileOperationSuccessResponse)} does not support writing '{options.Format}' format."); + } + } + + DecompileOperationSuccessResponse IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeDecompileOperationSuccessResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(DecompileOperationSuccessResponse)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationSuccessResponse.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationSuccessResponse.cs new file mode 100644 index 000000000000..10c823d350c5 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/DecompileOperationSuccessResponse.cs @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace Azure.ResourceManager.Resources.Bicep.Models +{ + /// The response of the decompileBicep operation. + public partial class DecompileOperationSuccessResponse + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// An array of key-value pairs containing the entryPoint string as the key for the Bicep file decompiled from the ARM json template. + /// The file path to the main Bicep file generated from the decompiled ARM json template. + /// or is null. + internal DecompileOperationSuccessResponse(IEnumerable files, string entryPoint) + { + Argument.AssertNotNull(files, nameof(files)); + Argument.AssertNotNull(entryPoint, nameof(entryPoint)); + + Files = files.ToList(); + EntryPoint = entryPoint; + } + + /// Initializes a new instance of . + /// An array of key-value pairs containing the entryPoint string as the key for the Bicep file decompiled from the ARM json template. + /// The file path to the main Bicep file generated from the decompiled ARM json template. + /// Keeps track of any properties unknown to the library. + internal DecompileOperationSuccessResponse(IReadOnlyList files, string entryPoint, IDictionary serializedAdditionalRawData) + { + Files = files; + EntryPoint = entryPoint; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal DecompileOperationSuccessResponse() + { + } + + /// An array of key-value pairs containing the entryPoint string as the key for the Bicep file decompiled from the ARM json template. + public IReadOnlyList Files { get; } + /// The file path to the main Bicep file generated from the decompiled ARM json template. + public string EntryPoint { get; } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/FileDefinition.Serialization.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/FileDefinition.Serialization.cs new file mode 100644 index 000000000000..7f8aa3fe51d9 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/FileDefinition.Serialization.cs @@ -0,0 +1,140 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace Azure.ResourceManager.Resources.Bicep.Models +{ + public partial class FileDefinition : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, ModelSerializationExtensions.WireOptions); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteStartObject(); + JsonModelWriteCore(writer, options); + writer.WriteEndObject(); + } + + /// The JSON writer. + /// The client options for reading and writing models. + protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FileDefinition)} does not support writing '{format}' format."); + } + + if (Optional.IsDefined(Path)) + { + writer.WritePropertyName("path"u8); + writer.WriteStringValue(Path); + } + if (Optional.IsDefined(Contents)) + { + writer.WritePropertyName("contents"u8); + writer.WriteStringValue(Contents); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value, ModelSerializationExtensions.JsonDocumentOptions)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + } + + FileDefinition IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(FileDefinition)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeFileDefinition(document.RootElement, options); + } + + internal static FileDefinition DeserializeFileDefinition(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string path = default; + string contents = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("path"u8)) + { + path = property.Value.GetString(); + continue; + } + if (property.NameEquals("contents"u8)) + { + contents = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new FileDefinition(path, contents, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options, AzureResourceManagerResourcesBicepContext.Default); + default: + throw new FormatException($"The model {nameof(FileDefinition)} does not support writing '{options.Format}' format."); + } + } + + FileDefinition IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data, ModelSerializationExtensions.JsonDocumentOptions); + return DeserializeFileDefinition(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(FileDefinition)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/FileDefinition.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/FileDefinition.cs new file mode 100644 index 000000000000..4c83656a3477 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/Models/FileDefinition.cs @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Azure.ResourceManager.Resources.Bicep.Models +{ + /// The definition of a file along with its contents. + public partial class FileDefinition + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + internal FileDefinition() + { + } + + /// Initializes a new instance of . + /// The file path of the Bicep file. + /// The contents of the Bicep file. + /// Keeps track of any properties unknown to the library. + internal FileDefinition(string path, string contents, IDictionary serializedAdditionalRawData) + { + Path = path; + Contents = contents; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The file path of the Bicep file. + public string Path { get; } + /// The contents of the Bicep file. + public string Contents { get; } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/ProviderConstants.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/ProviderConstants.cs new file mode 100644 index 000000000000..cfd7cc573a23 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/ProviderConstants.cs @@ -0,0 +1,16 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using Azure.Core.Pipeline; + +namespace Azure.ResourceManager.Resources.Bicep +{ + internal static class ProviderConstants + { + public static string DefaultProviderNamespace { get; } = ClientDiagnostics.GetResourceProviderNamespace(typeof(ProviderConstants).Assembly); + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/RestOperations/DecompileOperationGroupRestOperations.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/RestOperations/DecompileOperationGroupRestOperations.cs new file mode 100644 index 000000000000..a61ec3ca742e --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Generated/RestOperations/DecompileOperationGroupRestOperations.cs @@ -0,0 +1,125 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager.Resources.Bicep.Models; + +namespace Azure.ResourceManager.Resources.Bicep +{ + internal partial class DecompileOperationGroupRestOperations + { + private readonly TelemetryDetails _userAgent; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// Initializes a new instance of DecompileOperationGroupRestOperations. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The application id to use for user agent. + /// Service host. + /// The API version to use for this operation. + /// or is null. + public DecompileOperationGroupRestOperations(HttpPipeline pipeline, string applicationId, Uri endpoint = null, string apiVersion = default) + { + _pipeline = pipeline ?? throw new ArgumentNullException(nameof(pipeline)); + _endpoint = endpoint ?? new Uri("https://management.azure.com"); + _apiVersion = apiVersion ?? "2023-11-01"; + _userAgent = new TelemetryDetails(GetType().Assembly, applicationId); + } + + internal RequestUriBuilder CreateBicepRequestUri(string subscriptionId, DecompileOperationContent content) + { + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendPath("/providers/Microsoft.Resources/decompileBicep", false); + uri.AppendQuery("api-version", _apiVersion, true); + return uri; + } + + internal HttpMessage CreateBicepRequest(string subscriptionId, DecompileOperationContent content) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendPath("/providers/Microsoft.Resources/decompileBicep", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + var content0 = new Utf8JsonRequestContent(); + content0.JsonWriter.WriteObjectValue(content, ModelSerializationExtensions.WireOptions); + request.Content = content0; + _userAgent.Apply(message); + return message; + } + + /// Decompiles an ARM json template into a Bicep template. + /// The ID of the target subscription. The value must be an UUID. + /// The request body. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public async Task> BicepAsync(string subscriptionId, DecompileOperationContent content, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); + Argument.AssertNotNull(content, nameof(content)); + + using var message = CreateBicepRequest(subscriptionId, content); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + DecompileOperationSuccessResponse value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, ModelSerializationExtensions.JsonDocumentOptions, cancellationToken).ConfigureAwait(false); + value = DecompileOperationSuccessResponse.DeserializeDecompileOperationSuccessResponse(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw new RequestFailedException(message.Response); + } + } + + /// Decompiles an ARM json template into a Bicep template. + /// The ID of the target subscription. The value must be an UUID. + /// The request body. + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public Response Bicep(string subscriptionId, DecompileOperationContent content, CancellationToken cancellationToken = default) + { + Argument.AssertNotNullOrEmpty(subscriptionId, nameof(subscriptionId)); + Argument.AssertNotNull(content, nameof(content)); + + using var message = CreateBicepRequest(subscriptionId, content); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + DecompileOperationSuccessResponse value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream, ModelSerializationExtensions.JsonDocumentOptions); + value = DecompileOperationSuccessResponse.DeserializeDecompileOperationSuccessResponse(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw new RequestFailedException(message.Response); + } + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/GlobalSuppressions.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/GlobalSuppressions.cs new file mode 100644 index 000000000000..3ae4bb482939 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/GlobalSuppressions.cs @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Diagnostics.CodeAnalysis; + +[assembly: SuppressMessage("Naming", "AZC0030:Improper model name suffix", Justification = "Model name ends with 'Response', suppression added to avoid renaming.", Scope = "type", Target = "~T:Azure.ResourceManager.Resources.Bicep.Models.DecompileOperationSuccessResponse")] +[assembly: SuppressMessage("Naming", "AZC0031:Improper model name suffix", Justification = "Model name ends with 'Definition', suppression added to avoid renaming.", Scope = "type", Target = "~T:Azure.ResourceManager.Resources.Bicep.Models.FileDefinition")] diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Properties/AssemblyInfo.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Properties/AssemblyInfo.cs new file mode 100644 index 000000000000..5203e5177abd --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/src/Properties/AssemblyInfo.cs @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Runtime.CompilerServices; + +[assembly: Azure.Core.AzureResourceProviderNamespace("Bicep")] + +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] +[assembly: InternalsVisibleTo("Azure.ResourceManager.Resources.Bicep.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100d15ddcb29688295338af4b7686603fe614abd555e09efba8fb88ee09e1f7b1ccaeed2e8f823fa9eef3fdd60217fc012ea67d2479751a0b8c087a4185541b851bd8b16f8d91b840e51b1cb0ba6fe647997e57429265e85ef62d565db50a69ae1647d54d7bd855e4db3d8a91510e5bcbd0edfbbecaa20a7bd9ae74593daa7b11b4")] diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/Azure.ResourceManager.Resources.Bicep.Tests.csproj b/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/Azure.ResourceManager.Resources.Bicep.Tests.csproj new file mode 100644 index 000000000000..eb2151493093 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/Azure.ResourceManager.Resources.Bicep.Tests.csproj @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/BicepManagementTestBase.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/BicepManagementTestBase.cs new file mode 100644 index 000000000000..b8ace7fafbe3 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/BicepManagementTestBase.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core; +using Azure.Core.TestFramework; +using Azure.ResourceManager.Resources; +using Azure.ResourceManager.TestFramework; +using NUnit.Framework; +using System.Threading.Tasks; + +namespace Azure.ResourceManager.Resources.Bicep.Tests +{ + public class BicepManagementTestBase : ManagementRecordedTestBase + { + protected ArmClient Client { get; private set; } + protected SubscriptionResource DefaultSubscription { get; private set; } + + protected BicepManagementTestBase(bool isAsync, RecordedTestMode mode) + : base(isAsync, mode) + { + } + + protected BicepManagementTestBase(bool isAsync) + : base(isAsync) + { + } + + [SetUp] + public async Task CreateCommonClient() + { + Client = GetArmClient(); + DefaultSubscription = await Client.GetDefaultSubscriptionAsync().ConfigureAwait(false); + } + + protected async Task CreateResourceGroup(SubscriptionResource subscription, string rgNamePrefix, AzureLocation location) + { + string rgName = Recording.GenerateAssetName(rgNamePrefix); + ResourceGroupData input = new ResourceGroupData(location); + var lro = await subscription.GetResourceGroups().CreateOrUpdateAsync(WaitUntil.Completed, rgName, input); + return lro.Value; + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/BicepManagementTestEnvironment.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/BicepManagementTestEnvironment.cs new file mode 100644 index 000000000000..505455d1acb9 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/BicepManagementTestEnvironment.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using Azure.Core.TestFramework; + +namespace Azure.ResourceManager.Resources.Bicep.Tests +{ + public class BicepManagementTestEnvironment : TestEnvironment + { + } +} \ No newline at end of file diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/DecompileOperationTests.cs b/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/DecompileOperationTests.cs new file mode 100644 index 000000000000..f6bcef34cb1c --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/tests/DecompileOperationTests.cs @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using NUnit.Framework; +using Azure.ResourceManager.Resources.Bicep.Models; +using Azure.Core; +using System.Linq; + +namespace Azure.ResourceManager.Resources.Bicep.Tests +{ + public sealed class DecompileOperationTests : BicepManagementTestBase + { + public DecompileOperationTests(bool isAsync) + : base(isAsync) + { + } + + [TestCase] + [RecordedTest] + public async Task Decompile_generates_valid_bicep_code() + { + var subscription = await Client.GetDefaultSubscriptionAsync(); + + var response = await subscription.BicepDecompileOperationGroupAsync(new DecompileOperationContent(""" + { + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "metadata": { + "_generator": { + "name": "bicep", + "version": "0.36.1.42791", + "templateHash": "18309635653390499776" + } + }, + "parameters": { + "foo": { + "type": "string" + } + }, + "resources": [], + "outputs": { + "foo": { + "type": "string", + "value": "[parameters('foo')]" + } + } + } + """.Replace("\r\n", "\n"))); + + var mainBicep = response.Value.Files.Single(x => x.Path == response.Value.EntryPoint); + Assert.AreEqual("param foo string\n\noutput foo string = foo\n", mainBicep.Contents); + } + } +} diff --git a/sdk/resources/Azure.ResourceManager.Resources.Bicep/tsp-location.yaml b/sdk/resources/Azure.ResourceManager.Resources.Bicep/tsp-location.yaml new file mode 100644 index 000000000000..b708fa950820 --- /dev/null +++ b/sdk/resources/Azure.ResourceManager.Resources.Bicep/tsp-location.yaml @@ -0,0 +1,3 @@ +directory: specification/resources/Bicep.Management +commit: bd299f84bb4485de6cd4b9740bf4d0e9495347e0 +repo: Azure/azure-rest-api-specs \ No newline at end of file diff --git a/sdk/resources/ci.mgmt.yml b/sdk/resources/ci.mgmt.yml index 3fefd5254c85..ee7782445114 100644 --- a/sdk/resources/ci.mgmt.yml +++ b/sdk/resources/ci.mgmt.yml @@ -12,6 +12,7 @@ pr: include: - sdk/resources/ci.mgmt.yml - sdk/resources/Azure.ResourceManager.Resources/ + - sdk/resources/Azure.ResourceManager.Resources.Bicep/ extends: template: /eng/pipelines/templates/stages/archetype-sdk-client.yml @@ -21,3 +22,5 @@ extends: Artifacts: - name: Azure.ResourceManager.Resources safeName: AzureResourceManagerResources + - name: Azure.ResourceManager.Resources.Bicep + safeName: AzureResourceManagerResourcesBicep