Skip to content

Commit e1c582d

Browse files
author
Yalin Li
authored
[ACR ]Update README.md and samples (Azure#22219)
* Update README.md * Update README.md * Update README.md * end_point -> endpoint * Address comments
1 parent 6cd6eeb commit e1c582d

15 files changed

+185
-135
lines changed

sdk/containerregistry/azure-containerregistry/README.md

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ The [Azure Identity library][identity] provides easy Azure Active Directory supp
4242
from azure.containerregistry import ContainerRegistryClient
4343
from azure.identity import DefaultAzureCredential
4444

45-
account_url = "https://mycontainerregistry.azurecr.io"
45+
endpoint = "https://mycontainerregistry.azurecr.io"
4646
audience = "https://management.azure.com"
47-
client = ContainerRegistryClient(account_url, DefaultAzureCredential(), audience=audience)
47+
client = ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience=audience)
4848
```
4949

5050
## Key concepts
@@ -56,12 +56,80 @@ For more information please see [Container Registry Concepts](https://docs.micro
5656

5757
## Examples
5858

59-
<!-- Pending Sample Creation -->
59+
The following sections provide several code snippets covering some of the most common ACR Service tasks, including:
60+
61+
- [List repositories](#list-repositories)
62+
- [List tags with anonymous access](#list-tags-with-anonymous-access)
63+
- [Set artifact properties](#set-artifact-properties)
64+
- [Delete images](#delete-images)
65+
66+
Please note that each sample assumes there is a `CONTAINERREGISTRY_ENDPOINT` environment variable set to a string containing the `https://` prefix and the name of the login server, for example "https://myregistry.azurecr.io".
67+
68+
### List repositories
69+
70+
Iterate through the collection of repositories in the registry.
71+
72+
```python
73+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
74+
75+
with ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience="https://management.azure.com") as client:
76+
# Iterate through all the repositories
77+
for repository_name in client.list_repository_names():
78+
print(repository_name)
79+
```
80+
81+
### List tags with anonymous access
82+
83+
Iterate through the collection of tags in the repository with anonymous access.
84+
85+
```python
86+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
87+
88+
with ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience="https://management.azure.com") as client:
89+
manifest = client.get_manifest_properties("library/hello-world", "latest")
90+
print(manifest.repository_name + ": ")
91+
for tag in manifest.tags:
92+
print(tag + "\n")
93+
```
94+
95+
### Set artifact properties
96+
97+
Set properties of an artifact.
98+
99+
```python
100+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
101+
102+
with ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience="https://management.azure.com") as client:
103+
# Set permissions on the v1 image's "latest" tag
104+
client.update_manifest_properties(
105+
"library/hello-world",
106+
"latest",
107+
can_write=False,
108+
can_delete=False
109+
)
110+
```
111+
112+
### Delete images
113+
114+
Delete images older than the first three in the repository.
115+
116+
```python
117+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
118+
119+
with ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience="https://management.azure.com") as client:
120+
for repository in client.list_repository_names():
121+
manifest_count = 0
122+
for manifest in client.list_manifest_properties(repository, order_by=ManifestOrder.LAST_UPDATE_TIME_DESCENDING):
123+
manifest_count += 1
124+
if manifest_count > 3:
125+
print("Deleting {}:{}".format(repository, manifest.digest))
126+
client.delete_manifest(repository, manifest.digest)
127+
```
60128

61129
## Troubleshooting
62130

63131
### General
64-
Form Recognizer client library will raise exceptions defined in [Azure Core][azure_core_exceptions].
132+
ACR client library will raise exceptions defined in [Azure Core][azure_core_exceptions].
65133

66134
### Logging
67135
This library uses the standard
@@ -82,7 +150,9 @@ describes available configurations for retries, logging, transport protocols, an
82150

83151
## Next steps
84152

85-
<!-- Pending Sample Creation -->
153+
- Go further with azure.containerregistry and our [samples][samples].
154+
- Watch a [demo or deep dive video](https://azure.microsoft.com/resources/videos/index/?service=container-registry).
155+
- Read more about the [Azure Container Registry service](https://docs.microsoft.com/azure/container-registry/container-registry-intro).
86156

87157
## Contributing
88158

@@ -112,14 +182,12 @@ additional questions or comments.
112182
[container_registry_concepts]: https://docs.microsoft.com/azure/container-registry/container-registry-concepts
113183
[azure_cli]: https://docs.microsoft.com/cli/azure
114184
[azure_sub]: https://azure.microsoft.com/free/
115-
[identity]: https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/identity/Azure.Identity/README.md
116-
117-
[samples]: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/containerregistry/Azure.Containers.ContainerRegistry/samples/
185+
[identity]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/README.md
186+
[samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/containerregistry/azure-containerregistry/samples
118187
[cla]: https://cla.microsoft.com
119188
[coc]: https://opensource.microsoft.com/codeofconduct/
120189
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
121190
[coc_contact]: mailto:opencode@microsoft.com
122-
123191
[azure_core_ref_docs]: https://aka.ms/azsdk/python/core/docs
124192
[azure_core_exceptions]: https://aka.ms/azsdk/python/core/docs#module-azure.core.exceptions
125193
[python_logging]: https://docs.python.org/3/library/logging.html

sdk/containerregistry/azure-containerregistry/azure/containerregistry/_container_registry_client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,8 @@ def delete_manifest(self, repository, tag_or_digest, **kwargs):
356356
357357
from azure.containerregistry import ContainerRepositoryClient
358358
from azure.identity import DefaultAzureCredential
359-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
360-
client = ContainerRepositoryClient(account_url, DefaultAzureCredential())
359+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
360+
client = ContainerRepositoryClient(endpoint, DefaultAzureCredential())
361361
client.delete_manifest("my_repository", "my_tag_or_digest")
362362
"""
363363
if _is_tag(tag_or_digest):
@@ -383,8 +383,8 @@ def delete_tag(self, repository, tag, **kwargs):
383383
384384
from azure.containerregistry import ContainerRepositoryClient
385385
from azure.identity import DefaultAzureCredential
386-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
387-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
386+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
387+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
388388
for artifact in client.list_tag_properties():
389389
client.delete_tag("my_repository", tag.name)
390390
"""
@@ -406,8 +406,8 @@ def get_manifest_properties(self, repository, tag_or_digest, **kwargs):
406406
407407
from azure.containerregistry import ContainerRepositoryClient
408408
from azure.identity import DefaultAzureCredential
409-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
410-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
409+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
410+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
411411
for artifact in client.list_manifest_properties():
412412
properties = client.get_manifest_properties("my_repository", artifact.digest)
413413
"""
@@ -436,8 +436,8 @@ def get_tag_properties(self, repository, tag, **kwargs):
436436
437437
from azure.containerregistry import ContainerRepositoryClient
438438
from azure.identity import DefaultAzureCredential
439-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
440-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
439+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
440+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
441441
for tag in client.list_tag_properties():
442442
tag_properties = client.get_tag_properties("my_repository", tag.name)
443443
"""
@@ -467,8 +467,8 @@ def list_tag_properties(self, repository, **kwargs):
467467
468468
from azure.containerregistry import ContainerRepositoryClient
469469
from azure.identity import DefaultAzureCredential
470-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
471-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
470+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
471+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
472472
for tag in client.list_tag_properties():
473473
tag_properties = client.get_tag_properties("my_repository", tag.name)
474474
"""
@@ -608,8 +608,8 @@ def update_manifest_properties(self, *args, **kwargs):
608608
609609
from azure.containerregistry import ContainerRepositoryClient
610610
from azure.identity import DefaultAzureCredential
611-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
612-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
611+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
612+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
613613
for artifact in client.list_manifest_properties():
614614
received_properties = client.update_manifest_properties(
615615
"my_repository",
@@ -677,8 +677,8 @@ def update_tag_properties(self, *args, **kwargs):
677677
678678
from azure.containerregistry import ContainerRepositoryClient, TagWriteableProperties
679679
from azure.identity import DefaultAzureCredential
680-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
681-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
680+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
681+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
682682
tag_identifier = "latest"
683683
received = client.update_tag_properties(
684684
"my_repository",

sdk/containerregistry/azure-containerregistry/azure/containerregistry/aio/_async_container_registry_client.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ async def delete_manifest(self, repository: str, tag_or_digest: str, **kwargs: A
346346
347347
from azure.containerregistry.aio import ContainerRepositoryClient
348348
from azure.identity.aio import DefaultAzureCredential
349-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
350-
client = ContainerRepositoryClient(account_url, DefaultAzureCredential())
349+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
350+
client = ContainerRepositoryClient(endpoint, DefaultAzureCredential())
351351
await client.delete_manifest("my_repository", "my_tag_or_digest")
352352
"""
353353
if _is_tag(tag_or_digest):
@@ -372,8 +372,8 @@ async def delete_tag(self, repository: str, tag: str, **kwargs: Any) -> None:
372372
373373
from azure.containerregistry.aio import ContainerRepositoryClient
374374
from azure.identity.aio import DefaultAzureCredential
375-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
376-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
375+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
376+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
377377
async for artifact in client.list_tag_properties():
378378
await client.delete_tag("my_repository", tag.name)
379379
"""
@@ -396,8 +396,8 @@ async def get_manifest_properties(
396396
397397
from azure.containerregistry.aio import ContainerRepositoryClient
398398
from azure.identity.aio import DefaultAzureCredential
399-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
400-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
399+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
400+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
401401
async for artifact in client.list_manifest_properties():
402402
properties = await client.get_manifest_properties("my_repository", artifact.digest)
403403
"""
@@ -426,8 +426,8 @@ async def get_tag_properties(self, repository: str, tag: str, **kwargs: Any) ->
426426
427427
from azure.containerregistry.aio import ContainerRepositoryClient
428428
from azure.identity.aio import DefaultAzureCredential
429-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
430-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
429+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
430+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
431431
async for tag in client.list_tag_properties():
432432
tag_properties = await client.get_tag_properties("my_repository", tag.name)
433433
"""
@@ -455,8 +455,8 @@ def list_tag_properties(self, repository: str, **kwargs: Any) -> AsyncItemPaged[
455455
456456
from azure.containerregistry.aio import ContainerRepositoryClient
457457
from azure.identity.aio import DefaultAzureCredential
458-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
459-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
458+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
459+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
460460
async for tag in client.list_tag_properties():
461461
tag_properties = await client.get_tag_properties(tag.name)
462462
"""
@@ -642,8 +642,8 @@ async def update_manifest_properties(
642642
643643
from azure.containerregistry.aio import ContainerRepositoryClient
644644
from azure.identity.aio import DefaultAzureCredential
645-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
646-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
645+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
646+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
647647
async for artifact in client.list_manifest_properties():
648648
received_properties = await client.update_manifest_properties(
649649
"my_repository",
@@ -712,8 +712,8 @@ async def update_tag_properties(
712712
713713
from azure.containerregistry.aio import ContainerRepositoryClient
714714
from azure.identity.aio import DefaultAzureCredential
715-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
716-
client = ContainerRepositoryClient(account_url, "my_repository", DefaultAzureCredential())
715+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
716+
client = ContainerRepositoryClient(endpoint, "my_repository", DefaultAzureCredential())
717717
tag_identifier = "latest"
718718
received = await client.update_tag_properties(
719719
"my_repository",

sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_delete_images_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def __init__(self):
3535
async def delete_images(self):
3636
# [START list_repository_names]
3737
audience = "https://management.azure.com"
38-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
38+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
3939
credential = DefaultAzureCredential()
40-
client = ContainerRegistryClient(account_url, credential, audience=audience)
40+
client = ContainerRegistryClient(endpoint, credential, audience=audience)
4141

4242
async with client:
4343
async for repository in client.list_repository_names():

sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_delete_tags_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ def __init__(self):
3535
async def delete_tags(self):
3636
# [START list_repository_names]
3737
audience = "https://management.azure.com"
38-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
38+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
3939
credential = DefaultAzureCredential()
40-
client = ContainerRegistryClient(account_url, credential, audience=audience)
40+
client = ContainerRegistryClient(endpoint, credential, audience=audience)
4141

4242
async with client:
4343
async for repository in client.list_repository_names():

sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_hello_world_async.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ def __init__(self):
3434
async def create_registry_client(self):
3535
# Instantiate the ContainerRegistryClient
3636
# [START create_registry_client]
37-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
37+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
3838
audience = "https://management.azure.com"
39-
client = ContainerRegistryClient(account_url, DefaultAzureCredential(), audience=audience)
39+
client = ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience=audience)
4040
# [END create_registry_client]
4141

4242
async def basic_sample(self):
4343
# Instantiate the client
44-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
44+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
4545
audience = "https://management.azure.com"
46-
client = ContainerRegistryClient(account_url, DefaultAzureCredential(), audience=audience)
46+
client = ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience=audience)
4747
async with client:
4848
# Iterate through all the repositories
4949
async for repository_name in client.list_repository_names():

sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_list_tags_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def __init__(self):
3838
async def list_tags(self):
3939
# Create a new ContainerRegistryClient
4040
audience = "https://management.azure.com"
41-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
41+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
4242
credential = DefaultAzureCredential()
43-
client = ContainerRegistryClient(account_url, credential, audience=audience)
43+
client = ContainerRegistryClient(endpoint, credential, audience=audience)
4444

4545
manifest = await client.get_manifest_properties("library/hello-world", "latest")
4646
print(manifest.repository_name + ": ")

sdk/containerregistry/azure-containerregistry/samples/async_samples/sample_set_image_properties_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ def __init__(self):
3636

3737
async def set_image_properties(self):
3838
# Create a new ContainerRegistryClient
39-
account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
39+
endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]
4040
audience = "https://management.azure.com"
4141
credential = DefaultAzureCredential()
42-
client = ContainerRegistryClient(account_url, credential, audience=audience)
42+
client = ContainerRegistryClient(endpoint, credential, audience=audience)
4343

4444
# [START update_manifest_properties]
4545
# Set permissions on the v1 image's "latest" tag

0 commit comments

Comments
 (0)