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

[ACR] Update cloud configuration API #20464

Merged
merged 12 commits into from
Sep 3, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ def __init__(self, endpoint, credential=None, **kwargs):
:param str endpoint: An ACR endpoint
:param credential: The credential with which to authenticate
:type credential: :class:`~azure.core.credentials.TokenCredential`
:keyword credential_scopes: URL for credential authentication if different from the default
:paramtype credential_scopes: List[str]
:keyword audience: URL to use for credential authentication with AAD. Its value could be
:"https://management.azure.com", "https://management.chinacloudapi.cn", "https://management.microsoftazure.de" or
:"https://management.usgovcloudapi.net"
:paramtype audience: str
:returns: None
:raises: None
:raises ValueError: if audience keyword-only argument isn't provided

.. admonition:: Example:

Expand All @@ -45,11 +47,16 @@ def __init__(self, endpoint, credential=None, **kwargs):
:dedent: 8
:caption: Instantiate an instance of `ContainerRegistryClient`
"""
audience = kwargs.pop("audience", None)
if not audience:
raise ValueError("The argument audience must be set to initialize ContainerRegistryClient.")
defaultScope = [audience + "/.default"]
if not endpoint.startswith("https://") and not endpoint.startswith("http://"):
endpoint = "https://" + endpoint
self._endpoint = endpoint
self._credential = credential
super(ContainerRegistryClient, self).__init__(endpoint=endpoint, credential=credential, **kwargs)
super(ContainerRegistryClient, self).__init__(
endpoint=endpoint, credential=credential, credential_scopes=defaultScope, **kwargs)

def _get_digest_from_tag(self, repository, tag):
# type: (str, str) -> str
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@


class ContainerRegistryClient(ContainerRegistryBaseClient):
def __init__(self, endpoint: str, credential: Optional["AsyncTokenCredential"] = None, **kwargs: Any) -> None:
def __init__(
self, endpoint: str, credential: Optional["AsyncTokenCredential"] = None, *, audience, **kwargs: Any) -> None:
"""Create a ContainerRegistryClient from an endpoint and a credential

:param endpoint: An ACR endpoint
:type endpoint: str
:param credential: The credential with which to authenticate
:type credential: :class:`~azure.core.credentials_async.AsyncTokenCredential`
:keyword credential_scopes: URL for credential authentication if different from the default
:paramtype credential_scopes: List[str]
:keyword audience: URL to use for credential authentication with AAD. Its value could be
:"https://management.azure.com", "https://management.chinacloudapi.cn", "https://management.microsoftazure.de" or
:"https://management.usgovcloudapi.net"
:paramtype audience: ~azure.containerregistry.ContainerRegistryAudience or str
:returns: None
:raises: None

Expand All @@ -47,11 +50,13 @@ def __init__(self, endpoint: str, credential: Optional["AsyncTokenCredential"] =
:dedent: 8
:caption: Instantiate an instance of `ContainerRegistryClient`
"""
defaultScope = [audience + "/.default"]
if not endpoint.startswith("https://") and not endpoint.startswith("http://"):
endpoint = "https://" + endpoint
self._endpoint = endpoint
self._credential = credential
super(ContainerRegistryClient, self).__init__(endpoint=endpoint, credential=credential, **kwargs)
super(ContainerRegistryClient, self).__init__(
endpoint=endpoint, credential=credential, credential_scopes=defaultScope, **kwargs)

async def _get_digest_from_tag(self, repository: str, tag: str) -> str:
tag_props = await self.get_tag_properties(repository, tag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from azure.identity.aio import DefaultAzureCredential, ClientSecretCredential
from azure.identity import AzureAuthorityHosts

from testcase import ContainerRegistryTestClass, get_authorization_scope, get_authority
from testcase import ContainerRegistryTestClass, get_audience, get_authority

logger = logging.getLogger()

Expand Down Expand Up @@ -51,11 +51,11 @@ def create_registry_client(self, endpoint, **kwargs):
authority = get_authority(endpoint)
audience = kwargs.pop("audience", None)
if not audience:
audience = get_authorization_scope(authority)
audience = get_audience(authority)
credential = self.get_credential(authority=authority)
return ContainerRegistryClient(endpoint=endpoint, credential=credential, credential_scopes=audience, **kwargs)
return ContainerRegistryClient(endpoint=endpoint, credential=credential, audience=audience, **kwargs)

def create_anon_client(self, endpoint, **kwargs):
authority = get_authority(endpoint)
audience = get_authorization_scope(authority)
return ContainerRegistryClient(endpoint=endpoint, credential=None, credential_scopes=audience, **kwargs)
audience = get_audience(authority)
return ContainerRegistryClient(endpoint=endpoint, credential=None, audience=audience, **kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interactions:
Connection:
- keep-alive
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://fake_url.azurecr.io/acr/v1/library%2Fhello-world/_tags/latest
response:
Expand All @@ -30,7 +30,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:52 GMT
- Mon, 30 Aug 2021 20:27:52 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -59,7 +59,7 @@ interactions:
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://fake_url.azurecr.io/oauth2/token
response:
Expand All @@ -71,15 +71,15 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:52 GMT
- Mon, 30 Aug 2021 20:27:52 GMT
server:
- openresty
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
x-ms-ratelimit-remaining-calls-per-second:
- '166.55'
- '166.516667'
status:
code: 200
message: OK
Expand All @@ -93,14 +93,14 @@ interactions:
Connection:
- keep-alive
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://fake_url.azurecr.io/acr/v1/library%2Fhello-world/_tags/latest
response:
body:
string: '{"registry": "yalinlitestsanon.azurecr.io", "imageName": "library/hello-world",
"tag": {"name": "latest", "digest": "sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38",
"createdTime": "2021-08-17T18:04:24.1991429Z", "lastUpdateTime": "2021-08-17T18:04:24.1991429Z",
"tag": {"name": "latest", "digest": "sha256:7d91b69e04a9029b99f3585aaaccae2baa80bcf318f4a5d2165a9898cd2dc0a1",
"createdTime": "2021-08-30T10:55:20.0468904Z", "lastUpdateTime": "2021-08-30T10:55:20.0468904Z",
"signed": false, "changeableAttributes": {"deleteEnabled": true, "writeEnabled":
true, "readEnabled": true, "listEnabled": true}}}'
headers:
Expand All @@ -116,7 +116,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:52 GMT
- Mon, 30 Aug 2021 20:27:52 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand All @@ -141,9 +141,9 @@ interactions:
Content-Length:
- '0'
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: DELETE
uri: https://fake_url.azurecr.io/v2/library%2Fhello-world/manifests/sha256%3A0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
uri: https://fake_url.azurecr.io/v2/library%2Fhello-world/manifests/sha256%3A7d91b69e04a9029b99f3585aaaccae2baa80bcf318f4a5d2165a9898cd2dc0a1
response:
body:
string: '{"errors": [{"code": "UNAUTHORIZED", "message": "authentication required,
Expand All @@ -162,7 +162,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:52 GMT
- Mon, 30 Aug 2021 20:27:52 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -191,7 +191,7 @@ interactions:
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://fake_url.azurecr.io/oauth2/token
response:
Expand All @@ -203,15 +203,15 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:52 GMT
- Mon, 30 Aug 2021 20:27:52 GMT
server:
- openresty
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
x-ms-ratelimit-remaining-calls-per-second:
- '166.533333'
- '165.966667'
status:
code: 200
message: OK
Expand All @@ -227,9 +227,9 @@ interactions:
Content-Length:
- '0'
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: DELETE
uri: https://fake_url.azurecr.io/v2/library%2Fhello-world/manifests/sha256%3A0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
uri: https://fake_url.azurecr.io/v2/library%2Fhello-world/manifests/sha256%3A7d91b69e04a9029b99f3585aaaccae2baa80bcf318f4a5d2165a9898cd2dc0a1
response:
body:
string: '{"errors": [{"code": "UNAUTHORIZED", "message": "authentication required,
Expand All @@ -248,7 +248,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:52 GMT
- Mon, 30 Aug 2021 20:27:52 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interactions:
Content-Length:
- '0'
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: DELETE
uri: https://fake_url.azurecr.io/acr/v1/library%2Fhello-world
response:
Expand All @@ -32,7 +32,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:52 GMT
- Mon, 30 Aug 2021 20:27:52 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -61,7 +61,7 @@ interactions:
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://fake_url.azurecr.io/oauth2/token
response:
Expand All @@ -73,15 +73,15 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:52 GMT
- Mon, 30 Aug 2021 20:27:52 GMT
server:
- openresty
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
x-ms-ratelimit-remaining-calls-per-second:
- '166.65'
- '166.383333'
status:
code: 200
message: OK
Expand All @@ -97,7 +97,7 @@ interactions:
Content-Length:
- '0'
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: DELETE
uri: https://fake_url.azurecr.io/acr/v1/library%2Fhello-world
response:
Expand All @@ -118,7 +118,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:52 GMT
- Mon, 30 Aug 2021 20:27:52 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ interactions:
Content-Length:
- '0'
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: DELETE
uri: https://fake_url.azurecr.io/acr/v1/library%2Fhello-world/_tags/latest
response:
Expand All @@ -32,7 +32,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:52 GMT
- Mon, 30 Aug 2021 20:27:52 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -61,7 +61,7 @@ interactions:
Content-Type:
- application/x-www-form-urlencoded
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://fake_url.azurecr.io/oauth2/token
response:
Expand All @@ -73,15 +73,15 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:53 GMT
- Mon, 30 Aug 2021 20:27:53 GMT
server:
- openresty
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
x-ms-ratelimit-remaining-calls-per-second:
- '166.116667'
- '166.083333'
status:
code: 200
message: OK
Expand All @@ -97,7 +97,7 @@ interactions:
Content-Length:
- '0'
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b5 Python/3.9.2 (Windows-10-10.0.19041-SP0)
- azsdk-python-azure-containerregistry/1.0.0b6 Python/3.6.8 (Windows-10-10.0.19041-SP0)
method: DELETE
uri: https://fake_url.azurecr.io/acr/v1/library%2Fhello-world/_tags/latest
response:
Expand All @@ -118,7 +118,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Tue, 17 Aug 2021 18:06:53 GMT
- Mon, 30 Aug 2021 20:27:53 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down
Loading