From 5508f5f8423f1237598ef3f71319c3894e564fa9 Mon Sep 17 00:00:00 2001 From: Feng Zhou Date: Sat, 10 Jul 2021 22:04:07 +0800 Subject: [PATCH 1/7] make the type of Parent of ResourceContainerBase to be OperationsBase --- .../src/Generated/ResourceGroupContainer.cs | 5 +++++ .../Azure.ResourceManager.Core/src/ResourceContainerBase.cs | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/ResourceGroupContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/ResourceGroupContainer.cs index b7bd7b3aadb4..30ad1defb971 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/ResourceGroupContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/ResourceGroupContainer.cs @@ -34,6 +34,11 @@ internal ResourceGroupContainer(SubscriptionOperations subscription) /// protected override ResourceType ValidResourceType => SubscriptionOperations.ResourceType; + /// + /// Gets the parent resource of this resource. + /// + protected new SubscriptionOperations Parent { get {return base.Parent as SubscriptionOperations;} } + private ResourceGroupsRestOperations RestClient { get diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs index 84269c9aaeda..bcbddcf9fa35 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ResourceContainerBase.cs @@ -48,11 +48,6 @@ protected ResourceContainerBase(OperationsBase parent) { } - /// - /// Gets the parent resource of this resource. - /// - protected new ResourceOperationsBase Parent { get {return base.Parent as ResourceOperationsBase;} } - /// /// Verify that the input resource Id is a valid container for this type. /// From 1712f4e17b194060d2c38736ba07b58a2a3c185f Mon Sep 17 00:00:00 2001 From: Feng Zhou Date: Mon, 12 Jul 2021 14:36:12 +0800 Subject: [PATCH 2/7] make TenantOperations the parent of SubscriptionContainer --- .../Azure.ResourceManager.Core/src/ArmClient.cs | 2 +- .../src/Generated/SubscriptionContainer.cs | 14 ++++++++++++-- .../src/Resources/LocationContainer.cs | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs index 012b4e63c299..6afbe291926c 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs @@ -133,7 +133,7 @@ private ArmClient( /// Subscription container. public virtual SubscriptionContainer GetSubscriptions() { - return new SubscriptionContainer(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline)); + return new SubscriptionContainer(Tenant); } /// diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs index 0ff4c6e1a6fd..1783c8c97772 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs @@ -25,8 +25,18 @@ protected SubscriptionContainer() /// Initializes a new instance of the class. /// /// - internal SubscriptionContainer(ClientContext clientContext) - : base(clientContext, null) + // internal SubscriptionContainer(ClientContext clientContext) + // : base(clientContext, null) + // { + // RestClient = new SubscriptionsRestOperations(this.Diagnostics, this.Pipeline); + // } + + /// + /// Initializes a new instance of the class. + /// + /// The resource representing the parent resource. + internal SubscriptionContainer(TenantOperations parent) + : base(parent) { RestClient = new SubscriptionsRestOperations(this.Diagnostics, this.Pipeline); } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationContainer.cs index 3397ee28f7f4..53462165d472 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/LocationContainer.cs @@ -42,7 +42,7 @@ internal LocationContainer(SubscriptionOperations subscriptionOperations) /// Subscription container. public SubscriptionContainer GetSubscriptions() { - return new SubscriptionContainer(new ClientContext(ClientOptions, Credential, BaseUri, Pipeline)); + return new SubscriptionContainer(new TenantOperations(ClientOptions, Credential, BaseUri, Pipeline)); } /// From f9cdf0422d76fdc78193d9bab59d75f707c5584a Mon Sep 17 00:00:00 2001 From: Feng Zhou Date: Mon, 12 Jul 2021 15:28:37 +0800 Subject: [PATCH 3/7] merge upstream --- .../Azure.ResourceManager.Core/src/ArmClient.cs | 2 +- .../src/Generated/FeatureContainer.cs | 5 +++++ .../src/Generated/SubscriptionContainer.cs | 10 ---------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs index 0820f6aced47..d09f1d11ee96 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs @@ -131,7 +131,7 @@ public ArmClient( /// Subscription container. public virtual SubscriptionContainer GetSubscriptions() { - return new SubscriptionContainer(Tenant); + return new SubscriptionContainer(_tenant); } /// diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/FeatureContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/FeatureContainer.cs index 3af480a13d37..55524eb9d14b 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/FeatureContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/FeatureContainer.cs @@ -36,6 +36,11 @@ internal FeatureContainer(ProviderOperations parent) _restClient = new FeaturesRestOperations(_clientDiagnostics, Pipeline, Id.SubscriptionId, BaseUri); } + /// + /// Gets the parent resource of this resource. + /// + protected new ProviderOperations Parent { get {return base.Parent as ProviderOperations;} } + /// protected override ResourceType ValidResourceType => ProviderOperations.ResourceType; diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs index fa62722242ac..a2916f155648 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs @@ -21,16 +21,6 @@ protected SubscriptionContainer() { } - /// - /// Initializes a new instance of the class. - /// - /// - // internal SubscriptionContainer(ClientContext clientContext) - // : base(clientContext, null) - // { - // RestClient = new SubscriptionsRestOperations(this.Diagnostics, this.Pipeline); - // } - /// /// Initializes a new instance of the class. /// From ce302e5235d089553890b7d1956ea20714ffe176 Mon Sep 17 00:00:00 2001 From: Feng Zhou Date: Mon, 12 Jul 2021 16:10:29 +0800 Subject: [PATCH 4/7] fix validation --- sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs | 2 +- .../src/Generated/SubscriptionContainer.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs index d09f1d11ee96..d6a0d52a8a03 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs @@ -93,10 +93,10 @@ public ArmClient( ClientOptions = options?.Clone() ?? new ArmClientOptions(); Pipeline = ManagementPipelineBuilder.Build(Credential, BaseUri, options ?? ClientOptions); + _tenant = new TenantOperations(ClientOptions, Credential, BaseUri, Pipeline); DefaultSubscription = string.IsNullOrWhiteSpace(defaultSubscriptionId) ? GetDefaultSubscription() : GetSubscriptions().TryGet(defaultSubscriptionId); - _tenant = new TenantOperations(ClientOptions, Credential, BaseUri, Pipeline); ClientOptions.ApiVersions.SetProviderClient(this); } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs index a2916f155648..b95838648e9d 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs @@ -131,7 +131,7 @@ async Task> NextPageFunc(string nextLink, int? pageSizeHint) /// The identifier of the resource. protected override void Validate(ResourceIdentifier identifier) { - if (!(identifier is null)) + if (identifier != ResourceIdentifier.RootResourceIdentifier) throw new ArgumentException("Invalid parent for subscription container", nameof(identifier)); } From 03c1ce212e1ba59d171354ddaf0463a17e654c18 Mon Sep 17 00:00:00 2001 From: Feng Zhou Date: Mon, 12 Jul 2021 16:32:18 +0800 Subject: [PATCH 5/7] fix the ValidResourceType for SubscriptionContainer --- .../src/Generated/SubscriptionContainer.cs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs index b95838648e9d..59baae3a13f4 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/SubscriptionContainer.cs @@ -31,10 +31,15 @@ internal SubscriptionContainer(TenantOperations parent) RestClient = new SubscriptionsRestOperations(this.Diagnostics, this.Pipeline, this.BaseUri); } + /// + /// Gets the parent resource of this resource. + /// + protected new TenantOperations Parent { get {return base.Parent as TenantOperations;} } + /// /// Gets the valid resource type associated with the container. /// - protected override ResourceType ValidResourceType => SubscriptionOperations.ResourceType; + protected override ResourceType ValidResourceType => TenantOperations.ResourceType; /// /// Gets the operations that can be performed on the container. @@ -125,16 +130,6 @@ async Task> NextPageFunc(string nextLink, int? pageSizeHint) return PageableHelpers.CreateAsyncEnumerable(FirstPageFunc, NextPageFunc); } - /// - /// Validate the resource identifier is supported in the current container. - /// - /// The identifier of the resource. - protected override void Validate(ResourceIdentifier identifier) - { - if (identifier != ResourceIdentifier.RootResourceIdentifier) - throw new ArgumentException("Invalid parent for subscription container", nameof(identifier)); - } - /// /// Gets details for this subscription from the service. /// From e80a100155b155513156f89d5ddec9ea98747c43 Mon Sep 17 00:00:00 2001 From: Feng Zhou Date: Tue, 13 Jul 2021 10:47:16 +0800 Subject: [PATCH 6/7] refactor GetSubscriptions --- .../Azure.ResourceManager.Core/src/ArmClient.cs | 5 +---- .../src/Generated/TenantOperations.cs | 9 +++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs index f329c80b8fe9..52f3951d956e 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmClient.cs @@ -128,10 +128,7 @@ public ArmClient( /// Gets the Azure subscriptions. /// /// Subscription container. - public virtual SubscriptionContainer GetSubscriptions() - { - return new SubscriptionContainer(_tenant); - } + public virtual SubscriptionContainer GetSubscriptions() => _tenant.GetSubscriptions(); /// /// Gets the tenants. diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/TenantOperations.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/TenantOperations.cs index 52eedd63b4f2..59c0c1062aae 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/TenantOperations.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/TenantOperations.cs @@ -213,5 +213,14 @@ internal ManagementGroupOperations GetManagementGroupOperations(string id) { return new ManagementGroupOperations(this, id); } + + /// + /// Gets the subscription container for this tenant. + /// + /// A container of the subscriptions. + public virtual SubscriptionContainer GetSubscriptions() + { + return new SubscriptionContainer(this); + } } } From ebcffa067fd6fb3955a34832b68e5c0b0a14a32b Mon Sep 17 00:00:00 2001 From: Feng Zhou Date: Tue, 13 Jul 2021 11:19:58 +0800 Subject: [PATCH 7/7] override Parent for ManagementGroupContainer --- .../Generated/ManagementGroup/ManagementGroupContainer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/ManagementGroup/ManagementGroupContainer.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/ManagementGroup/ManagementGroupContainer.cs index d3a28e5d9cbb..fda384bc1988 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/ManagementGroup/ManagementGroupContainer.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Generated/ManagementGroup/ManagementGroupContainer.cs @@ -36,6 +36,11 @@ internal ManagementGroupContainer(TenantOperations tenant) _restClient = new ManagementGroupsRestOperations(_clientDiagnostics, Pipeline, BaseUri); } + /// + /// Gets the parent resource of this resource. + /// + protected new TenantOperations Parent { get {return base.Parent as TenantOperations;} } + /// protected override ResourceType ValidResourceType => TenantOperations.ResourceType;