示例#1
0
    def delete_old_tags(self):
        from azure.containerregistry import (
            ContainerRegistryClient,
            ContainerRepositoryClient,
            TagOrder
        )
        from azure.identity import DefaultAzureCredential

        # [START list_repositories]
        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
        credential = DefaultAzureCredential()
        client = ContainerRegistryClient(account_url, credential)

        for repository in client.list_repositories():
            repository_client = ContainerRepositoryClient(account_url, repository, credential)
            # [END list_repositories]

            # [START list_tags]
            tag_count = 0
            for tag in repository_client.list_tags(order_by=TagOrder.LAST_UPDATE_TIME_DESCENDING):
                tag_count += 1
                if tag_count > 3:
                    repository_client.delete_tag(tag.name)
            # [END list_tags]

        client.close()
示例#2
0
    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)
    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 = client.get_repository_properties(HELLO_WORLD)       
        with pytest.raises(ValueError):
            client = ContainerRegistryClient(endpoint=containerregistry_endpoint, credential=credential)
示例#4
0
    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)

        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
            for manifest in client.list_manifest_properties(
                    repository,
                    order_by=ManifestOrder.LAST_UPDATE_TIME_DESCENDING):
                manifest_count += 1
                if manifest_count > 3:
                    client.delete_manifest(repository, manifest.digest)
            # [END list_manifest_properties]

        client.close()
示例#5
0
    def create_registry_client(self):
        # Instantiate the ContainerRegistryClient
        # [START create_registry_client]
        from azure.containerregistry import ContainerRegistryClient
        from azure.identity import DefaultAzureCredential

        client = ContainerRegistryClient(self.account_url, DefaultAzureCredential())
    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 = client.get_manifest_properties("library/hello-world",
                                                  "latest")
        print(manifest.repository_name + ": ")
        for tag in manifest.tags:
            print(tag + "\n")

        client.close()
示例#7
0
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 create_anon_client(self, endpoint, **kwargs):
     authority = get_authority(endpoint)
     audience = get_audience(authority)
     return ContainerRegistryClient(endpoint=endpoint,
                                    credential=None,
                                    audience=audience,
                                    **kwargs)
示例#9
0
 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)
    def create_registry_client(self):
        # Instantiate the ContainerRegistryClient
        # [START create_registry_client]
        from azure.containerregistry import ContainerRegistryClient
        from azure.identity import DefaultAzureCredential
        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]

        client = ContainerRegistryClient(account_url, DefaultAzureCredential())
示例#11
0
    def basic_sample(self):

        from azure.containerregistry import ContainerRegistryClient
        from azure.identity import DefaultAzureCredential

        # Instantiate the client
        client = ContainerRegistryClient(self.account_url, DefaultAzureCredential())
        with client:
            # Iterate through all the repositories
            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)

                    with repository_client:
                        # Show all tags
                        for tag in repository_client.list_tags():
                            print(tag.digest)
 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)
     logger.warning("Authority: {} \nAuthorization scope: {}".format(
         authority, audience))
     return ContainerRegistryClient(endpoint=endpoint,
                                    credential=credential,
                                    audience=audience,
                                    **kwargs)
示例#13
0
    def list_tags(self):
        # Create a new ContainerRegistryClient
        audience = "https://management.azure.com"
        endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]

        with ContainerRegistryClient(endpoint,
                                     DefaultAzureCredential(),
                                     audience=audience) as client:
            manifest = client.get_manifest_properties("library/hello-world",
                                                      "latest")
            print(manifest.repository_name + ": ")
            for tag in manifest.tags:
                print(tag + "\n")
示例#14
0
    def set_image_properties(self):
        # Instantiate an instance of ContainerRegistryClient
        audience = "https://management.azure.com"
        endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]

        with ContainerRegistryClient(endpoint,
                                     DefaultAzureCredential(),
                                     audience=audience) as client:
            # Set permissions on the v1 image's "latest" tag
            client.update_manifest_properties("library/hello-world",
                                              "latest",
                                              can_write=False,
                                              can_delete=False)
    def basic_sample(self):
        # Instantiate the ContainerRegistryClient
        audience = "https://management.azure.com"
        endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]

        with ContainerRegistryClient(endpoint,
                                     DefaultAzureCredential(),
                                     audience=audience) as client:
            # Iterate through all the repositories
            for repository_name in client.list_repository_names():
                if repository_name == "hello-world":
                    for tag in client.list_tag_properties(repository_name):
                        print(tag.digest)

                    # [START delete_repository]
                    client.delete_repository(repository_name, tag.name)
    def delete_tags(self):
        # [START list_repository_names]
        audience = "https://management.azure.com"
        endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]

        with ContainerRegistryClient(endpoint,
                                     DefaultAzureCredential(),
                                     audience=audience) as client:
            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
                for tag in client.list_tag_properties(
                        repository,
                        order_by=ArtifactTagOrder.LAST_UPDATED_ON_DESCENDING):
                    tag_count += 1
                    if tag_count > 3:
                        print("Deleting {}:{}".format(repository, tag.name))
                        client.delete_tag(repository, tag.name)
    def delete_old_tags(self):
        from azure.containerregistry import ContainerRegistryClient, TagOrder
        from azure.identity import DefaultAzureCredential

        # [START list_repository_names]
        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
        credential = DefaultAzureCredential()
        client = ContainerRegistryClient(account_url, credential)

        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
            tags = client.list_tag_properties(
                repository, order_by=TagOrder.LAST_UPDATE_TIME_DESCENDING)
            for tag in tags[3:]:
                client.delete_tag(repository, tag.name)
            # [END list_tag_properties]

        client.close()
示例#18
0
    def delete_images(self):
        # Instantiate an instance of ContainerRegistryClient
        audience = "https://management.azure.com"
        endpoint = os.environ["CONTAINERREGISTRY_ENDPOINT"]

        with ContainerRegistryClient(endpoint,
                                     DefaultAzureCredential(),
                                     audience=audience) as client:
            for repository in client.list_repository_names():
                print(repository)

                # Keep the three most recent images, delete everything else
                manifest_count = 0
                for manifest in client.list_manifest_properties(
                        repository,
                        order_by=ArtifactManifestOrder.
                        LAST_UPDATED_ON_DESCENDING):
                    manifest_count += 1
                    if manifest_count > 3:
                        print("Deleting {}:{}".format(repository,
                                                      manifest.digest))
                        client.delete_manifest(repository, manifest.digest)
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
示例#20
0
    def basic_sample(self):

        from azure.containerregistry import ContainerRegistryClient
        from azure.identity import DefaultAzureCredential

        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]

        # Instantiate the client
        client = ContainerRegistryClient(account_url, DefaultAzureCredential())
        with client:
            # Iterate through all the repositories
            for repository_name in client.list_repository_names():
                if repository_name == "hello-world":
                    for tag in client.list_tag_properties(repository_name):
                        print(tag.digest)

                    # [START delete_repository]
                    client.delete_repository(repository_name, tag.name)
    def basic_sample(self):

        from azure.containerregistry import ContainerRegistryClient
        from azure.identity import DefaultAzureCredential
        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]

        # Instantiate the client
        client = ContainerRegistryClient(account_url, DefaultAzureCredential())
        with client:
            # Iterate through all the repositories
            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)

                    with container_repository:
                        # Show all tags
                        for manifest in container_repository.list_manifests():
                            print(manifest.tags)

                    # [START delete_repository]
                    client.delete_repository("hello-world")
    def set_image_properties(self):
        # Create a new ContainerRegistryClient
        account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]
        audience = "https://management.azure.com"
        credential = DefaultAzureCredential()
        client = ContainerRegistryClient(account_url,
                                         credential,
                                         audience=audience)

        # [START update_manifest_properties]
        # Set permissions on the v1 image's "latest" tag
        client.update_manifest_properties("library/hello-world",
                                          "latest",
                                          can_write=False,
                                          can_delete=False)
        # [END update_manifest_properties]
        # After this update, if someone were to push an update to `myacr.azurecr.io\hello-world:v1`, it would fail.
        # It's worth noting that if this image also had another tag, such as `latest`, and that tag did not have
        # permissions set to prevent reads or deletes, the image could still be overwritten. For example,
        # if someone were to push an update to `<registry endpoint>\hello-world:latest`
        # (which references the same image), it would succeed.

        client.close()
 def create_anon_client(self, endpoint, **kwargs):
     return ContainerRegistryClient(endpoint=endpoint,
                                    credential=None,
                                    **kwargs)
示例#24
0
 def create_registry_client(self, endpoint, **kwargs):
     return ContainerRegistryClient(endpoint=endpoint, credential=self.get_credential(), **kwargs)