Skip to content

Commit c0efabb

Browse files
authored
allow subscription-only requests for registry list operation (#26674)
* allow subscription only list calls for registry list * cl * change scope values to constant, correct ml * correct lower call * use scope constants for WS list function * move cl entry to correct file. * correct cl again * fix changelog syntax
1 parent 73300e0 commit c0efabb

File tree

6 files changed

+29
-8
lines changed

6 files changed

+29
-8
lines changed

sdk/ml/azure-ai-ml/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 1.1.0 (Unreleased)
44

55
### Features Added
6+
- Registry list operation now accepts scope value to allow subscription-only based requests.
67
- Most configuration classes from the entity package now implement the standard mapping protocol.
78

89
### Breaking Changes

sdk/ml/azure-ai-ml/azure/ai/ml/constants/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
__path__ = __import__("pkgutil").extend_path(__path__, __name__)
66

7-
from ._common import AssetTypes, InputOutputModes, ModelType, TimeZone
7+
from ._common import AssetTypes, InputOutputModes, ModelType, TimeZone, Scope
88
from ._component import ParallelTaskType
99
from ._deployment import BatchDeploymentOutputAction
1010
from ._job import (
@@ -38,4 +38,5 @@
3838
"AcrAccountSku",
3939
"NlpModels",
4040
"NlpLearningRateScheduler",
41+
"Scope",
4142
]

sdk/ml/azure-ai-ml/azure/ai/ml/constants/_common.py

+5
Original file line numberDiff line numberDiff line change
@@ -562,3 +562,8 @@ class RollingRate:
562562
DAY = "day"
563563
HOUR = "hour"
564564
MINUTE = "minute"
565+
566+
567+
class Scope:
568+
SUBSCRIPTION="subscription"
569+
RESOURCE_GROUP="resource_group"

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_registry_operations.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from azure.ai.ml._utils._experimental import experimental
2121
from .._utils._azureml_polling import AzureMLPolling
22-
from ..constants._common import LROConfigurations
22+
from ..constants._common import LROConfigurations, Scope
2323

2424
ops_logger = OpsLogger(__name__)
2525
module_logger = ops_logger.module_logger
@@ -52,14 +52,19 @@ def __init__(
5252
self._init_kwargs = kwargs
5353

5454
#@ monitor_with_activity(logger, "Registry.List", ActivityType.PUBLICAPI)
55-
def list(self) -> Iterable[Registry]:
55+
def list(self, *, scope: str = Scope.RESOURCE_GROUP) -> Iterable[Registry]:
5656
"""List all registries that the user has access to in the current
57-
resource group.
57+
resource group or subscription.
5858
59+
:param scope: scope of the listing, "resource_group" or "subscription", defaults to "resource_group"
60+
:type scope: str, optional
5961
:return: An iterator like instance of Registry objects
6062
:rtype: ~azure.core.paging.ItemPaged[Registry]
6163
"""
62-
64+
if scope.lower() == Scope.SUBSCRIPTION:
65+
return self._operation.list_by_subscription(
66+
cls=lambda objs: [Registry._from_rest_object(obj) for obj in objs]
67+
)
6368
return self._operation.list(cls=lambda objs: [Registry._from_rest_object(obj) for obj in objs], \
6469
resource_group_name=self._resource_group_name)
6570

sdk/ml/azure-ai-ml/azure/ai/ml/operations/_workspace_operations.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from azure.ai.ml._utils.utils import camel_to_snake
3333
from azure.ai.ml._version import VERSION
3434
from azure.ai.ml.constants import ManagedServiceIdentityType
35-
from azure.ai.ml.constants._common import ArmConstants, LROConfigurations, WorkspaceResourceConstants
35+
from azure.ai.ml.constants._common import ArmConstants, LROConfigurations, WorkspaceResourceConstants, Scope
3636
from azure.ai.ml.entities._credentials import IdentityConfiguration
3737
from azure.ai.ml.exceptions import ErrorCategory, ErrorTarget, ValidationException
3838
from azure.core.credentials import TokenCredential
@@ -70,7 +70,7 @@ def __init__(
7070
self.containerRegistry = "none"
7171

7272
# @monitor_with_activity(logger, "Workspace.List", ActivityType.PUBLICAPI)
73-
def list(self, *, scope: str = "resource_group") -> Iterable[Workspace]:
73+
def list(self, *, scope: str = Scope.RESOURCE_GROUP) -> Iterable[Workspace]:
7474
"""List all workspaces that the user has access to in the current
7575
resource group or subscription.
7676
@@ -80,7 +80,7 @@ def list(self, *, scope: str = "resource_group") -> Iterable[Workspace]:
8080
:rtype: ~azure.core.paging.ItemPaged[Workspace]
8181
"""
8282

83-
if scope == "subscription":
83+
if scope == Scope.SUBSCRIPTION:
8484
return self._operation.list_by_subscription(
8585
cls=lambda objs: [Workspace._from_rest_object(obj) for obj in objs]
8686
)

sdk/ml/azure-ai-ml/tests/registry/unittests/test_registry_operations.py

+9
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,18 @@ def mock_registry_operation(
2929
@pytest.mark.unittest
3030
class TestRegistryOperations:
3131
def test_list(self, mock_registry_operation: RegistryOperations) -> None:
32+
# Test different input options for the scope value
3233
mock_registry_operation.list()
3334
mock_registry_operation._operation.list.assert_called_once()
3435

36+
mock_registry_operation.list(scope="invalid")
37+
assert mock_registry_operation._operation.list.call_count == 2
38+
mock_registry_operation._operation.list_by_subscription.assert_not_called()
39+
40+
mock_registry_operation.list(scope="subscription")
41+
assert mock_registry_operation._operation.list.call_count == 2
42+
mock_registry_operation._operation.list_by_subscription.assert_called_once()
43+
3544
def test_get(self, mock_registry_operation: RegistryOperations, randstr: Callable[[], str]) -> None:
3645
mock_registry_operation.get(f"unittest_{randstr('reg_name')}")
3746
mock_registry_operation._operation.get.assert_called_once()

0 commit comments

Comments
 (0)