diff --git a/sdk/resourcemanager/Azure.ResourceManager/CHANGELOG.md b/sdk/resourcemanager/Azure.ResourceManager/CHANGELOG.md index eeb202df0f3a4..6689a7a59453b 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/CHANGELOG.md +++ b/sdk/resourcemanager/Azure.ResourceManager/CHANGELOG.md @@ -1,40 +1,38 @@ # Release History -## 1.11.0-beta.1 (Unreleased) +## 1.10.2 (2024-03-01) ### Features Added -### Breaking Changes +- Added `ManagementGroupSubscriptions` operations. ### Bugs Fixed - Fixed [the issue](https://github.com/Azure/azure-sdk-for-net/issues/38154) that sdk caches wrong subscription provider. -### Other Changes - ## 1.10.1 (2024-01-26) ### Bugs Fixed -- Change the private ctor `OperationStatusResult` to protected. +- Changed the private ctor `OperationStatusResult` to protected. ## 1.10.0 (2024-01-12) ### Features Added -- Add `GetEntities` operation. -- Add `CheckResourceName` operation. -- Enable the new model serialization by using the System.ClientModel, refer this [document](https://aka.ms/azsdk/net/mrw) for more details. +- Added `GetEntities` operation. +- Added `CheckResourceName` operation. +- Enabled the new model serialization by using the System.ClientModel, refer this [document](https://aka.ms/azsdk/net/mrw) for more details. ## 1.9.0 (2023-11-14) ### Features Added -- Bump api-version of `Lock` to `2020-05-01`. +- Bumped api-version of `Lock` to `2020-05-01`. ### Bugs Fixed -- Add the `Default` enum value back to `EnforcementMode`. +- Added the `Default` enum value back to `EnforcementMode`. ### Other Changes @@ -44,26 +42,26 @@ ### Features Added -- Add a new method `GetCachedClient` in `ArmClient` class to unify the mocking experience. +- Added a new method `GetCachedClient` in `ArmClient` class to unify the mocking experience. ## 1.8.0-beta.1 (2023-08-09) ### Features Added -- Add a method `GetCachedClient` in `ArmClient` to enable mocking for extension methods. +- Added a method `GetCachedClient` in `ArmClient` to enable mocking for extension methods. ## 1.7.0 (2023-07-13) ### Other Changes -- Bump api-version of `Subscription` to `2022-12-01`. -- Bump api-version of `Tenant` to `2022-12-01`. +- Bumped api-version of `Subscription` to `2022-12-01`. +- Bumped api-version of `Tenant` to `2022-12-01`. ## 1.6.0 (2023-05-16) ### Features Added -- Add more model factory entries in class `Azure.ResourceManager.Models.ResourceManagerModelFactory` to support more generated models. +- Added more model factory entries in class `Azure.ResourceManager.Models.ResourceManagerModelFactory` to support more generated models. ### Bugs Fixed @@ -77,8 +75,8 @@ ### Other Changes -- Bump api-version of `PolicyAssignments` to `2022-06-01`. -- Bump api-version of `PolicyDefinitions` and `PolicySetDefinitions` to `2021-06-01`. +- Bumped api-version of `PolicyAssignments` to `2022-06-01`. +- Bumped api-version of `PolicyDefinitions` and `PolicySetDefinitions` to `2021-06-01`. - Introduced new property `TargetResourceGroupId` on `Azure.ResourceManager.Resources.Models.ResourcesMoveContent` to supersede `TargetResourceGroup` to emphasize this is accepting a `ResourceIdentifier` of the target resource group. ## 1.4.0 (2023-02-10) @@ -142,13 +140,13 @@ ### Features Added -- Add `ExtendedLocation` to common type. +- Added `ExtendedLocation` to common type. ## 1.1.1 (2022-06-22) ### Features Added -- Add OperationStatusResult to common type. +- Added OperationStatusResult to common type. ### Bugs Fixed @@ -162,7 +160,7 @@ ### Features Added -- Add Update methods in resource classes. +- Added Update methods in resource classes. ## 1.0.0 (2022-04-07) This package is the first stable release of the Azure Resources management core library. @@ -171,7 +169,7 @@ This package is the first stable release of the Azure Resources management core Minor changes since the public beta release: - All `Tag` methods have been removed from `SubscriptionResource` as the service doesn't support these operations. -- Simplify `type` property names. +- Simplified `type` property names. - Normalized the body parameter type names for PUT / POST / PATCH operations if it's only used as input. - Tweaked some properties to right type. @@ -179,7 +177,7 @@ Minor changes since the public beta release: ### Features Added -- New struct `ArmEnvironment`. +- Added new struct `ArmEnvironment`. ### Breaking Changes @@ -200,7 +198,7 @@ Minor changes since the public beta release: - ManagementGroup: Added GetAvailableLocations methods. - GenericResourceData: Added a new property ExtendedLocation. -- Support using different api versions for a service. +- Supported using different api versions for a service. ### Breaking Changes diff --git a/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs b/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs index 62a1456f48986..fafe6ce219a32 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/api/Azure.ResourceManager.netstandard2.0.cs @@ -18,6 +18,7 @@ public ArmClient(Azure.Core.TokenCredential credential, string defaultSubscripti public virtual Azure.ResourceManager.Resources.ManagementGroupPolicySetDefinitionResource GetManagementGroupPolicySetDefinitionResource(Azure.Core.ResourceIdentifier id) { throw null; } public virtual Azure.ResourceManager.ManagementGroups.ManagementGroupResource GetManagementGroupResource(Azure.Core.ResourceIdentifier id) { throw null; } public virtual Azure.ResourceManager.ManagementGroups.ManagementGroupCollection GetManagementGroups() { throw null; } + public virtual Azure.ResourceManager.ManagementGroups.ManagementGroupSubscriptionResource GetManagementGroupSubscriptionResource(Azure.Core.ResourceIdentifier id) { throw null; } public virtual Azure.ResourceManager.Resources.ManagementLockResource GetManagementLockResource(Azure.Core.ResourceIdentifier id) { throw null; } public virtual Azure.ResourceManager.Resources.PolicyAssignmentResource GetPolicyAssignmentResource(Azure.Core.ResourceIdentifier id) { throw null; } [System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)] @@ -177,9 +178,56 @@ protected ManagementGroupResource() { } public virtual Azure.Response GetManagementGroupPolicySetDefinition(string policySetDefinitionName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> GetManagementGroupPolicySetDefinitionAsync(string policySetDefinitionName, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual Azure.ResourceManager.Resources.ManagementGroupPolicySetDefinitionCollection GetManagementGroupPolicySetDefinitions() { throw null; } + public virtual Azure.Response GetManagementGroupSubscription(string subscriptionId, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetManagementGroupSubscriptionAsync(string subscriptionId, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.ResourceManager.ManagementGroups.ManagementGroupSubscriptionCollection GetManagementGroupSubscriptions() { throw null; } public virtual Azure.Response Update(Azure.ResourceManager.ManagementGroups.Models.ManagementGroupPatch patch, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } public virtual System.Threading.Tasks.Task> UpdateAsync(Azure.ResourceManager.ManagementGroups.Models.ManagementGroupPatch patch, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } } + public partial class ManagementGroupSubscriptionCollection : Azure.ResourceManager.ArmCollection, System.Collections.Generic.IAsyncEnumerable, System.Collections.Generic.IEnumerable, System.Collections.IEnumerable + { + protected ManagementGroupSubscriptionCollection() { } + public virtual Azure.ResourceManager.ArmOperation CreateOrUpdate(Azure.WaitUntil waitUntil, string subscriptionId, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> CreateOrUpdateAsync(Azure.WaitUntil waitUntil, string subscriptionId, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response Exists(string subscriptionId, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> ExistsAsync(string subscriptionId, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response Get(string subscriptionId, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Pageable GetAll(string skipToken = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.AsyncPageable GetAllAsync(string skipToken = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetAsync(string subscriptionId, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.NullableResponse GetIfExists(string subscriptionId, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetIfExistsAsync(string subscriptionId, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + System.Collections.Generic.IAsyncEnumerator System.Collections.Generic.IAsyncEnumerable.GetAsyncEnumerator(System.Threading.CancellationToken cancellationToken) { throw null; } + System.Collections.Generic.IEnumerator System.Collections.Generic.IEnumerable.GetEnumerator() { throw null; } + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; } + } + public partial class ManagementGroupSubscriptionData : Azure.ResourceManager.Models.ResourceData, System.ClientModel.Primitives.IJsonModel, System.ClientModel.Primitives.IPersistableModel + { + internal ManagementGroupSubscriptionData() { } + public string DisplayName { get { throw null; } } + public Azure.Core.ResourceIdentifier ParentId { get { throw null; } } + public string State { get { throw null; } } + public string Tenant { get { throw null; } } + Azure.ResourceManager.ManagementGroups.ManagementGroupSubscriptionData 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.ManagementGroups.ManagementGroupSubscriptionData 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 ManagementGroupSubscriptionResource : Azure.ResourceManager.ArmResource + { + public static readonly Azure.Core.ResourceType ResourceType; + protected ManagementGroupSubscriptionResource() { } + public virtual Azure.ResourceManager.ManagementGroups.ManagementGroupSubscriptionData Data { get { throw null; } } + public virtual bool HasData { get { throw null; } } + public static Azure.Core.ResourceIdentifier CreateResourceIdentifier(string groupId, string subscriptionId) { throw null; } + public virtual Azure.ResourceManager.ArmOperation Delete(Azure.WaitUntil waitUntil, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task DeleteAsync(Azure.WaitUntil waitUntil, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.Response Get(string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> GetAsync(string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual Azure.ResourceManager.ArmOperation Update(Azure.WaitUntil waitUntil, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + public virtual System.Threading.Tasks.Task> UpdateAsync(Azure.WaitUntil waitUntil, string cacheControl = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; } + } } namespace Azure.ResourceManager.ManagementGroups.Models { @@ -663,6 +711,7 @@ public static partial class ResourceManagerModelFactory public static Azure.ResourceManager.ManagementGroups.Models.ManagementGroupNameAvailabilityResult ManagementGroupNameAvailabilityResult(bool? nameAvailable = default(bool?), Azure.ResourceManager.ManagementGroups.Models.ManagementGroupNameUnavailableReason? reason = default(Azure.ResourceManager.ManagementGroups.Models.ManagementGroupNameUnavailableReason?), string message = null) { throw null; } public static Azure.ResourceManager.ManagementGroups.Models.ManagementGroupParentCreateOptions ManagementGroupParentCreateOptions(string id = null, string name = null, string displayName = null) { throw null; } public static Azure.ResourceManager.ManagementGroups.Models.ManagementGroupPathElement ManagementGroupPathElement(string name = null, string displayName = null) { throw null; } + public static Azure.ResourceManager.ManagementGroups.ManagementGroupSubscriptionData ManagementGroupSubscriptionData(Azure.Core.ResourceIdentifier id = null, string name = null, Azure.Core.ResourceType resourceType = default(Azure.Core.ResourceType), Azure.ResourceManager.Models.SystemData systemData = null, string tenant = null, string displayName = null, Azure.Core.ResourceIdentifier parentId = null, string state = null) { throw null; } public static Azure.ResourceManager.Resources.ManagementLockData ManagementLockData(Azure.Core.ResourceIdentifier id = null, string name = null, Azure.Core.ResourceType resourceType = default(Azure.Core.ResourceType), Azure.ResourceManager.Models.SystemData systemData = null, Azure.ResourceManager.Resources.Models.ManagementLockLevel level = default(Azure.ResourceManager.Resources.Models.ManagementLockLevel), string notes = null, System.Collections.Generic.IEnumerable owners = null) { throw null; } public static Azure.ResourceManager.Resources.Models.PairedRegion PairedRegion(string name = null, string id = null, string subscriptionId = null) { throw null; } public static Azure.ResourceManager.ManagementGroups.Models.ParentManagementGroupInfo ParentManagementGroupInfo(string id = null, string name = null, string displayName = null) { throw null; } diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/Generated/Samples/Sample_ManagementGroupSubscriptionCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/Generated/Samples/Sample_ManagementGroupSubscriptionCollection.cs new file mode 100644 index 0000000000000..e6bead3c066e0 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/Generated/Samples/Sample_ManagementGroupSubscriptionCollection.cs @@ -0,0 +1,196 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.ManagementGroups; + +namespace Azure.ResourceManager.ManagementGroups.Samples +{ + public partial class Sample_ManagementGroupSubscriptionCollection + { + // AddSubscriptionToManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task CreateOrUpdate_AddSubscriptionToManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/AddManagementGroupSubscription.json + // this example is just showing the usage of "ManagementGroupSubscriptions_Create" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "Group"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupSubscriptionResource + ManagementGroupSubscriptionCollection collection = managementGroup.GetManagementGroupSubscriptions(); + + // invoke the operation + string subscriptionId = "728bcbe4-8d56-4510-86c2-4921b8beefbc"; + string cacheControl = "no-cache"; + ArmOperation lro = await collection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionId, cacheControl: cacheControl); + ManagementGroupSubscriptionResource result = lro.Value; + + // the variable result is a resource, you could call other operations on this instance as well + // but just for demo, we get its data from this resource instance + ManagementGroupSubscriptionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetSubscriptionFromManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetSubscriptionFromManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetSubscriptionFromManagementGroup.json + // this example is just showing the usage of "ManagementGroupSubscriptions_GetSubscription" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "Group"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupSubscriptionResource + ManagementGroupSubscriptionCollection collection = managementGroup.GetManagementGroupSubscriptions(); + + // invoke the operation + string subscriptionId = "728bcbe4-8d56-4510-86c2-4921b8beefbc"; + string cacheControl = "no-cache"; + ManagementGroupSubscriptionResource result = await collection.GetAsync(subscriptionId, cacheControl: cacheControl); + + // the variable result is a resource, you could call other operations on this instance as well + // but just for demo, we get its data from this resource instance + ManagementGroupSubscriptionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // GetSubscriptionFromManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Exists_GetSubscriptionFromManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetSubscriptionFromManagementGroup.json + // this example is just showing the usage of "ManagementGroupSubscriptions_GetSubscription" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "Group"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupSubscriptionResource + ManagementGroupSubscriptionCollection collection = managementGroup.GetManagementGroupSubscriptions(); + + // invoke the operation + string subscriptionId = "728bcbe4-8d56-4510-86c2-4921b8beefbc"; + string cacheControl = "no-cache"; + bool result = await collection.ExistsAsync(subscriptionId, cacheControl: cacheControl); + + Console.WriteLine($"Succeeded: {result}"); + } + + // GetSubscriptionFromManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetIfExists_GetSubscriptionFromManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetSubscriptionFromManagementGroup.json + // this example is just showing the usage of "ManagementGroupSubscriptions_GetSubscription" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "Group"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupSubscriptionResource + ManagementGroupSubscriptionCollection collection = managementGroup.GetManagementGroupSubscriptions(); + + // invoke the operation + string subscriptionId = "728bcbe4-8d56-4510-86c2-4921b8beefbc"; + string cacheControl = "no-cache"; + NullableResponse response = await collection.GetIfExistsAsync(subscriptionId, cacheControl: cacheControl); + ManagementGroupSubscriptionResource result = response.HasValue ? response.Value : null; + + if (result == null) + { + Console.WriteLine($"Succeeded with null as result"); + } + else + { + // the variable result is a resource, you could call other operations on this instance as well + // but just for demo, we get its data from this resource instance + ManagementGroupSubscriptionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } + + // GetAllSubscriptionsFromManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task GetAll_GetAllSubscriptionsFromManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetAllSubscriptionsFromManagementGroup.json + // this example is just showing the usage of "ManagementGroupSubscriptions_GetSubscriptionsUnderManagementGroup" 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 ManagementGroupResource created on azure + // for more information of creating ManagementGroupResource, please refer to the document of ManagementGroupResource + string groupId = "Group"; + ResourceIdentifier managementGroupResourceId = ManagementGroupResource.CreateResourceIdentifier(groupId); + ManagementGroupResource managementGroup = client.GetManagementGroupResource(managementGroupResourceId); + + // get the collection of this ManagementGroupSubscriptionResource + ManagementGroupSubscriptionCollection collection = managementGroup.GetManagementGroupSubscriptions(); + + // invoke the operation and iterate over the result + await foreach (ManagementGroupSubscriptionResource item in collection.GetAllAsync()) + { + // the variable item is a resource, you could call other operations on this instance as well + // but just for demo, we get its data from this resource instance + ManagementGroupSubscriptionData resourceData = item.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + Console.WriteLine($"Succeeded"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/samples/Generated/Samples/Sample_ManagementGroupSubscriptionResource.cs b/sdk/resourcemanager/Azure.ResourceManager/samples/Generated/Samples/Sample_ManagementGroupSubscriptionResource.cs new file mode 100644 index 0000000000000..bab4d1ad4b3bc --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/samples/Generated/Samples/Sample_ManagementGroupSubscriptionResource.cs @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Identity; +using Azure.ResourceManager; +using Azure.ResourceManager.ManagementGroups; + +namespace Azure.ResourceManager.ManagementGroups.Samples +{ + public partial class Sample_ManagementGroupSubscriptionResource + { + // AddSubscriptionToManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Update_AddSubscriptionToManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/AddManagementGroupSubscription.json + // this example is just showing the usage of "ManagementGroupSubscriptions_Create" 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 ManagementGroupSubscriptionResource created on azure + // for more information of creating ManagementGroupSubscriptionResource, please refer to the document of ManagementGroupSubscriptionResource + string groupId = "Group"; + string subscriptionId = "728bcbe4-8d56-4510-86c2-4921b8beefbc"; + ResourceIdentifier managementGroupSubscriptionResourceId = ManagementGroupSubscriptionResource.CreateResourceIdentifier(groupId, subscriptionId); + ManagementGroupSubscriptionResource managementGroupSubscription = client.GetManagementGroupSubscriptionResource(managementGroupSubscriptionResourceId); + + // invoke the operation + string cacheControl = "no-cache"; + ArmOperation lro = await managementGroupSubscription.UpdateAsync(WaitUntil.Completed, cacheControl: cacheControl); + ManagementGroupSubscriptionResource result = lro.Value; + + // the variable result is a resource, you could call other operations on this instance as well + // but just for demo, we get its data from this resource instance + ManagementGroupSubscriptionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + + // DeleteSubscriptionFromManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Delete_DeleteSubscriptionFromManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/RemoveManagementGroupSubscription.json + // this example is just showing the usage of "ManagementGroupSubscriptions_Delete" 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 ManagementGroupSubscriptionResource created on azure + // for more information of creating ManagementGroupSubscriptionResource, please refer to the document of ManagementGroupSubscriptionResource + string groupId = "Group"; + string subscriptionId = "728bcbe4-8d56-4510-86c2-4921b8beefbc"; + ResourceIdentifier managementGroupSubscriptionResourceId = ManagementGroupSubscriptionResource.CreateResourceIdentifier(groupId, subscriptionId); + ManagementGroupSubscriptionResource managementGroupSubscription = client.GetManagementGroupSubscriptionResource(managementGroupSubscriptionResourceId); + + // invoke the operation + string cacheControl = "no-cache"; + await managementGroupSubscription.DeleteAsync(WaitUntil.Completed, cacheControl: cacheControl); + + Console.WriteLine($"Succeeded"); + } + + // GetSubscriptionFromManagementGroup + [NUnit.Framework.Test] + [NUnit.Framework.Ignore("Only verifying that the sample builds")] + public async Task Get_GetSubscriptionFromManagementGroup() + { + // Generated from example definition: specification/managementgroups/resource-manager/Microsoft.Management/stable/2021-04-01/examples/GetSubscriptionFromManagementGroup.json + // this example is just showing the usage of "ManagementGroupSubscriptions_GetSubscription" 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 ManagementGroupSubscriptionResource created on azure + // for more information of creating ManagementGroupSubscriptionResource, please refer to the document of ManagementGroupSubscriptionResource + string groupId = "Group"; + string subscriptionId = "728bcbe4-8d56-4510-86c2-4921b8beefbc"; + ResourceIdentifier managementGroupSubscriptionResourceId = ManagementGroupSubscriptionResource.CreateResourceIdentifier(groupId, subscriptionId); + ManagementGroupSubscriptionResource managementGroupSubscription = client.GetManagementGroupSubscriptionResource(managementGroupSubscriptionResourceId); + + // invoke the operation + string cacheControl = "no-cache"; + ManagementGroupSubscriptionResource result = await managementGroupSubscription.GetAsync(cacheControl: cacheControl); + + // the variable result is a resource, you could call other operations on this instance as well + // but just for demo, we get its data from this resource instance + ManagementGroupSubscriptionData resourceData = result.Data; + // for demo we just print out the id + Console.WriteLine($"Succeeded on id: {resourceData.Id}"); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/Azure.ResourceManager.csproj b/sdk/resourcemanager/Azure.ResourceManager/src/Azure.ResourceManager.csproj index f9a85dbe6dab7..20dc21e0892cb 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/Azure.ResourceManager.csproj +++ b/sdk/resourcemanager/Azure.ResourceManager/src/Azure.ResourceManager.csproj @@ -1,7 +1,7 @@ - 1.11.0-beta.1 + 1.10.2 1.10.1 Azure.ResourceManager diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/Extensions/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/Extensions/ArmClient.cs index 47c423e426c11..6881f263fc31b 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/Extensions/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/Extensions/ArmClient.cs @@ -23,5 +23,17 @@ public virtual ManagementGroupResource GetManagementGroupResource(ResourceIdenti ManagementGroupResource.ValidateResourceId(id); return new ManagementGroupResource(this, id); } + + /// + /// Gets an object representing a along with the instance operations that can be performed on it but with no data. + /// You can use to create a from its components. + /// + /// The resource ID of the resource to get. + /// Returns a object. + public virtual ManagementGroupSubscriptionResource GetManagementGroupSubscriptionResource(ResourceIdentifier id) + { + ManagementGroupSubscriptionResource.ValidateResourceId(id); + return new ManagementGroupSubscriptionResource(this, id); + } } } diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupResource.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupResource.cs index b33f7afab514c..abb6d8ab33c02 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupResource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupResource.cs @@ -90,6 +90,79 @@ internal static void ValidateResourceId(ResourceIdentifier id) throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Invalid resource type {0} expected {1}", id.ResourceType, ResourceType), nameof(id)); } + /// Gets a collection of ManagementGroupSubscriptionResources in the ManagementGroup. + /// An object representing collection of ManagementGroupSubscriptionResources and their operations over a ManagementGroupSubscriptionResource. + public virtual ManagementGroupSubscriptionCollection GetManagementGroupSubscriptions() + { + return GetCachedClient(client => new ManagementGroupSubscriptionCollection(client, Id)); + } + + /// + /// Retrieves details about given subscription which is associated with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscription + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + [ForwardsClientCalls] + public virtual async Task> GetManagementGroupSubscriptionAsync(string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + return await GetManagementGroupSubscriptions().GetAsync(subscriptionId, cacheControl, cancellationToken).ConfigureAwait(false); + } + + /// + /// Retrieves details about given subscription which is associated with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscription + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + [ForwardsClientCalls] + public virtual Response GetManagementGroupSubscription(string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + return GetManagementGroupSubscriptions().Get(subscriptionId, cacheControl, cancellationToken); + } + /// /// Get the details of the management group. /// diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionCollection.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionCollection.cs new file mode 100644 index 0000000000000..8cba425b3958b --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionCollection.cs @@ -0,0 +1,571 @@ +// 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.Globalization; +using System.Threading; +using System.Threading.Tasks; +using Autorest.CSharp.Core; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager; + +namespace Azure.ResourceManager.ManagementGroups +{ + /// + /// A class representing a collection of and their operations. + /// Each in the collection will belong to the same instance of . + /// To get a instance call the GetManagementGroupSubscriptions method from an instance of . + /// + public partial class ManagementGroupSubscriptionCollection : ArmCollection, IEnumerable, IAsyncEnumerable + { + private readonly ClientDiagnostics _managementGroupSubscriptionClientDiagnostics; + private readonly ManagementGroupSubscriptionsRestOperations _managementGroupSubscriptionRestClient; + + /// Initializes a new instance of the class for mocking. + protected ManagementGroupSubscriptionCollection() + { + } + + /// Initializes a new instance of the class. + /// The client parameters to use in these operations. + /// The identifier of the parent resource that is the target of operations. + internal ManagementGroupSubscriptionCollection(ArmClient client, ResourceIdentifier id) : base(client, id) + { + _managementGroupSubscriptionClientDiagnostics = new ClientDiagnostics("Azure.ResourceManager.ManagementGroups", ManagementGroupSubscriptionResource.ResourceType.Namespace, Diagnostics); + TryGetApiVersion(ManagementGroupSubscriptionResource.ResourceType, out string managementGroupSubscriptionApiVersion); + _managementGroupSubscriptionRestClient = new ManagementGroupSubscriptionsRestOperations(Pipeline, Diagnostics.ApplicationId, Endpoint, managementGroupSubscriptionApiVersion); +#if DEBUG + ValidateResourceId(Id); +#endif + } + + internal static void ValidateResourceId(ResourceIdentifier id) + { + if (id.ResourceType != ManagementGroupResource.ResourceType) + throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Invalid resource type {0} expected {1}", id.ResourceType, ManagementGroupResource.ResourceType), nameof(id)); + } + + /// + /// Associates existing subscription with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_Create + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// is null. + public virtual async Task> CreateOrUpdateAsync(WaitUntil waitUntil, string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionCollection.CreateOrUpdate"); + scope.Start(); + try + { + var response = await _managementGroupSubscriptionRestClient.CreateAsync(Id.Name, subscriptionId, cacheControl, cancellationToken).ConfigureAwait(false); + var operation = new ManagementGroupsArmOperation(Response.FromValue(new ManagementGroupSubscriptionResource(Client, response), response.GetRawResponse())); + if (waitUntil == WaitUntil.Completed) + await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Associates existing subscription with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_Create + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// is null. + public virtual ArmOperation CreateOrUpdate(WaitUntil waitUntil, string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionCollection.CreateOrUpdate"); + scope.Start(); + try + { + var response = _managementGroupSubscriptionRestClient.Create(Id.Name, subscriptionId, cacheControl, cancellationToken); + var operation = new ManagementGroupsArmOperation(Response.FromValue(new ManagementGroupSubscriptionResource(Client, response), response.GetRawResponse())); + if (waitUntil == WaitUntil.Completed) + operation.WaitForCompletion(cancellationToken); + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Retrieves details about given subscription which is associated with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscription + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// is null. + public virtual async Task> GetAsync(string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionCollection.Get"); + scope.Start(); + try + { + var response = await _managementGroupSubscriptionRestClient.GetSubscriptionAsync(Id.Name, subscriptionId, cacheControl, cancellationToken).ConfigureAwait(false); + if (response.Value == null) + throw new RequestFailedException(response.GetRawResponse()); + return Response.FromValue(new ManagementGroupSubscriptionResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Retrieves details about given subscription which is associated with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscription + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// is null. + public virtual Response Get(string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionCollection.Get"); + scope.Start(); + try + { + var response = _managementGroupSubscriptionRestClient.GetSubscription(Id.Name, subscriptionId, cacheControl, cancellationToken); + if (response.Value == null) + throw new RequestFailedException(response.GetRawResponse()); + return Response.FromValue(new ManagementGroupSubscriptionResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Retrieves details about all subscriptions which are associated with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscriptionsUnderManagementGroup + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// + /// Page continuation token is only used if a previous operation returned a partial result. + /// If a previous response contains a nextLink element, the value of the nextLink element will include a token parameter that specifies a starting point to use for subsequent calls. + /// + /// + /// The cancellation token to use. + /// An async collection of that may take multiple service requests to iterate over. + public virtual AsyncPageable GetAllAsync(string skipToken = null, CancellationToken cancellationToken = default) + { + HttpMessage FirstPageRequest(int? pageSizeHint) => _managementGroupSubscriptionRestClient.CreateGetSubscriptionsUnderManagementGroupRequest(Id.Name, skipToken); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => _managementGroupSubscriptionRestClient.CreateGetSubscriptionsUnderManagementGroupNextPageRequest(nextLink, Id.Name, skipToken); + return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new ManagementGroupSubscriptionResource(Client, ManagementGroupSubscriptionData.DeserializeManagementGroupSubscriptionData(e)), _managementGroupSubscriptionClientDiagnostics, Pipeline, "ManagementGroupSubscriptionCollection.GetAll", "value", "nextLink", cancellationToken); + } + + /// + /// Retrieves details about all subscriptions which are associated with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscriptionsUnderManagementGroup + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// + /// Page continuation token is only used if a previous operation returned a partial result. + /// If a previous response contains a nextLink element, the value of the nextLink element will include a token parameter that specifies a starting point to use for subsequent calls. + /// + /// + /// The cancellation token to use. + /// A collection of that may take multiple service requests to iterate over. + public virtual Pageable GetAll(string skipToken = null, CancellationToken cancellationToken = default) + { + HttpMessage FirstPageRequest(int? pageSizeHint) => _managementGroupSubscriptionRestClient.CreateGetSubscriptionsUnderManagementGroupRequest(Id.Name, skipToken); + HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => _managementGroupSubscriptionRestClient.CreateGetSubscriptionsUnderManagementGroupNextPageRequest(nextLink, Id.Name, skipToken); + return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new ManagementGroupSubscriptionResource(Client, ManagementGroupSubscriptionData.DeserializeManagementGroupSubscriptionData(e)), _managementGroupSubscriptionClientDiagnostics, Pipeline, "ManagementGroupSubscriptionCollection.GetAll", "value", "nextLink", cancellationToken); + } + + /// + /// Checks to see if the resource exists in azure. + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscription + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// is null. + public virtual async Task> ExistsAsync(string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionCollection.Exists"); + scope.Start(); + try + { + var response = await _managementGroupSubscriptionRestClient.GetSubscriptionAsync(Id.Name, subscriptionId, cacheControl, cancellationToken: cancellationToken).ConfigureAwait(false); + return Response.FromValue(response.Value != null, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Checks to see if the resource exists in azure. + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscription + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// is null. + public virtual Response Exists(string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionCollection.Exists"); + scope.Start(); + try + { + var response = _managementGroupSubscriptionRestClient.GetSubscription(Id.Name, subscriptionId, cacheControl, cancellationToken: cancellationToken); + return Response.FromValue(response.Value != null, response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Tries to get details for this resource from the service. + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscription + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// is null. + public virtual async Task> GetIfExistsAsync(string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionCollection.GetIfExists"); + scope.Start(); + try + { + var response = await _managementGroupSubscriptionRestClient.GetSubscriptionAsync(Id.Name, subscriptionId, cacheControl, cancellationToken: cancellationToken).ConfigureAwait(false); + if (response.Value == null) + return new NoValueResponse(response.GetRawResponse()); + return Response.FromValue(new ManagementGroupSubscriptionResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Tries to get details for this resource from the service. + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscription + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// is an empty string, and was expected to be non-empty. + /// is null. + public virtual NullableResponse GetIfExists(string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionCollection.GetIfExists"); + scope.Start(); + try + { + var response = _managementGroupSubscriptionRestClient.GetSubscription(Id.Name, subscriptionId, cacheControl, cancellationToken: cancellationToken); + if (response.Value == null) + return new NoValueResponse(response.GetRawResponse()); + return Response.FromValue(new ManagementGroupSubscriptionResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetAll().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetAll().GetEnumerator(); + } + + IAsyncEnumerator IAsyncEnumerable.GetAsyncEnumerator(CancellationToken cancellationToken) + { + return GetAllAsync(cancellationToken: cancellationToken).GetAsyncEnumerator(cancellationToken); + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionData.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionData.Serialization.cs new file mode 100644 index 0000000000000..f3f9e1b7cb298 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionData.Serialization.cs @@ -0,0 +1,241 @@ +// 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; +using Azure.ResourceManager.ManagementGroups.Models; +using Azure.ResourceManager.Models; + +namespace Azure.ResourceManager.ManagementGroups +{ + public partial class ManagementGroupSubscriptionData : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ManagementGroupSubscriptionData)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + if (options.Format != "W") + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (options.Format != "W") + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (options.Format != "W") + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(ResourceType); + } + if (options.Format != "W" && SystemData != null) + { + writer.WritePropertyName("systemData"u8); + JsonSerializer.Serialize(writer, SystemData); + } + writer.WritePropertyName("properties"u8); + writer.WriteStartObject(); + if (Tenant != null) + { + writer.WritePropertyName("tenant"u8); + writer.WriteStringValue(Tenant); + } + if (DisplayName != null) + { + writer.WritePropertyName("displayName"u8); + writer.WriteStringValue(DisplayName); + } + if (Parent != null) + { + if (Parent != null) + { + writer.WritePropertyName("parent"u8); + writer.WriteObjectValue(Parent); + } + else + { + writer.WriteNull("parent"); + } + } + if (State != null) + { + writer.WritePropertyName("state"u8); + writer.WriteStringValue(State); + } + writer.WriteEndObject(); + 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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ManagementGroupSubscriptionData 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(ManagementGroupSubscriptionData)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeManagementGroupSubscriptionData(document.RootElement, options); + } + + internal static ManagementGroupSubscriptionData DeserializeManagementGroupSubscriptionData(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ResourceIdentifier id = default; + string name = default; + ResourceType type = default; + SystemData systemData = default; + string tenant = default; + string displayName = default; + DescendantParentGroupInfo parent = default; + string state = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id"u8)) + { + id = new ResourceIdentifier(property.Value.GetString()); + continue; + } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ResourceType(property.Value.GetString()); + continue; + } + if (property.NameEquals("systemData"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + systemData = JsonSerializer.Deserialize(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("properties"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + property.ThrowNonNullablePropertyIsNull(); + continue; + } + foreach (var property0 in property.Value.EnumerateObject()) + { + if (property0.NameEquals("tenant"u8)) + { + tenant = property0.Value.GetString(); + continue; + } + if (property0.NameEquals("displayName"u8)) + { + displayName = property0.Value.GetString(); + continue; + } + if (property0.NameEquals("parent"u8)) + { + if (property0.Value.ValueKind == JsonValueKind.Null) + { + parent = null; + continue; + } + parent = DescendantParentGroupInfo.DeserializeDescendantParentGroupInfo(property0.Value, options); + continue; + } + if (property0.NameEquals("state"u8)) + { + state = property0.Value.GetString(); + continue; + } + } + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ManagementGroupSubscriptionData( + id, + name, + type, + systemData, + tenant, + displayName, + parent, + state, + 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); + default: + throw new FormatException($"The model {nameof(ManagementGroupSubscriptionData)} does not support '{options.Format}' format."); + } + } + + ManagementGroupSubscriptionData 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); + return DeserializeManagementGroupSubscriptionData(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ManagementGroupSubscriptionData)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionData.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionData.cs new file mode 100644 index 0000000000000..026c33b34913e --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionData.cs @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; +using Azure.ResourceManager.ManagementGroups.Models; +using Azure.ResourceManager.Models; + +namespace Azure.ResourceManager.ManagementGroups +{ + /// + /// A class representing the ManagementGroupSubscription data model. + /// The details of subscription under management group. + /// + public partial class ManagementGroupSubscriptionData : ResourceData + { + /// + /// 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 ManagementGroupSubscriptionData() + { + } + + /// Initializes a new instance of . + /// The id. + /// The name. + /// The resourceType. + /// The systemData. + /// The AAD Tenant ID associated with the subscription. For example, 00000000-0000-0000-0000-000000000000. + /// The friendly name of the subscription. + /// The ID of the parent management group. + /// The state of the subscription. + /// Keeps track of any properties unknown to the library. + internal ManagementGroupSubscriptionData(ResourceIdentifier id, string name, ResourceType resourceType, SystemData systemData, string tenant, string displayName, DescendantParentGroupInfo parent, string state, IDictionary serializedAdditionalRawData) : base(id, name, resourceType, systemData) + { + Tenant = tenant; + DisplayName = displayName; + Parent = parent; + State = state; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The AAD Tenant ID associated with the subscription. For example, 00000000-0000-0000-0000-000000000000. + public string Tenant { get; } + /// The friendly name of the subscription. + public string DisplayName { get; } + /// The ID of the parent management group. + internal DescendantParentGroupInfo Parent { get; } + /// The fully qualified ID for the parent management group. For example, /providers/Microsoft.Management/managementGroups/0000000-0000-0000-0000-000000000000. + public ResourceIdentifier ParentId + { + get => Parent?.Id; + } + + /// The state of the subscription. + public string State { get; } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionResource.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionResource.cs new file mode 100644 index 0000000000000..bbafb6de4dbba --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ManagementGroupSubscriptionResource.cs @@ -0,0 +1,351 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Globalization; +using System.Threading; +using System.Threading.Tasks; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager; + +namespace Azure.ResourceManager.ManagementGroups +{ + /// + /// A Class representing a ManagementGroupSubscription along with the instance operations that can be performed on it. + /// If you have a you can construct a + /// from an instance of using the GetManagementGroupSubscriptionResource method. + /// Otherwise you can get one from its parent resource using the GetManagementGroupSubscription method. + /// + public partial class ManagementGroupSubscriptionResource : ArmResource + { + /// Generate the resource identifier of a instance. + /// The groupId. + /// The subscriptionId. + public static ResourceIdentifier CreateResourceIdentifier(string groupId, string subscriptionId) + { + var resourceId = $"/providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId}"; + return new ResourceIdentifier(resourceId); + } + + private readonly ClientDiagnostics _managementGroupSubscriptionClientDiagnostics; + private readonly ManagementGroupSubscriptionsRestOperations _managementGroupSubscriptionRestClient; + private readonly ManagementGroupSubscriptionData _data; + + /// Gets the resource type for the operations. + public static readonly ResourceType ResourceType = "Microsoft.Management/managementGroups/subscriptions"; + + /// Initializes a new instance of the class for mocking. + protected ManagementGroupSubscriptionResource() + { + } + + /// Initializes a new instance of the class. + /// The client parameters to use in these operations. + /// The resource that is the target of operations. + internal ManagementGroupSubscriptionResource(ArmClient client, ManagementGroupSubscriptionData data) : this(client, data.Id) + { + HasData = true; + _data = data; + } + + /// 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 ManagementGroupSubscriptionResource(ArmClient client, ResourceIdentifier id) : base(client, id) + { + _managementGroupSubscriptionClientDiagnostics = new ClientDiagnostics("Azure.ResourceManager.ManagementGroups", ResourceType.Namespace, Diagnostics); + TryGetApiVersion(ResourceType, out string managementGroupSubscriptionApiVersion); + _managementGroupSubscriptionRestClient = new ManagementGroupSubscriptionsRestOperations(Pipeline, Diagnostics.ApplicationId, Endpoint, managementGroupSubscriptionApiVersion); +#if DEBUG + ValidateResourceId(Id); +#endif + } + + /// Gets whether or not the current instance has data. + public virtual bool HasData { get; } + + /// Gets the data representing this Feature. + /// Throws if there is no data loaded in the current instance. + public virtual ManagementGroupSubscriptionData Data + { + get + { + if (!HasData) + throw new InvalidOperationException("The current instance does not have data, you must call Get first."); + return _data; + } + } + + internal static void ValidateResourceId(ResourceIdentifier id) + { + if (id.ResourceType != ResourceType) + throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Invalid resource type {0} expected {1}", id.ResourceType, ResourceType), nameof(id)); + } + + /// + /// Retrieves details about given subscription which is associated with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscription + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + public virtual async Task> GetAsync(string cacheControl = null, CancellationToken cancellationToken = default) + { + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionResource.Get"); + scope.Start(); + try + { + var response = await _managementGroupSubscriptionRestClient.GetSubscriptionAsync(Id.Parent.Name, Id.Name, cacheControl, cancellationToken).ConfigureAwait(false); + if (response.Value == null) + throw new RequestFailedException(response.GetRawResponse()); + return Response.FromValue(new ManagementGroupSubscriptionResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Retrieves details about given subscription which is associated with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_GetSubscription + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + public virtual Response Get(string cacheControl = null, CancellationToken cancellationToken = default) + { + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionResource.Get"); + scope.Start(); + try + { + var response = _managementGroupSubscriptionRestClient.GetSubscription(Id.Parent.Name, Id.Name, cacheControl, cancellationToken); + if (response.Value == null) + throw new RequestFailedException(response.GetRawResponse()); + return Response.FromValue(new ManagementGroupSubscriptionResource(Client, response.Value), response.GetRawResponse()); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// De-associates subscription from the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_Delete + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + public virtual async Task DeleteAsync(WaitUntil waitUntil, string cacheControl = null, CancellationToken cancellationToken = default) + { + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionResource.Delete"); + scope.Start(); + try + { + var response = await _managementGroupSubscriptionRestClient.DeleteAsync(Id.Parent.Name, Id.Name, cacheControl, cancellationToken).ConfigureAwait(false); + var operation = new ManagementGroupsArmOperation(response); + if (waitUntil == WaitUntil.Completed) + await operation.WaitForCompletionResponseAsync(cancellationToken).ConfigureAwait(false); + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// De-associates subscription from the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_Delete + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + public virtual ArmOperation Delete(WaitUntil waitUntil, string cacheControl = null, CancellationToken cancellationToken = default) + { + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionResource.Delete"); + scope.Start(); + try + { + var response = _managementGroupSubscriptionRestClient.Delete(Id.Parent.Name, Id.Name, cacheControl, cancellationToken); + var operation = new ManagementGroupsArmOperation(response); + if (waitUntil == WaitUntil.Completed) + operation.WaitForCompletionResponse(cancellationToken); + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Associates existing subscription with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_Create + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + public virtual async Task> UpdateAsync(WaitUntil waitUntil, string cacheControl = null, CancellationToken cancellationToken = default) + { + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionResource.Update"); + scope.Start(); + try + { + var response = await _managementGroupSubscriptionRestClient.CreateAsync(Id.Parent.Name, Id.Name, cacheControl, cancellationToken).ConfigureAwait(false); + var operation = new ManagementGroupsArmOperation(Response.FromValue(new ManagementGroupSubscriptionResource(Client, response), response.GetRawResponse())); + if (waitUntil == WaitUntil.Completed) + await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// Associates existing subscription with the management group. + /// + /// + /// + /// Request Path + /// /providers/Microsoft.Management/managementGroups/{groupId}/subscriptions/{subscriptionId} + /// + /// + /// Operation Id + /// ManagementGroupSubscriptions_Create + /// + /// + /// Default Api Version + /// 2021-04-01 + /// + /// + /// Resource + /// + /// + /// + /// + /// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + public virtual ArmOperation Update(WaitUntil waitUntil, string cacheControl = null, CancellationToken cancellationToken = default) + { + using var scope = _managementGroupSubscriptionClientDiagnostics.CreateScope("ManagementGroupSubscriptionResource.Update"); + scope.Start(); + try + { + var response = _managementGroupSubscriptionRestClient.Create(Id.Parent.Name, Id.Name, cacheControl, cancellationToken); + var operation = new ManagementGroupsArmOperation(Response.FromValue(new ManagementGroupSubscriptionResource(Client, response), response.GetRawResponse())); + if (waitUntil == WaitUntil.Completed) + operation.WaitForCompletion(cancellationToken); + return operation; + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/Models/ListSubscriptionUnderManagementGroup.Serialization.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/Models/ListSubscriptionUnderManagementGroup.Serialization.cs new file mode 100644 index 0000000000000..bfe4716154f58 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/Models/ListSubscriptionUnderManagementGroup.Serialization.cs @@ -0,0 +1,148 @@ +// 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; +using Azure.ResourceManager.ManagementGroups; + +namespace Azure.ResourceManager.ManagementGroups.Models +{ + internal partial class ListSubscriptionUnderManagementGroup : IUtf8JsonSerializable, IJsonModel + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) => ((IJsonModel)this).Write(writer, new ModelReaderWriterOptions("W")); + + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ListSubscriptionUnderManagementGroup)} does not support '{format}' format."); + } + + writer.WriteStartObject(); + if (!(Value is ChangeTrackingList collection && collection.IsUndefined)) + { + writer.WritePropertyName("value"u8); + writer.WriteStartArray(); + foreach (var item in Value) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && NextLink != null) + { + writer.WritePropertyName("nextLink"u8); + writer.WriteStringValue(NextLink); + } + 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)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ListSubscriptionUnderManagementGroup 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(ListSubscriptionUnderManagementGroup)} does not support '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeListSubscriptionUnderManagementGroup(document.RootElement, options); + } + + internal static ListSubscriptionUnderManagementGroup DeserializeListSubscriptionUnderManagementGroup(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= new ModelReaderWriterOptions("W"); + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList value = default; + string nextLink = default; + IDictionary serializedAdditionalRawData = default; + Dictionary additionalPropertiesDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("value"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ManagementGroupSubscriptionData.DeserializeManagementGroupSubscriptionData(item, options)); + } + value = array; + continue; + } + if (property.NameEquals("nextLink"u8)) + { + nextLink = property.Value.GetString(); + continue; + } + if (options.Format != "W") + { + additionalPropertiesDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = additionalPropertiesDictionary; + return new ListSubscriptionUnderManagementGroup(value ?? new ChangeTrackingList(), nextLink, 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); + default: + throw new FormatException($"The model {nameof(ListSubscriptionUnderManagementGroup)} does not support '{options.Format}' format."); + } + } + + ListSubscriptionUnderManagementGroup 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); + return DeserializeListSubscriptionUnderManagementGroup(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ListSubscriptionUnderManagementGroup)} does not support '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/Models/ListSubscriptionUnderManagementGroup.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/Models/ListSubscriptionUnderManagementGroup.cs new file mode 100644 index 0000000000000..de615e7adfca8 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/Models/ListSubscriptionUnderManagementGroup.cs @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using Azure.Core; +using Azure.ResourceManager.ManagementGroups; + +namespace Azure.ResourceManager.ManagementGroups.Models +{ + /// The details of all subscriptions under management group. + internal partial class ListSubscriptionUnderManagementGroup + { + /// + /// 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 ListSubscriptionUnderManagementGroup() + { + Value = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// The list of subscriptions. + /// The URL to use for getting the next set of results. + /// Keeps track of any properties unknown to the library. + internal ListSubscriptionUnderManagementGroup(IReadOnlyList value, string nextLink, IDictionary serializedAdditionalRawData) + { + Value = value; + NextLink = nextLink; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// The list of subscriptions. + public IReadOnlyList Value { get; } + /// The URL to use for getting the next set of results. + public string NextLink { get; } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ResourceManagerModelFactory.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ResourceManagerModelFactory.cs index 7250869207a8c..71c0f3315e0e1 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ResourceManagerModelFactory.cs +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/ResourceManagerModelFactory.cs @@ -193,6 +193,30 @@ public static DescendantData DescendantData(ResourceIdentifier id = null, string serializedAdditionalRawData: null); } + /// Initializes a new instance of . + /// The id. + /// The name. + /// The resourceType. + /// The systemData. + /// The AAD Tenant ID associated with the subscription. For example, 00000000-0000-0000-0000-000000000000. + /// The friendly name of the subscription. + /// The ID of the parent management group. + /// The state of the subscription. + /// A new instance for mocking. + public static ManagementGroupSubscriptionData ManagementGroupSubscriptionData(ResourceIdentifier id = null, string name = null, ResourceType resourceType = default, SystemData systemData = null, string tenant = null, string displayName = null, ResourceIdentifier parentId = null, string state = null) + { + return new ManagementGroupSubscriptionData( + id, + name, + resourceType, + systemData, + tenant, + displayName, + parentId != null ? new DescendantParentGroupInfo(parentId, serializedAdditionalRawData: null) : null, + state, + serializedAdditionalRawData: null); + } + /// Initializes a new instance of . /// Required. True indicates name is valid and available. False indicates the name is invalid, unavailable, or both. /// Required if nameAvailable == false. Invalid indicates the name provided does not match the resource provider's naming requirements (incorrect length, unsupported characters, etc.) AlreadyExists indicates that the name is already in use and is therefore unavailable. diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/RestOperations/ManagementGroupSubscriptionsRestOperations.cs b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/RestOperations/ManagementGroupSubscriptionsRestOperations.cs new file mode 100644 index 0000000000000..10d104646f6aa --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/src/ManagementGroup/Generated/RestOperations/ManagementGroupSubscriptionsRestOperations.cs @@ -0,0 +1,577 @@ +// 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; +using Azure.Core; +using Azure.Core.Pipeline; +using Azure.ResourceManager.ManagementGroups.Models; + +namespace Azure.ResourceManager.ManagementGroups +{ + internal partial class ManagementGroupSubscriptionsRestOperations + { + private readonly TelemetryDetails _userAgent; + private readonly HttpPipeline _pipeline; + private readonly Uri _endpoint; + private readonly string _apiVersion; + + /// Initializes a new instance of ManagementGroupSubscriptionsRestOperations. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// The application id to use for user agent. + /// server parameter. + /// Api Version. + /// or is null. + public ManagementGroupSubscriptionsRestOperations(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 ?? "2021-04-01"; + _userAgent = new TelemetryDetails(GetType().Assembly, applicationId); + } + + internal HttpMessage CreateCreateRequest(string groupId, string subscriptionId, string cacheControl) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Put; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/providers/Microsoft.Management/managementGroups/", false); + uri.AppendPath(groupId, true); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + if (cacheControl != null) + { + request.Headers.Add("Cache-Control", cacheControl); + } + request.Headers.Add("Accept", "application/json"); + _userAgent.Apply(message); + return message; + } + + /// + /// Associates existing subscription with the management group. + /// + /// + /// Management Group ID. + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public async Task> CreateAsync(string groupId, string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (groupId == null) + { + throw new ArgumentNullException(nameof(groupId)); + } + if (groupId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(groupId)); + } + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var message = CreateCreateRequest(groupId, subscriptionId, cacheControl); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + ManagementGroupSubscriptionData value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = ManagementGroupSubscriptionData.DeserializeManagementGroupSubscriptionData(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw new RequestFailedException(message.Response); + } + } + + /// + /// Associates existing subscription with the management group. + /// + /// + /// Management Group ID. + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public Response Create(string groupId, string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (groupId == null) + { + throw new ArgumentNullException(nameof(groupId)); + } + if (groupId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(groupId)); + } + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var message = CreateCreateRequest(groupId, subscriptionId, cacheControl); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + ManagementGroupSubscriptionData value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = ManagementGroupSubscriptionData.DeserializeManagementGroupSubscriptionData(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw new RequestFailedException(message.Response); + } + } + + internal HttpMessage CreateDeleteRequest(string groupId, string subscriptionId, string cacheControl) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Delete; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/providers/Microsoft.Management/managementGroups/", false); + uri.AppendPath(groupId, true); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + if (cacheControl != null) + { + request.Headers.Add("Cache-Control", cacheControl); + } + request.Headers.Add("Accept", "application/json"); + _userAgent.Apply(message); + return message; + } + + /// + /// De-associates subscription from the management group. + /// + /// + /// Management Group ID. + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public async Task DeleteAsync(string groupId, string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (groupId == null) + { + throw new ArgumentNullException(nameof(groupId)); + } + if (groupId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(groupId)); + } + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var message = CreateDeleteRequest(groupId, subscriptionId, cacheControl); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + case 204: + return message.Response; + default: + throw new RequestFailedException(message.Response); + } + } + + /// + /// De-associates subscription from the management group. + /// + /// + /// Management Group ID. + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public Response Delete(string groupId, string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (groupId == null) + { + throw new ArgumentNullException(nameof(groupId)); + } + if (groupId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(groupId)); + } + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var message = CreateDeleteRequest(groupId, subscriptionId, cacheControl); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + case 204: + return message.Response; + default: + throw new RequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetSubscriptionRequest(string groupId, string subscriptionId, string cacheControl) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/providers/Microsoft.Management/managementGroups/", false); + uri.AppendPath(groupId, true); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(subscriptionId, true); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + if (cacheControl != null) + { + request.Headers.Add("Cache-Control", cacheControl); + } + request.Headers.Add("Accept", "application/json"); + _userAgent.Apply(message); + return message; + } + + /// + /// Retrieves details about given subscription which is associated with the management group. + /// + /// + /// Management Group ID. + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public async Task> GetSubscriptionAsync(string groupId, string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (groupId == null) + { + throw new ArgumentNullException(nameof(groupId)); + } + if (groupId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(groupId)); + } + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var message = CreateGetSubscriptionRequest(groupId, subscriptionId, cacheControl); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + ManagementGroupSubscriptionData value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = ManagementGroupSubscriptionData.DeserializeManagementGroupSubscriptionData(document.RootElement); + return Response.FromValue(value, message.Response); + } + case 404: + return Response.FromValue((ManagementGroupSubscriptionData)null, message.Response); + default: + throw new RequestFailedException(message.Response); + } + } + + /// + /// Retrieves details about given subscription which is associated with the management group. + /// + /// + /// Management Group ID. + /// Subscription ID. + /// Indicates whether the request should utilize any caches. Populate the header with 'no-cache' value to bypass existing caches. + /// The cancellation token to use. + /// or is null. + /// or is an empty string, and was expected to be non-empty. + public Response GetSubscription(string groupId, string subscriptionId, string cacheControl = null, CancellationToken cancellationToken = default) + { + if (groupId == null) + { + throw new ArgumentNullException(nameof(groupId)); + } + if (groupId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(groupId)); + } + if (subscriptionId == null) + { + throw new ArgumentNullException(nameof(subscriptionId)); + } + if (subscriptionId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(subscriptionId)); + } + + using var message = CreateGetSubscriptionRequest(groupId, subscriptionId, cacheControl); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + ManagementGroupSubscriptionData value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = ManagementGroupSubscriptionData.DeserializeManagementGroupSubscriptionData(document.RootElement); + return Response.FromValue(value, message.Response); + } + case 404: + return Response.FromValue((ManagementGroupSubscriptionData)null, message.Response); + default: + throw new RequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetSubscriptionsUnderManagementGroupRequest(string groupId, string skipToken) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/providers/Microsoft.Management/managementGroups/", false); + uri.AppendPath(groupId, true); + uri.AppendPath("/subscriptions", false); + uri.AppendQuery("api-version", _apiVersion, true); + if (skipToken != null) + { + uri.AppendQuery("$skiptoken", skipToken, true); + } + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + _userAgent.Apply(message); + return message; + } + + /// + /// Retrieves details about all subscriptions which are associated with the management group. + /// + /// + /// Management Group ID. + /// + /// Page continuation token is only used if a previous operation returned a partial result. + /// If a previous response contains a nextLink element, the value of the nextLink element will include a token parameter that specifies a starting point to use for subsequent calls. + /// + /// + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public async Task> GetSubscriptionsUnderManagementGroupAsync(string groupId, string skipToken = null, CancellationToken cancellationToken = default) + { + if (groupId == null) + { + throw new ArgumentNullException(nameof(groupId)); + } + if (groupId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(groupId)); + } + + using var message = CreateGetSubscriptionsUnderManagementGroupRequest(groupId, skipToken); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + ListSubscriptionUnderManagementGroup value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = ListSubscriptionUnderManagementGroup.DeserializeListSubscriptionUnderManagementGroup(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw new RequestFailedException(message.Response); + } + } + + /// + /// Retrieves details about all subscriptions which are associated with the management group. + /// + /// + /// Management Group ID. + /// + /// Page continuation token is only used if a previous operation returned a partial result. + /// If a previous response contains a nextLink element, the value of the nextLink element will include a token parameter that specifies a starting point to use for subsequent calls. + /// + /// + /// The cancellation token to use. + /// is null. + /// is an empty string, and was expected to be non-empty. + public Response GetSubscriptionsUnderManagementGroup(string groupId, string skipToken = null, CancellationToken cancellationToken = default) + { + if (groupId == null) + { + throw new ArgumentNullException(nameof(groupId)); + } + if (groupId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(groupId)); + } + + using var message = CreateGetSubscriptionsUnderManagementGroupRequest(groupId, skipToken); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + ListSubscriptionUnderManagementGroup value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = ListSubscriptionUnderManagementGroup.DeserializeListSubscriptionUnderManagementGroup(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw new RequestFailedException(message.Response); + } + } + + internal HttpMessage CreateGetSubscriptionsUnderManagementGroupNextPageRequest(string nextLink, string groupId, string skipToken) + { + var message = _pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendRawNextLink(nextLink, false); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + _userAgent.Apply(message); + return message; + } + + /// + /// Retrieves details about all subscriptions which are associated with the management group. + /// + /// + /// The URL to the next page of results. + /// Management Group ID. + /// + /// Page continuation token is only used if a previous operation returned a partial result. + /// If a previous response contains a nextLink element, the value of the nextLink element will include a token parameter that specifies a starting point to use for subsequent calls. + /// + /// + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public async Task> GetSubscriptionsUnderManagementGroupNextPageAsync(string nextLink, string groupId, string skipToken = null, CancellationToken cancellationToken = default) + { + if (nextLink == null) + { + throw new ArgumentNullException(nameof(nextLink)); + } + if (groupId == null) + { + throw new ArgumentNullException(nameof(groupId)); + } + if (groupId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(groupId)); + } + + using var message = CreateGetSubscriptionsUnderManagementGroupNextPageRequest(nextLink, groupId, skipToken); + await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false); + switch (message.Response.Status) + { + case 200: + { + ListSubscriptionUnderManagementGroup value = default; + using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false); + value = ListSubscriptionUnderManagementGroup.DeserializeListSubscriptionUnderManagementGroup(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw new RequestFailedException(message.Response); + } + } + + /// + /// Retrieves details about all subscriptions which are associated with the management group. + /// + /// + /// The URL to the next page of results. + /// Management Group ID. + /// + /// Page continuation token is only used if a previous operation returned a partial result. + /// If a previous response contains a nextLink element, the value of the nextLink element will include a token parameter that specifies a starting point to use for subsequent calls. + /// + /// + /// The cancellation token to use. + /// or is null. + /// is an empty string, and was expected to be non-empty. + public Response GetSubscriptionsUnderManagementGroupNextPage(string nextLink, string groupId, string skipToken = null, CancellationToken cancellationToken = default) + { + if (nextLink == null) + { + throw new ArgumentNullException(nameof(nextLink)); + } + if (groupId == null) + { + throw new ArgumentNullException(nameof(groupId)); + } + if (groupId.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", nameof(groupId)); + } + + using var message = CreateGetSubscriptionsUnderManagementGroupNextPageRequest(nextLink, groupId, skipToken); + _pipeline.Send(message, cancellationToken); + switch (message.Response.Status) + { + case 200: + { + ListSubscriptionUnderManagementGroup value = default; + using var document = JsonDocument.Parse(message.Response.ContentStream); + value = ListSubscriptionUnderManagementGroup.DeserializeListSubscriptionUnderManagementGroup(document.RootElement); + return Response.FromValue(value, message.Response); + } + default: + throw new RequestFailedException(message.Response); + } + } + } +} diff --git a/sdk/resourcemanager/Azure.ResourceManager/src/autorest.md b/sdk/resourcemanager/Azure.ResourceManager/src/autorest.md index 8462cbca76697..2f4132dabee67 100644 --- a/sdk/resourcemanager/Azure.ResourceManager/src/autorest.md +++ b/sdk/resourcemanager/Azure.ResourceManager/src/autorest.md @@ -703,7 +703,6 @@ operation-positions: Entities_List: collection operation-groups-to-omit: - HierarchySettings - - ManagementGroupSubscriptions - TenantBackfill no-property-type-replacement: DescendantParentGroupInfo @@ -719,6 +718,10 @@ rename-mapping: Permissions: EntityPermission Permissions.noaccess: NoAccess SearchOptions: EntitySearchOption + SubscriptionUnderManagementGroup: ManagementGroupSubscription + +override-operation-name: + ManagementGroupSubscriptions_GetSubscription: GetManagementGroupSubscription acronym-mapping: CPU: Cpu diff --git a/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/SubscriptionUnderManagementGroupCollectionTests.cs b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/SubscriptionUnderManagementGroupCollectionTests.cs new file mode 100644 index 0000000000000..404bbfe64c599 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager/tests/Scenario/SubscriptionUnderManagementGroupCollectionTests.cs @@ -0,0 +1,82 @@ +using System.Threading.Tasks; +using Azure.Core.TestFramework; +using Azure.ResourceManager.ManagementGroups; +using Azure.ResourceManager.ManagementGroups.Models; +using NUnit.Framework; + +namespace Azure.ResourceManager.Tests +{ + public class ManagementGroupSubscriptionCollectionTests : ResourceManagerTestBase + { + public ManagementGroupSubscriptionCollectionTests(bool isAsync) + :base(isAsync,RecordedTestMode.Record) + { + } + + public async Task CreateManagementGroupAsync() + { + var mgmtGroupName = Recording.GenerateAssetName("mgmt-group-"); + var mgmtGroupOp = await Client.GetManagementGroups().CreateOrUpdateAsync(WaitUntil.Started, mgmtGroupName, new ManagementGroupCreateOrUpdateContent()); + var mgmtGroup = await mgmtGroupOp.WaitForCompletionAsync(); + return mgmtGroup; + } + + [RecordedTest] + [Ignore("Unable to test this.")] + public async Task CreateOrUpdate() + { + var mgmtGroup = await CreateManagementGroupAsync(); + var subscriptionUnderMgmtGroupCollection = mgmtGroup.GetManagementGroupSubscriptions(); + var subscriptionId = (await Client.GetDefaultSubscriptionAsync()).Id.SubscriptionId; + var subscriptionUnderMgmtGroup = (await subscriptionUnderMgmtGroupCollection.CreateOrUpdateAsync(WaitUntil.Completed,subscriptionId)).Value; + Assert.AreEqual(subscriptionUnderMgmtGroup.Data.Id.SubscriptionId,subscriptionId); + } + + [RecordedTest] + [Ignore("Unable to test this.")] + public async Task Get() + { + var mgmtGroup = await CreateManagementGroupAsync(); + var subscriptionUnderMgmtGroupCollection = mgmtGroup.GetManagementGroupSubscriptions(); + var subscriptionId = (await Client.GetDefaultSubscriptionAsync()).Id.SubscriptionId; + var subscriptionUnderMgmtGroup = (await subscriptionUnderMgmtGroupCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionId)).Value; + var subscriptionUnderMgmtGroup1 = (await subscriptionUnderMgmtGroupCollection.GetAsync(subscriptionId)).Value; + Assert.AreEqual(subscriptionUnderMgmtGroup.Data.Name,subscriptionUnderMgmtGroup1.Data.Name); + Assert.AreEqual(subscriptionUnderMgmtGroup.Data.Id.SubscriptionId,subscriptionUnderMgmtGroup1.Data.Id.SubscriptionId); + } + + [RecordedTest] + [Ignore("Unable to test this.")] + public async Task GetAll() + { + ArmClientOptions options1 = new ArmClientOptions(); + ArmClientOptions options2 = new ArmClientOptions(); + var client1 = GetArmClient(options1); + var client2 = GetArmClient(options2); + var subscription1 = await client1.GetDefaultSubscriptionAsync(); + var subscription2 = await client2.GetDefaultSubscriptionAsync(); + var mgmtGroup = await CreateManagementGroupAsync(); + var subscriptionUnderMgmtGroupCollection = mgmtGroup.GetManagementGroupSubscriptions(); + _ = await subscriptionUnderMgmtGroupCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscription1.Id.SubscriptionId); + _ = await subscriptionUnderMgmtGroupCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscription2.Id.SubscriptionId); + var count = 0; + await foreach (var item in subscriptionUnderMgmtGroupCollection.GetAllAsync()) + { + count++; + }; + Assert.AreEqual(2, count); + } + + [RecordedTest] + [Ignore("Unable to test this.")] + public async Task Exist() + { + var mgmtGroup = await CreateManagementGroupAsync(); + var subscriptionUnderMgmtGroupCollection = mgmtGroup.GetManagementGroupSubscriptions(); + var subscriptionId = (await Client.GetDefaultSubscriptionAsync()).Id.SubscriptionId; + _ = await subscriptionUnderMgmtGroupCollection.CreateOrUpdateAsync(WaitUntil.Completed, subscriptionId); + Assert.IsTrue(await subscriptionUnderMgmtGroupCollection.ExistsAsync(subscriptionId)); + Assert.IsFalse(await subscriptionUnderMgmtGroupCollection.ExistsAsync(subscriptionId + 1)); + } + } +}