Skip to content

Commit

Permalink
updating sample for beta2 api (#18711)
Browse files Browse the repository at this point in the history
  • Loading branch information
seankane-msft authored May 17, 2021
1 parent 386548d commit fb9747d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ def __init__(self, endpoint, repository, tag_or_digest, 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_repository_client]
:end-before: [END create_repository_client]
:language: python
:dedent: 8
:caption: Instantiate an instance of `ContainerRepositoryClient`
"""
if not endpoint.startswith("https://") and not endpoint.startswith("http://"):
endpoint = "https://" + endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,40 @@
class CreateClients(object):
def __init__(self):
load_dotenv(find_dotenv())
self.account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]

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(self.account_url, DefaultAzureCredential())
client = ContainerRegistryClient(account_url, DefaultAzureCredential())
# [END create_registry_client]

async def create_repository_client(self):
# Instantiate the ContainerRegistryClient
# [START create_repository_client]
from azure.containerregistry.aio import ContainerRepository
from azure.identity.aio import DefaultAzureCredential

client = ContainerRepository(self.account_url, "my_repository", DefaultAzureCredential())
# [END create_repository_client]

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(self.account_url, DefaultAzureCredential())
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
repository_client = client.get_repository(repository_name)
# Create a repository object from the registry client
container_repository = client.get_repository(repository_name)

async with repository_client:
async with container_repository:
# Show all tags
async for tag in repository_client.list_tags():
print(tag.digest)

# [START delete_repository]
await client.delete_repository("hello-world")
# [END delete_repository]
async for manifest in container_repository.list_manifests():
print(manifest.tags)

async def main():
sample = CreateClients()
await sample.create_registry_client()
await sample.create_repository_client()
await sample.basic_sample()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,44 +26,36 @@
class CreateClients(object):
def __init__(self):
load_dotenv(find_dotenv())
self.account_url = os.environ["CONTAINERREGISTRY_ENDPOINT"]

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(self.account_url, DefaultAzureCredential())
client = ContainerRegistryClient(account_url, DefaultAzureCredential())
# [END create_registry_client]

def create_repository_client(self):
# Instantiate the ContainerRegistryClient
# [START create_repository_client]
from azure.containerregistry import ContainerRepository
from azure.identity import DefaultAzureCredential

client = ContainerRepository(self.account_url, "my_repository", DefaultAzureCredential())
# [END create_repository_client]

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(self.account_url, DefaultAzureCredential())
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 client from the registry client
repository_client = client.get_repository(repository_name)
# Create a repository object from the registry client
container_repository = client.get_repository(repository_name)

with repository_client:
with container_repository:
# Show all tags
for tag in repository_client.list_tags():
print(tag.digest)
for manifest in container_repository.list_manifests():
print(manifest.tags)

# [START delete_repository]
client.delete_repository("hello-world")
Expand All @@ -73,5 +65,4 @@ def basic_sample(self):
if __name__ == "__main__":
sample = CreateClients()
sample.create_registry_client()
sample.create_repository_client()
sample.basic_sample()
2 changes: 1 addition & 1 deletion sdk/containerregistry/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ stages:
AllocateResourceGroup: false
BuildTargetingString: azure-containerregistry
ServiceDirectory: containerregistry
TestSamples: false
TestSamples: true
DeployArmTemplate: true
EnvVars:
AZURE_CLIENT_ID: $(aad-azure-sdk-test-client-id)
Expand Down

0 comments on commit fb9747d

Please sign in to comment.