Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5947e8b
get other conn types in list op
MilesHolland Jan 12, 2024
4f006da
accept empty connections in rest-local conversion
MilesHolland Jan 25, 2024
e319d40
Merge branch 'main' of https://github.com/azure/azure-sdk-for-python
MilesHolland Jan 25, 2024
e5af527
Merge branch 'main' into connections-jan-asks
MilesHolland Jan 25, 2024
9318317
azure blob base changes
MilesHolland Jan 31, 2024
d986da9
Merge branch 'main' into connections-jan-asks
MilesHolland Jan 31, 2024
1b6d921
partial replacement of if-else with maps in wc
MilesHolland Feb 2, 2024
6263dc6
more if-else removal refactors
MilesHolland Feb 5, 2024
4b6f2dc
Merge branch 'main' into connections-jan-asks
MilesHolland Feb 5, 2024
5882887
solidify connection changes
MilesHolland Feb 6, 2024
47c9b51
run black on v2
MilesHolland Feb 6, 2024
de24812
Merge branch 'main' into connections-jan-asks
MilesHolland Feb 6, 2024
5c8930f
initial self review
MilesHolland Feb 6, 2024
4b4c988
spelling
MilesHolland Feb 6, 2024
6f539fd
rerun black and ai nit
MilesHolland Feb 6, 2024
ea5b62f
more nits, and push flag to v2
MilesHolland Feb 7, 2024
7d4ca46
e2e test
MilesHolland Feb 7, 2024
d87bba7
Merge branch 'main' into connections-jan-asks
MilesHolland Feb 7, 2024
663ea4c
e2e test recordings and use 2024 restclient
MilesHolland Feb 7, 2024
a3907f9
analyze ci issues
MilesHolland Feb 7, 2024
2e85ab2
Merge branch 'main' into connections-jan-asks
MilesHolland Feb 7, 2024
5aa8207
mypy fixes
MilesHolland Feb 8, 2024
7795de7
more mypy
MilesHolland Feb 8, 2024
ec10c08
Merge branch 'connections-jan-asks' of github.com:MilesHolland/azure-…
MilesHolland Feb 8, 2024
0e2d312
remove 2024 conn dep until CI wakes up
MilesHolland Feb 8, 2024
31939b5
skip problematic test
MilesHolland Feb 8, 2024
e3be48b
try bumping mindep
MilesHolland Feb 8, 2024
710b06a
remove skip
MilesHolland Feb 8, 2024
b922eec
undo 1.14.0 dep
MilesHolland Feb 8, 2024
9d800cb
add back in 1.14 dep
MilesHolland Feb 8, 2024
a408731
comments
MilesHolland Feb 12, 2024
10922a1
linting
MilesHolland Feb 12, 2024
d2c66ed
remove extra line
MilesHolland Feb 12, 2024
dba0cbd
more linting
MilesHolland Feb 13, 2024
66e202c
run black
MilesHolland Feb 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
azure blob base changes
  • Loading branch information
MilesHolland committed Jan 31, 2024
commit 93183177e0073fbc941c0870bd1635ec4fc6bf91
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
AzureAIServiceConnection,
GitHubConnection,
CustomConnection,
AzureBlobStoreConnection,
)
from .mlindex import Index
from .project import Project
from .data import Data
from .configs import AzureOpenAIModelConfiguration
from azure.ai.ml.entities import ApiKeyConfiguration

__all__ = [
"BaseConnection",
Expand All @@ -31,5 +33,7 @@
"AzureOpenAIModelConfiguration",
"GitHubConnection",
"CustomConnection",
"AzureBlobStoreConnection",
"ApiKeyConfiguration"
]

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from azure.ai.ml.entities._credentials import ApiKeyConfiguration
from azure.core.credentials import TokenCredential
from azure.ai.ml._restclient.v2023_06_01_preview.models import ConnectionCategory


from azure.ai.ml.constants._common import (
WorkspaceConnectionTypes,
)
class BaseConnection:
"""A connection to a specific external AI system. This is a base class and should not be
instantiated directly. Use the child classes that are specialized for connections to different services.
Expand Down Expand Up @@ -46,7 +47,8 @@ def __init__(
**kwargs,
):
# Sneaky short-circuit to allow direct v2 WS conn injection without any
# polymorphic required argument hassles.
# polymorphic-argument hassles.
# See _from_v2_workspace_connection for usage.
if kwargs.pop("make_empty", False):
return

Expand Down Expand Up @@ -87,6 +89,9 @@ def _get_ai_connection_class_from_type(cls, conn_type: str):
AzureOpenAIConnection,
AzureAISearchConnection,
AzureAIServiceConnection,
GitHubConnection,
CustomConnection,
AzureBlobStoreConnection
)

cat = camel_to_snake(conn_type).lower()
Expand All @@ -96,6 +101,15 @@ def _get_ai_connection_class_from_type(cls, conn_type: str):
return AzureAISearchConnection
elif cat == camel_to_snake(ConnectionCategory.COGNITIVE_SERVICE).lower():
return AzureAIServiceConnection
elif cat == camel_to_snake(ConnectionCategory.GIT).lower():
return GitHubConnection
elif cat == camel_to_snake("azure_blob").lower():
return AzureBlobStoreConnection
elif (cat == camel_to_snake(ConnectionCategory.CUSTOM_KEYS).lower()
or cat == camel_to_snake(WorkspaceConnectionTypes.CUSTOM).lower()):
# Accept both custom_keys and custom as conversion type in case of
# improper input.
return CustomConnection
return BaseConnection


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class AzureOpenAIConnection(BaseConnection):
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
:param credentials: The credentials for authenticating the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
:param api_version: The api version that this connection was created for.
Expand All @@ -36,6 +34,8 @@ class AzureOpenAIConnection(BaseConnection):
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""

def __init__(
Expand Down Expand Up @@ -66,8 +66,8 @@ def api_version(self) -> Optional[str]:
def api_version(self, value: str) -> None:
"""Set the API version of the connection.

:return: the API version of the connection.
:rtype: str
:param value: the API version of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_API_VERSION_KEY] = value

Expand All @@ -86,8 +86,8 @@ def api_type(self) -> Optional[str]:
def api_type(self, value: str) -> None:
"""Set the API type of the connection.

:return: the API type of the connection.
:rtype: str
:param value: the API type of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_API_TYPE_KEY] = value

Expand Down Expand Up @@ -154,15 +154,15 @@ class AzureAISearchConnection(BaseConnection):
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
:param credentials: The credentials for authenticating the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
:param api_version: The api version that this connection was created for. Only applies to certain connection types.
:type api_version: Optional[str]
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""

def __init__(
Expand Down Expand Up @@ -192,8 +192,8 @@ def api_version(self) -> Optional[str]:
def api_version(self, value: str) -> None:
"""Set the API version of the connection.

:return: the API version of the connection.
:rtype: str
:param value: the API version of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_API_VERSION_KEY] = value

Expand Down Expand Up @@ -224,8 +224,6 @@ class AzureAIServiceConnection(BaseConnection):
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
:param credentials: The credentials for authenticating the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
:param api_version: The api version that this connection was created for.
Expand All @@ -236,6 +234,8 @@ class AzureAIServiceConnection(BaseConnection):
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""

def __init__(
Expand Down Expand Up @@ -265,8 +265,8 @@ def api_version(self) -> Optional[str]:
def api_version(self, value: str) -> None:
"""Set the API version of the connection.

:return: the API version of the connection.
:rtype: str
:param value: the API version of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_API_VERSION_KEY] = value

Expand All @@ -285,8 +285,8 @@ def kind(self) -> Optional[str]:
def kind(self, value: str) -> None:
"""Set the kind of the connection.

:return: the kind of the connection.
:rtype: str
:param value: the kind of the connection.
:type value: str
"""
self._workspace_connection.tags[CONNECTION_KIND_KEY] = value

Expand All @@ -297,13 +297,13 @@ class GitHubConnection(BaseConnection):
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
:param credentials: The credentials for authenticating the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""

def __init__(
Expand All @@ -316,20 +316,91 @@ def __init__(
kwargs.pop("type", None) # make sure we never somehow use wrong type
super().__init__(target=target, type="git", credentials=credentials, **kwargs)

class AzureBlobStoreConnection(BaseConnection):
"""A Connection to an Azure Blob Datastore.

:param name: Name of the connection.
:type name: str
:param target: The URL or ARM resource ID of the resource.
:type target: str
:param credentials: ?????
:type credentials: ?????
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""

def __init__(
self,
*,
target: str,
credentials = None,
container_name: str,
account_name: str,
**kwargs,
) -> None:
kwargs.pop("type", None) # make sure we never somehow use wrong type
super().__init__(
target=target,
type="azure_blob",
credentials=credentials,
container_name=container_name,
account_name=account_name,
**kwargs
)

@property
def container_name(self) -> str:
"""The container name of the connection.

:return: the container name of the connection.
:rtype: str
"""
return self._workspace_connection.container_name

@container_name.setter
def container_name(self, value: str) -> None:
"""Set the container name of the connection.

:param value: the new container name of the connection.
:type value: str
"""
self._workspace_connection.container_name = value

@property
def account_name(self) -> str:
"""The account name of the connection.

:return: the account name of the connection.
:rtype: str
"""
return self._workspace_connection.account_name

@account_name.setter
def account_name(self, value: str) -> None:
"""Set the account name of the connection.

:param value: the new account name of the connection.
:type value: str
"""
self._workspace_connection.account_name = value

class CustomConnection(BaseConnection):
"""A Connection to system that's not encapsulated by other connection types.

:param name: Name of the connection.
:type name: str
:param target: The URL or ARM resource ID of the external resource.
:type target: str
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
:param credentials: The credentials for authenticating the external resource.
:type credentials: ~azure.ai.ml.entities.ApiKeyConfiguration
:param is_shared: For connections created for a project, this determines if the connection
is shared amongst other connections with that project's parent AI resource. Defaults to True.
:type is_shared: bool
:param tags: Tag dictionary. Tags can be added, removed, and updated.
:type tags: dict
"""
def __init__(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def list(self, connection_type: Optional[str] = None, scope: str = OperationScop
client = self._resource_ml_client if scope == OperationScope.AI_RESOURCE else self._project_ml_client
return [
BaseConnection._from_v2_workspace_connection(conn)
for conn in client._workspace_connections.list(connection_type=connection_type)
for conn in client._workspace_connections.list(connection_type=connection_type, params={"includeAll": "true"})
]

@distributed_trace
Expand All @@ -58,11 +58,11 @@ def get(self, name: str, scope: str = OperationScope.AI_RESOURCE, **kwargs) -> B
"""
client = self._resource_ml_client if scope == OperationScope.AI_RESOURCE else self._project_ml_client
workspace_connection = client._workspace_connections.get(name=name, **kwargs)
connection = BaseConnection._from_v2_workspace_connection(workspace_connection)
connection = BaseConnection._from_v2_workspace_connection(workspace_connection, params={"includeAll": "true"})

# It's by design that both API and V2 SDK don't include the secrets from API response, the following
# code fills the gap when possible
if not connection.credentials.key:
if not (connection.credentials and connection.credentials.key):
list_secrets_response = client.connections._operation.list_secrets(
connection_name=name,
resource_group_name=client.resource_group_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,22 @@ def make(self, data, **kwargs):
from azure.ai.ml.entities import AzureAIServiceWorkspaceConnection

return AzureAIServiceWorkspaceConnection(**data)


# pylint: disable-next=name-too-long
class AzureBlobStoreWorkspaceConnectionSchema(WorkspaceConnectionSchema):
# type and credentials limited
type = StringTransformedEnum(
allowed_values=ConnectionCategory.COGNITIVE_SERVICE, casing_transform=camel_to_snake, required=True
)
credentials = NestedField(ApiKeyConfigurationSchema)

account_name = fields.Str(required=True, allow_none=False)
container_name = fields.Str(required=True, allow_none=False)


@post_load
def make(self, data, **kwargs):
from azure.ai.ml.entities import AzureBlobStoreWorkspaceConnection

return AzureBlobStoreWorkspaceConnection(**data)
4 changes: 3 additions & 1 deletion sdk/ml/azure-ai-ml/azure/ai/ml/constants/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@
CONNECTION_API_VERSION_KEY = "ApiVersion"
CONNECTION_API_TYPE_KEY = "ApiType"
CONNECTION_KIND_KEY = "Kind"
CONNECTION_CONTAINER_NAME_KEY = "ContainerName"
CONNECTION_ACCOUNT_NAME_KEY = "AccountName"


class DefaultOpenEncoding:
Expand Down Expand Up @@ -793,7 +795,7 @@ class InputOutputModes:
class WorkspaceConnectionTypes:
"""Names for workspace connection types that are different from that underlying api enum values."""

CUSTOM = "custom"
CUSTOM = "custom" # Corresponds to "custom_keys".


class LegacyAssetTypes:
Expand Down
Loading