async def delete_old_tags(self): from azure.containerregistry import TagOrder from azure.containerregistry.aio import ( ContainerRegistryClient, ) from azure.identity.aio import DefaultAzureCredential # [START list_repository_names] account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] credential = DefaultAzureCredential() client = ContainerRegistryClient(account_url, credential) async with client: async for repository in client.list_repository_names(): print(repository) # [END list_repository_names] # [START list_tag_properties] # Keep the three most recent tags, delete everything else tag_count = 0 async for tag in client.list_tag_properties( repository, order_by=TagOrder.LAST_UPDATE_TIME_DESCENDING): tag_count += 1 if tag_count > 3: await client.delete_tag(repository, tag.name)
async def delete_old_tags(self): from azure.containerregistry import TagOrderBy from azure.containerregistry.aio import ( ContainerRegistryClient, ContainerRepositoryClient, ) from azure.identity.aio import DefaultAzureCredential # [START list_repositories] account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] credential = DefaultAzureCredential() client = ContainerRegistryClient(account_url, credential) async for repository in client.list_repositories(): repository_client = ContainerRepositoryClient( account_url, repository, credential) # [END list_repositories] # [START list_tags] tag_count = 0 async for tag in repository_client.list_tags( order_by=TagOrderBy.LAST_UPDATE_TIME_DESCENDING): tag_count += 1 if tag_count > 3: await repository_client.delete_tag(tag.name) # [END list_tags] await client.close()
async def test_construct_container_registry_client( self, containerregistry_endpoint): authority = get_authority(containerregistry_endpoint) credential = self.get_credential(authority) client = ContainerRegistryClient(endpoint=containerregistry_endpoint, credential=credential, audience="https://microsoft.com") with pytest.raises(ClientAuthenticationError): properties = await client.get_repository_properties(HELLO_WORLD) with pytest.raises(TypeError): client = ContainerRegistryClient( endpoint=containerregistry_endpoint, credential=credential)
def create_anon_client(self, endpoint, **kwargs): authority = get_authority(endpoint) audience = get_audience(authority) return ContainerRegistryClient(endpoint=endpoint, credential=None, audience=audience, **kwargs)
def create_registry_client(self): # Instantiate the ContainerRegistryClient # [START create_registry_client] from azure.containerregistry.aio import ContainerRegistryClient from azure.identity.aio import DefaultAzureCredential client = ContainerRegistryClient(self.account_url, DefaultAzureCredential())
class ListArtifactsTest(PerfStressTest): def __init__(self, arguments): super().__init__(arguments) account_url = self.get_from_env( "CONTAINERREGISTRY_ANONREGISTRY_ENDPOINT") audience = "https://management.azure.com" self.anon_client = ContainerRegistryClient(endpoint=account_url, credential=None, audience=audience) self.async_anon_client = AsyncContainerRegistryClient( endpoint=account_url, credential=None, audience=audience) self.repository = "node" async def close(self): await self.async_anon_client.close() await super().close() def run_sync(self): for _ in self.anon_client.list_manifest_properties(self.repository): pass async def run_async(self): async for _ in self.async_anon_client.list_manifest_properties( self.repository): pass
def __init__(self, arguments): super().__init__(arguments) account_url = self.get_from_env("CONTAINERREGISTRY_ANONREGISTRY_ENDPOINT") audience = "https://management.azure.com" self.anon_client = ContainerRegistryClient(endpoint=account_url, credential=None, audience=audience) self.async_anon_client = AsyncContainerRegistryClient(endpoint=account_url, credential=None, audience=audience)
async def basic_sample(self): # Instantiate an instance of ContainerRegistryClient # [START create_registry_client] endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"] audience = "https://management.azure.com" client = ContainerRegistryClient(endpoint, DefaultAzureCredential(), audience=audience) # [END create_registry_client] async with client: # Iterate through all the repositories async for repository_name in client.list_repository_names(): if repository_name == "hello-world": # Create a repository client from the registry client async for tag in client.list_tag_properties(repository_name): print(tag.digest) # [START delete_repository] await client.delete_repository(repository_name, "hello-world")
async def create_registry_client(self): # Instantiate the ContainerRegistryClient # [START create_registry_client] account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] audience = "https://management.azure.com" client = ContainerRegistryClient(account_url, DefaultAzureCredential(), audience=audience)
async def create_registry_client(self): # Instantiate the ContainerRegistryClient # [START create_registry_client] from azure.containerregistry.aio import ContainerRegistryClient from azure.identity.aio import DefaultAzureCredential account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] client = ContainerRegistryClient(account_url, DefaultAzureCredential())
async def basic_sample(self): from azure.containerregistry.aio import ContainerRegistryClient from azure.identity.aio import DefaultAzureCredential # Instantiate the client client = ContainerRegistryClient(self.account_url, DefaultAzureCredential()) async with client: # Iterate through all the repositories async for repository_name in client.list_repositories(): if repository_name == "hello-world": # Create a repository client from the registry client repository_client = client.get_repository_client(repository_name) async with repository_client: # Show all tags async for tag in repository_client.list_tags(): print(tag.digest)
async def basic_sample(self): from azure.containerregistry.aio import ContainerRegistryClient from azure.identity.aio import DefaultAzureCredential account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] # Instantiate the client client = ContainerRegistryClient(account_url, DefaultAzureCredential()) async with client: # Iterate through all the repositories async for repository_name in client.list_repository_names(): if repository_name == "hello-world": # Create a repository client from the registry client async for tag in client.list_tag_properties(repository_name): print(tag.digest) # [START delete_repository] await client.delete_repository(repository_name, "hello-world")
def create_registry_client(self, endpoint, **kwargs): authority = get_authority(endpoint) audience = kwargs.pop("audience", None) if not audience: audience = get_audience(authority) credential = self.get_credential(authority=authority) return ContainerRegistryClient(endpoint=endpoint, credential=credential, audience=audience, **kwargs)
async def basic_sample(self): from azure.containerregistry.aio import ContainerRegistryClient from azure.identity.aio import DefaultAzureCredential account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] # Instantiate the client client = ContainerRegistryClient(account_url, DefaultAzureCredential()) async with client: # Iterate through all the repositories async for repository_name in client.list_repository_names(): if repository_name == "hello-world": # Create a repository object from the registry client container_repository = client.get_repository(repository_name) async with container_repository: # Show all tags async for manifest in container_repository.list_manifests(): print(manifest.tags)
async def delete_images(self): # [START list_repository_names] audience = "https://management.azure.com" account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] credential = DefaultAzureCredential() client = ContainerRegistryClient(account_url, credential, audience=audience) async with client: async for repository in client.list_repository_names(): print(repository) # [END list_repository_names] # [START list_manifest_properties] # Keep the three most recent images, delete everything else manifest_count = 0 async for manifest in client.list_manifest_properties(repository, order_by=ManifestOrder.LAST_UPDATE_TIME_DESCENDING): manifest_count += 1 if manifest_count > 3: await client.delete_manifest(repository, manifest.digest)
async def delete_tags(self): # [START list_repository_names] audience = "https://management.azure.com" endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"] credential = DefaultAzureCredential() client = ContainerRegistryClient(endpoint, credential, audience=audience) async with client: async for repository in client.list_repository_names(): print(repository) # [END list_repository_names] # Keep the three most recent tags, delete everything else tag_count = 0 async for tag in client.list_tag_properties( repository, order_by=ArtifactTagOrder.LAST_UPDATED_ON_DESCENDING): tag_count += 1 if tag_count > 3: await client.delete_tag(repository, tag.name)
async def set_image_properties(self): # Instantiate an instance of ContainerRegistryClient endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"] audience = "https://management.azure.com" credential = DefaultAzureCredential() client = ContainerRegistryClient(endpoint, credential, audience=audience) # Set permissions on the v1 image's "latest" tag await client.update_manifest_properties("library/hello-world", "latest", can_write=False, can_delete=False)
async def list_tags(self): # Create a new ContainerRegistryClient audience = "https://management.azure.com" account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"] credential = DefaultAzureCredential() client = ContainerRegistryClient(account_url, credential, audience=audience) manifest = await client.get_manifest_properties( "library/hello-world", "latest") print(manifest.repository_name + ": ") for tag in manifest.tags: print(tag + "\n")
async def list_tags(self): # Instantiate an instance of ContainerRegistryClient audience = "https://management.azure.com" endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"] credential = DefaultAzureCredential() client = ContainerRegistryClient(endpoint, credential, audience=audience) manifest = await client.get_manifest_properties( "library/hello-world", "latest") print(manifest.repository_name + ": ") # Iterate through all the tags for tag in manifest.tags: print(tag + "\n")
class ListRepositoriesTest(PerfStressTest): def __init__(self, arguments): super().__init__(arguments) endpoint = self.get_from_env("CONTAINERREGISTRY_ANONREGISTRY_ENDPOINT") audience = "https://management.azure.com" self.anon_client = ContainerRegistryClient(endpoint=endpoint, credential=None, audience=audience) self.async_anon_client = AsyncContainerRegistryClient( endpoint=endpoint, credential=None, audience=audience) async def close(self): await self.async_anon_client.close() await super().close() def run_sync(self): for _ in self.anon_client.list_repository_names(): pass async def run_async(self): async for _ in self.async_anon_client.list_repository_names(): pass
def create_anon_client(self, endpoint, **kwargs): return ContainerRegistryClient(endpoint=endpoint, credential=None, **kwargs)
def create_registry_client(self, endpoint, **kwargs): return ContainerRegistryClient( endpoint=endpoint, credential=self.get_credential(), **kwargs, )