-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
Azure.Mgmt.CoreAzure management coreAzure management coreMgmtThis issue is related to a management-plane library.This issue is related to a management-plane library.bugThis issue requires a change to an existing behavior in the product in order to be resolved.This issue requires a change to an existing behavior in the product in order to be resolved.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.Workflow: The Azure SDK team believes it to be addressed and ready to close.
Milestone
Description
Is your feature request related to a problem? Please describe.
In Azure/azure-cli#10641 (comment), Azure CLI receives an incorrect --scope
/subscriptions/{subscription_id}/resourceGroups/
which lacks the resource group name. It gets injected into the resource URL, thus corrupting the command.
In order to fix it, I try to use azure.mgmt.core.tools.is_valid_resource_id
to detect whether a scope
is valid:
def is_valid_resource_id(rid, exception_type=None): |
Unfortunately, is_valid_resource_id
can't return the correct value for some edge cases like this.
A code snippet:
from azure.mgmt.core.tools import parse_resource_id, is_valid_resource_id
res_ids = ['/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/rg1',
'/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups',
'/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/',
'/subscriptions//resourceGroups/']
for res_id in res_ids:
print(res_id)
print(parse_resource_id(res_id))
print(is_valid_resource_id(res_id))
print()
Output:
/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/rg1
{'subscription': '0b1f6471-1bf0-4dda-aec3-cb9272f09590', 'resource_group': 'rg1'}
True
/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups
{'subscription': '0b1f6471-1bf0-4dda-aec3-cb9272f09590'}
False
# The trailing slash makes is_valid_resource_id return True
/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/
{'subscription': '0b1f6471-1bf0-4dda-aec3-cb9272f09590', 'resource_group': ''}
True
# Empty subscription ID shouldn't be allowed
/subscriptions//resourceGroups/
{'subscription': '', 'resource_group': ''}
True
Describe the solution you'd like
- No empty name
''
should be allowed when parsing a resource ID is_valid_resource_id
should returnFalse
for/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/
Metadata
Metadata
Assignees
Labels
Azure.Mgmt.CoreAzure management coreAzure management coreMgmtThis issue is related to a management-plane library.This issue is related to a management-plane library.bugThis issue requires a change to an existing behavior in the product in order to be resolved.This issue requires a change to an existing behavior in the product in order to be resolved.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.Workflow: The Azure SDK team believes it to be addressed and ready to close.