-
Notifications
You must be signed in to change notification settings - Fork 3k
[Container Registry] Improved samples #18263
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
Changes from 4 commits
2cd779a
89ff226
8ff2256
592f0c2
2902a53
16f264c
a3b9ba8
4bc1f2c
c9e4dcc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,6 +44,15 @@ def __init__(self, endpoint, repository, credential, **kwargs): | |
:type credential: :class:`~azure.core.credentials.TokenCredential` | ||
:returns: None | ||
:raises: None | ||
|
||
.. admonition:: Example: | ||
|
||
.. literalinclude:: ../samples/sample_create_client.py | ||
:start-after: [START create_registry_client] | ||
:end-before: [END create_registry_client] | ||
seankane-msft marked this conversation as resolved.
Show resolved
Hide resolved
|
||
:language: python | ||
:dedent: 8 | ||
:caption: Instantiate an instance of `ContainerRepositoryClient` | ||
""" | ||
if not endpoint.startswith("https://") and not endpoint.startswith("http://"): | ||
endpoint = "https://" + endpoint | ||
|
@@ -64,6 +73,17 @@ def delete(self, **kwargs): | |
:returns: Object containing information about the deleted repository | ||
:rtype: :class:`~azure.containerregistry.DeletedRepositoryResult` | ||
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError` | ||
|
||
Example | ||
|
||
.. code-block:: python | ||
|
||
from azure.containerregistry import ContainerRepositoryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] | ||
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential()) | ||
client.delete() | ||
""" | ||
return DeletedRepositoryResult._from_generated( # pylint: disable=protected-access | ||
self._client.container_registry.delete_repository(self.repository, **kwargs) | ||
|
@@ -78,6 +98,18 @@ def delete_registry_artifact(self, digest, **kwargs): | |
:type digest: str | ||
:returns: None | ||
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError` | ||
|
||
Example | ||
|
||
.. code-block:: python | ||
|
||
from azure.containerregistry import ContainerRepositoryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] | ||
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential()) | ||
for artifact in client.list_registry_artifacts(): | ||
client.delete_registry_artifact(artifact.digest) | ||
""" | ||
self._client.container_registry_repository.delete_manifest(self.repository, digest, **kwargs) | ||
|
||
|
@@ -89,6 +121,18 @@ def delete_tag(self, tag, **kwargs): | |
:param str tag: The tag to be deleted | ||
:returns: None | ||
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError` | ||
|
||
Example | ||
|
||
.. code-block:: python | ||
|
||
from azure.containerregistry import ContainerRepositoryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] | ||
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential()) | ||
for artifact in client.list_tags(): | ||
client.delete_tag(tag.name) | ||
""" | ||
self._client.container_registry_repository.delete_tag(self.repository, tag, **kwargs) | ||
|
||
|
@@ -99,6 +143,24 @@ def get_properties(self, **kwargs): | |
|
||
:returns: :class:`~azure.containerregistry.RepositoryProperties` | ||
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError` | ||
|
||
Example | ||
|
||
.. code-block:: python | ||
|
||
from azure.containerregistry import ContainerRepositoryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] | ||
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential()) | ||
repository_properties = client.get_properties() | ||
print(repository_properties.name) | ||
print(repository_properties.content_permissions) | ||
print(repository_properties.created_on) | ||
print(repository_properties.last_updated_on) | ||
print(repository_properties.manifest_count) | ||
print(repository_properties.registry) | ||
print(repository_properties.tag_count) | ||
""" | ||
return RepositoryProperties._from_generated( # pylint: disable=protected-access | ||
self._client.container_registry_repository.get_properties(self.repository, **kwargs) | ||
|
@@ -113,6 +175,18 @@ def get_registry_artifact_properties(self, tag_or_digest, **kwargs): | |
:type tag_or_digest: str | ||
:returns: :class:`~azure.containerregistry.RegistryArtifactProperties` | ||
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError` | ||
|
||
Example | ||
|
||
.. code-block:: python | ||
|
||
from azure.containerregistry import ContainerRepositoryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] | ||
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential()) | ||
for artifact in client.list_registry_artifacts(): | ||
properties = client.get_registry_artifact_properties(artifact.digest) | ||
""" | ||
if _is_tag(tag_or_digest): | ||
tag_or_digest = self._get_digest_from_tag(tag_or_digest) | ||
|
@@ -132,6 +206,18 @@ def get_tag_properties(self, tag, **kwargs): | |
:type tag: str | ||
:returns: :class:`~azure.containerregistry.TagProperties` | ||
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError` | ||
|
||
Example | ||
|
||
.. code-block:: python | ||
|
||
from azure.containerregistry import ContainerRepositoryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] | ||
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential()) | ||
for tag in client.list_tags(): | ||
tag_properties = client.get_tag_properties(tag.name) | ||
""" | ||
return TagProperties._from_generated( # pylint: disable=protected-access | ||
self._client.container_registry_repository.get_tag_properties(self.repository, tag, **kwargs) | ||
|
@@ -152,6 +238,18 @@ def list_registry_artifacts(self, **kwargs): | |
:return: ItemPaged[:class:`RegistryArtifactProperties`] | ||
:rtype: :class:`~azure.core.paging.ItemPaged` | ||
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError` | ||
|
||
Example | ||
|
||
.. code-block:: python | ||
|
||
from azure.containerregistry import ContainerRepositoryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] | ||
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential()) | ||
for artifact in client.list_registry_artifacts(): | ||
print(artifact.digest) | ||
""" | ||
name = self.repository | ||
last = kwargs.pop("last", None) | ||
|
@@ -270,6 +368,18 @@ def list_tags(self, **kwargs): | |
:return: ItemPaged[:class:`~azure.containerregistry.TagProperties`] | ||
:rtype: :class:`~azure.core.paging.ItemPaged` | ||
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError` | ||
|
||
Example | ||
|
||
.. code-block:: python | ||
|
||
from azure.containerregistry import ContainerRepositoryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] | ||
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential()) | ||
for tag in client.list_tags(): | ||
tag_properties = client.get_tag_properties(tag.name) | ||
""" | ||
name = self.repository | ||
last = kwargs.pop("last", None) | ||
|
@@ -384,6 +494,26 @@ def set_manifest_properties(self, digest, permissions, **kwargs): | |
:type permissions: ContentPermissions | ||
:returns: :class:`~azure.containerregistry.RegistryArtifactProperties` | ||
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError` | ||
|
||
Example | ||
|
||
.. code-block:: python | ||
|
||
from azure.containerregistry import ContainerRepositoryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] | ||
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential()) | ||
for artifact in client.list_registry_artifacts(): | ||
received_permissions = client.set_manifest_properties( | ||
artifact.digest, | ||
ContentPermissions( | ||
can_delete=False, | ||
can_list=False, | ||
can_read=False, | ||
can_write=False, | ||
), | ||
) | ||
""" | ||
return RegistryArtifactProperties._from_generated( # pylint: disable=protected-access | ||
self._client.container_registry_repository.update_manifest_attributes( | ||
|
@@ -402,6 +532,26 @@ def set_tag_properties(self, tag, permissions, **kwargs): | |
:type permissions: ContentPermissions | ||
:returns: :class:`~azure.containerregistry.TagProperties` | ||
:raises: :class:`~azure.core.exceptions.ResourceNotFoundError` | ||
|
||
Example | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there some sort of guideline on which samples should be inserted here vs. pointing to the samples folder? Was this just decided on due to length of sample? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't have a great understanding of how customers are going to use the library, which means we have limited samples but I wanted to include how each client method would be used so this was my compromise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes sense. Thinking from a user perspective, having samples in a But since you said you'll test things out in the UX studies, I'm good with this :) |
||
|
||
.. code-block:: python | ||
|
||
from azure.containerregistry import ContainerRepositoryClient | ||
from azure.identity import DefaultAzureCredential | ||
|
||
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] | ||
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential()) | ||
tag_identifier = "latest" | ||
received = client.set_tag_properties( | ||
tag_identifier, | ||
ContentPermissions( | ||
can_delete=False, | ||
can_list=False, | ||
can_read=False, | ||
can_write=False, | ||
), | ||
) | ||
""" | ||
return TagProperties._from_generated( # pylint: disable=protected-access | ||
self._client.container_registry_repository.update_tag_attributes( | ||
|
Uh oh!
There was an error while loading. Please reload this page.