Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Container Registry] renamings #18492

Merged
merged 2 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from ._models import (
DeleteRepositoryResult,
ContentProperties,
RegistryArtifactOrderBy,
RegistryArtifactProperties,
ManifestOrderBy,
ArtifactManifestProperties,
RepositoryProperties,
TagOrderBy,
ArtifactTagProperties,
Expand All @@ -26,8 +26,8 @@
"ContainerRepositoryClient",
"DeleteRepositoryResult",
"ContentProperties",
"RegistryArtifactOrderBy",
"RegistryArtifactProperties",
"ManifestOrderBy",
"ArtifactManifestProperties",
"RepositoryProperties",
"TagOrderBy",
"ArtifactTagProperties",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ._helpers import _is_tag, _parse_next_link
from ._models import (
DeleteRepositoryResult,
RegistryArtifactProperties,
ArtifactManifestProperties,
RepositoryProperties,
ArtifactTagProperties,
)
Expand Down Expand Up @@ -105,19 +105,20 @@ def get_properties(self, **kwargs):

@distributed_trace
def get_registry_artifact_properties(self, tag_or_digest, **kwargs):
# type: (str, Dict[str, Any]) -> RegistryArtifactProperties
# type: (str, Dict[str, Any]) -> ArtifactManifestProperties
"""Get the properties of a registry artifact

:param tag_or_digest: The tag/digest of a registry artifact
:type tag_or_digest: str
:returns: :class:`~azure.containerregistry.RegistryArtifactProperties`
:returns: :class:`~azure.containerregistry.ArtifactManifestProperties`
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError`
"""
if _is_tag(tag_or_digest):
tag_or_digest = self._get_digest_from_tag(tag_or_digest)

return RegistryArtifactProperties._from_generated( # pylint: disable=protected-access
self._client.container_registry.get_manifest_properties(self.repository, tag_or_digest, **kwargs)
return ArtifactManifestProperties._from_generated( # pylint: disable=protected-access
self._client.container_registry.get_manifest_properties(self.repository, tag_or_digest, **kwargs),
repository=self.repository
)

@distributed_trace
Expand All @@ -137,17 +138,17 @@ def get_tag_properties(self, tag, **kwargs):

@distributed_trace
def list_registry_artifacts(self, **kwargs):
# type: (Dict[str, Any]) -> ItemPaged[RegistryArtifactProperties]
# type: (Dict[str, Any]) -> ItemPaged[ArtifactManifestProperties]
"""List the artifacts for a repository

:keyword last: Query parameter for the last item in the previous call. Ensuing
call will return values after last lexically
:paramtype last: str
:keyword order_by: Query parameter for ordering by time ascending or descending
:paramtype order_by: :class:`~azure.containerregistry.RegistryArtifactOrderBy`
:paramtype order_by: :class:`~azure.containerregistry.ManifestOrderBy`
:keyword results_per_page: Number of repositories to return per page
:paramtype results_per_page: int
:return: ItemPaged[:class:`RegistryArtifactProperties`]
:return: ItemPaged[:class:`ArtifactManifestProperties`]
:rtype: :class:`~azure.core.paging.ItemPaged`
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError`
"""
Expand All @@ -158,7 +159,7 @@ def list_registry_artifacts(self, **kwargs):
cls = kwargs.pop(
"cls",
lambda objs: [
RegistryArtifactProperties._from_generated(x) for x in objs # pylint: disable=protected-access
ArtifactManifestProperties._from_generated(x, repository=self.repository) for x in objs # pylint: disable=protected-access
],
)

Expand Down Expand Up @@ -377,20 +378,21 @@ def get_next(next_link=None):

@distributed_trace
def set_manifest_properties(self, digest, permissions, **kwargs):
# type: (str, ContentProperties, Dict[str, Any]) -> RegistryArtifactProperties
# type: (str, ContentProperties, Dict[str, Any]) -> ArtifactManifestProperties
"""Set the properties for a manifest

:param digest: Digest of a manifest
:type digest: str
:param permissions: The property's values to be set
:type permissions: ContentProperties
:returns: :class:`~azure.containerregistry.RegistryArtifactProperties`
:returns: :class:`~azure.containerregistry.ArtifactManifestProperties`
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError`
"""
return RegistryArtifactProperties._from_generated( # pylint: disable=protected-access
return ArtifactManifestProperties._from_generated( # pylint: disable=protected-access
self._client.container_registry.update_manifest_properties(
self.repository, digest, value=permissions._to_generated(), **kwargs # pylint: disable=protected-access
)
),
repository=self.repository
)

@distributed_trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _from_generated(cls, gen):
)


class RegistryArtifactProperties(object):
class ArtifactManifestProperties(object):
"""Represents properties of a registry artifact

:ivar str cpu_architecture: CPU Architecture of an artifact
Expand All @@ -85,7 +85,7 @@ class RegistryArtifactProperties(object):
:ivar last_updated_on: Time and date an artifact was last updated
:vartype last_updated_on: :class:`~datetime.datetime`
:ivar str operating_system: Operating system for the artifact
:ivar List[str] references: References for the artifact
:ivar str repository_name: Repository name the artifact belongs to
:ivar str size: Size of the artifact
:ivar List[str] tags: Tags associated with a registry artifact
:ivar writeable_properties: Permissions for an artifact
Expand All @@ -98,16 +98,16 @@ def __init__(self, **kwargs):
self.digest = kwargs.get("digest", None)
self.last_updated_on = kwargs.get("last_updated_on", None)
self.operating_system = kwargs.get("operating_system", None)
self.references = kwargs.get("references", None)
self.repository_name = kwargs.get("repository_name", None)
self.size = kwargs.get("size", None)
self.tags = kwargs.get("tags", None)
self.writeable_properties = kwargs.get("content_permissions", None)
if self.writeable_properties:
self.writeable_properties = ContentProperties._from_generated(self.writeable_properties)

@classmethod
def _from_generated(cls, generated):
# type: (ManifestAttributesBase) -> RegistryArtifactProperties
def _from_generated(cls, generated, **kwargs):
# type: (ManifestAttributesBase, Any) -> ArtifactManifestProperties
return cls(
cpu_architecture=generated.architecture,
created_on=generated.created_on,
Expand All @@ -117,6 +117,7 @@ def _from_generated(cls, generated):
size=generated.size,
tags=generated.tags,
content_permissions=generated.writeable_properties,
repository_name=kwargs.get("repository_name"),
seankane-msft marked this conversation as resolved.
Show resolved Hide resolved
)


Expand Down Expand Up @@ -160,7 +161,7 @@ def _from_generated(cls, generated):
)


class RegistryArtifactOrderBy(str, Enum):
class ManifestOrderBy(str, Enum):
"""Enum for ordering registry artifacts"""

LAST_UPDATE_TIME_DESCENDING = "timedesc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .._models import (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird nit: it seems that the convention for naming async client files is more like _container_repository_client_async.py from my experience (even though the user won't see this). Is there a reason you did _async_container...?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason, you're the first person to point this out too. I'll make a fix for that after this release, I think it will create a bunch of annoying merge conflicts if I do it now.

DeleteRepositoryResult,
ContentProperties,
RegistryArtifactProperties,
ArtifactManifestProperties,
RepositoryProperties,
ArtifactTagProperties,
)
Expand Down Expand Up @@ -104,19 +104,20 @@ async def get_properties(self, **kwargs: Dict[str, Any]) -> RepositoryProperties
@distributed_trace_async
async def get_registry_artifact_properties(
swathipil marked this conversation as resolved.
Show resolved Hide resolved
self, tag_or_digest: str, **kwargs: Dict[str, Any]
) -> RegistryArtifactProperties:
) -> ArtifactManifestProperties:
"""Get the properties of a registry artifact

:param tag_or_digest: The tag/digest of a registry artifact
:type tag_or_digest: str
:returns: :class:`~azure.containerregistry.RegistryArtifactProperties`
:returns: :class:`~azure.containerregistry.ArtifactManifestProperties`
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError`
"""
if _is_tag(tag_or_digest):
tag_or_digest = self._get_digest_from_tag(tag_or_digest)

return RegistryArtifactProperties._from_generated( # pylint: disable=protected-access
await self._client.container_registry.get_manifest_properties(self.repository, tag_or_digest, **kwargs)
return ArtifactManifestProperties._from_generated( # pylint: disable=protected-access
await self._client.container_registry.get_manifest_properties(self.repository, tag_or_digest, **kwargs),
repository=self.repository
)

@distributed_trace_async
Expand All @@ -134,17 +135,17 @@ async def get_tag_properties(self, tag: str, **kwargs: Dict[str, Any]) -> Artifa
)

@distributed_trace
def list_registry_artifacts(self, **kwargs: Dict[str, Any]) -> AsyncItemPaged[RegistryArtifactProperties]:
def list_registry_artifacts(self, **kwargs: Dict[str, Any]) -> AsyncItemPaged[ArtifactManifestProperties]:
"""List the artifacts for a repository

:keyword last: Query parameter for the last item in the previous call. Ensuing
call will return values after last lexically
:paramtype last: str
:keyword order_by: Query parameter for ordering by time ascending or descending
:paramtype order_by: :class:`~azure.containerregistry.RegistryArtifactOrderBy`
:paramtype order_by: :class:`~azure.containerregistry.ManifestOrderBy`
:keyword results_per_page: Number of repositories to return per page
:paramtype results_per_page: int
:return: ItemPaged[:class:`~azure.containerregistry.RegistryArtifactProperties`]
:return: ItemPaged[:class:`~azure.containerregistry.ArtifactManifestProperties`]
:rtype: :class:`~azure.core.async_paging.AsyncItemPaged`
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError`
"""
Expand All @@ -155,7 +156,7 @@ def list_registry_artifacts(self, **kwargs: Dict[str, Any]) -> AsyncItemPaged[Re
cls = kwargs.pop(
"cls",
lambda objs: [
RegistryArtifactProperties._from_generated(x) for x in objs # pylint: disable=protected-access
ArtifactManifestProperties._from_generated(x, repository=self.repository) for x in objs # pylint: disable=protected-access
],
)

Expand Down Expand Up @@ -381,13 +382,14 @@ async def set_manifest_properties(
:type digest: str
:param permissions: The property's values to be set
:type permissions: ContentProperties
:returns: :class:`~azure.containerregistry.RegistryArtifactProperties`
:returns: :class:`~azure.containerregistry.ArtifactManifestProperties`
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError`
"""
return RegistryArtifactProperties._from_generated( # pylint: disable=protected-access
return ArtifactManifestProperties._from_generated( # pylint: disable=protected-access
await self._client.container_registry.update_manifest_properties(
self.repository, digest, value=permissions._to_generated(), **kwargs # pylint: disable=protected-access
)
),
repository=self.repository
)

@distributed_trace_async
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from azure.containerregistry import (
DeleteRepositoryResult,
ContentProperties,
RegistryArtifactOrderBy,
RegistryArtifactProperties,
ManifestOrderBy,
ArtifactManifestProperties,
ArtifactTagProperties,
TagOrderBy,
)
Expand Down Expand Up @@ -70,7 +70,7 @@ def test_list_registry_artifacts(self, containerregistry_endpoint):
count = 0
for artifact in client.list_registry_artifacts():
assert artifact is not None
assert isinstance(artifact, RegistryArtifactProperties)
assert isinstance(artifact, ArtifactManifestProperties)
assert artifact.created_on is not None
assert isinstance(artifact.created_on, datetime)
assert artifact.last_updated_on is not None
Expand Down Expand Up @@ -101,7 +101,7 @@ def test_list_registry_artifacts_descending(self, containerregistry_endpoint):

prev_last_updated_on = None
count = 0
for artifact in client.list_registry_artifacts(order_by=RegistryArtifactOrderBy.LAST_UPDATE_TIME_DESCENDING):
for artifact in client.list_registry_artifacts(order_by=ManifestOrderBy.LAST_UPDATE_TIME_DESCENDING):
if prev_last_updated_on:
assert artifact.last_updated_on < prev_last_updated_on
prev_last_updated_on = artifact.last_updated_on
Expand All @@ -115,7 +115,7 @@ def test_list_registry_artifacts_ascending(self, containerregistry_endpoint):

prev_last_updated_on = None
count = 0
for artifact in client.list_registry_artifacts(order_by=RegistryArtifactOrderBy.LAST_UPDATE_TIME_ASCENDING):
for artifact in client.list_registry_artifacts(order_by=ManifestOrderBy.LAST_UPDATE_TIME_ASCENDING):
if prev_last_updated_on:
assert artifact.last_updated_on > prev_last_updated_on
prev_last_updated_on = artifact.last_updated_on
Expand All @@ -129,7 +129,7 @@ def test_get_registry_artifact_properties(self, containerregistry_endpoint):

properties = client.get_registry_artifact_properties("latest")

assert isinstance(properties, RegistryArtifactProperties)
assert isinstance(properties, ArtifactManifestProperties)
assert isinstance(properties.created_on, datetime)
assert isinstance(properties.last_updated_on, datetime)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
DeleteRepositoryResult,
ArtifactTagProperties,
ContentProperties,
RegistryArtifactOrderBy,
RegistryArtifactProperties,
ManifestOrderBy,
ArtifactManifestProperties,
TagOrderBy,
)
from azure.core.exceptions import ResourceNotFoundError
Expand All @@ -29,7 +29,7 @@ async def test_list_registry_artifacts(self, containerregistry_endpoint):

async for artifact in client.list_registry_artifacts():
assert artifact is not None
assert isinstance(artifact, RegistryArtifactProperties)
assert isinstance(artifact, ArtifactManifestProperties)
assert artifact.created_on is not None
assert isinstance(artifact.created_on, datetime)
assert artifact.last_updated_on is not None
Expand Down Expand Up @@ -277,7 +277,7 @@ async def test_list_registry_artifacts(self, containerregistry_endpoint):
count = 0
async for artifact in client.list_registry_artifacts():
assert artifact is not None
assert isinstance(artifact, RegistryArtifactProperties)
assert isinstance(artifact, ArtifactManifestProperties)
assert artifact.created_on is not None
assert isinstance(artifact.created_on, datetime)
assert artifact.last_updated_on is not None
Expand All @@ -293,7 +293,7 @@ async def test_list_registry_artifacts_descending(self, containerregistry_endpoi
prev_last_updated_on = None
count = 0
async for artifact in client.list_registry_artifacts(
order_by=RegistryArtifactOrderBy.LAST_UPDATE_TIME_DESCENDING
order_by=ManifestOrderBy.LAST_UPDATE_TIME_DESCENDING
):
if prev_last_updated_on:
assert artifact.last_updated_on < prev_last_updated_on
Expand All @@ -309,7 +309,7 @@ async def test_list_registry_artifacts_ascending(self, containerregistry_endpoin
prev_last_updated_on = None
count = 0
async for artifact in client.list_registry_artifacts(
order_by=RegistryArtifactOrderBy.LAST_UPDATE_TIME_ASCENDING
order_by=ManifestOrderBy.LAST_UPDATE_TIME_ASCENDING
):
if prev_last_updated_on:
assert artifact.last_updated_on > prev_last_updated_on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
ContainerRegistryClient,
ArtifactTagProperties,
ContentProperties,
RegistryArtifactProperties,
ArtifactManifestProperties,
)

from azure.core.credentials import AccessToken
Expand Down Expand Up @@ -276,7 +276,7 @@ def assert_tag(
assert tag.repository == repository

def assert_registry_artifact(self, tag_or_digest, expected_tag_or_digest):
assert isinstance(tag_or_digest, RegistryArtifactProperties)
assert isinstance(tag_or_digest, ArtifactManifestProperties)
assert tag_or_digest == expected_tag_or_digest


Expand Down