Skip to content
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

updating sample for beta2 api #18711

Merged
merged 1 commit into from
May 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you move the creating repository client sample elsewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This object isn't meant to be instantiated directly so I removed the sample

# 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