azure-sdk-for-net
azure-sdk-for-net copied to clipboard
[BUG] ResourcesManagementClient requires a subscriptionId parameter, but calling Subscriptions doesn't use it
Describe the bug
Object Azure.ResourceManager.Resources.ResourcesManagementClient
requires string subscriptionId
. The string name is completely misleading for my use case, which works.
I want to list all subscriptions from a logged-in user's tenant (ignoring the case where one account can have multiple tenants).
Consider this use case:
public ResourcesManagementClient(string subscriptionId, TokenCredential tokenCredential, ResourcesManagementClientOptions options = null);
var credential = new DefaultAzureCredential();
var resourcesManagementClient = new ResourcesManagementClient("", credential);
var x = resourcesManagementClient.Subscriptions.List().ToList();
Note, that while creating a new ResourcesManagementClient
I gave an empty string to the string subscriptionId
parameter. This is very convoluted and it is not mentioned in the documentation (at least I didn't find it from many many hours of searching). All of this while ResourcesManagementClient
requires a string subscriptionId
parameter.
From what I understand, that resourcesManagementClient.Subscriptions.List()
calls https://graph.microsoft.com/beta/subscriptions
endpoint, which does not require that parameter.
The fact that I saw string subscriptionId
made me think I need to use some other object, which burnt a lot of unneeded hours. Maybe making the variable optional, or adding comments that certain uses don't require that parameter and it can be set to an empty string could be beneficial. At least mentioning this in documentation should be necessary.
If I missed something and it's my fault for not noticing, I'm sorry in advance.
Environment:
- Azure.ResourceManager.Resources 1.0.0-preview.2
a day later I noticed, that new DefaultAzureCredential()
returns credentials for the running application, not for a logged-in user. But this does not change the fact that the Subscriptions call doesn't require an id.
Thank you for your feedback. Tagging and routing to the team member best able to assist.
Thank you for the feedback. Yes, it makes sense. We are currently reworking the management APIs. This issue has been addressed in the design. We have plans to refresh all existing new Azure.ResourceManager.XXX libraries once the work is done. Please stay tuned and keep suggestions coming.
Hi @lukasan, the new Track 2 sdk integrates with the Azure.Identity library, so you can create Credential by given subscriptionId for the client. Please let me know if this can help you.
Sorry, @ArthurMa1978, but I don't work with this project any more so I can't answer you. But the idea was that without a subscription ID and only having the user details, I can get all subscriptions (or subscription IDs) that a user has access to in a tenant.