Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d7bcfe6
changing ContainerRepositoryClient to ContainerRepository
seankane-msft Apr 27, 2021
7a0b598
renaming files
seankane-msft Apr 27, 2021
15bbaaf
re-recording, commenting out tests that are not necessary
seankane-msft Apr 27, 2021
b91302c
working sync registry artifact class
seankane-msft Apr 28, 2021
6f7c55c
async registry artifact
seankane-msft Apr 28, 2021
22ecb18
issue with recording infra that is removing an acr specific oauth path
seankane-msft Apr 28, 2021
d5986dd
pylint issues
seankane-msft Apr 28, 2021
1287136
recording and processors
seankane-msft Apr 28, 2021
145949b
removing commented out code
seankane-msft Apr 28, 2021
09f3636
undoing changes to cache
seankane-msft Apr 28, 2021
6e38bf1
more lint fixes
seankane-msft Apr 28, 2021
d9659c0
help with logging output
seankane-msft Apr 28, 2021
941473a
change to list_repository_names
seankane-msft Apr 28, 2021
44ceace
renaming for consistency
seankane-msft Apr 28, 2021
4e5dbc8
all changes made, plus recordings
seankane-msft Apr 28, 2021
f7caebd
fixing up more tests again!
seankane-msft Apr 28, 2021
6ced986
formatting
seankane-msft Apr 28, 2021
5417f1d
merge conflicts
seankane-msft Apr 29, 2021
83c0d90
fixing up merge issues
seankane-msft May 3, 2021
c0ed9ff
merge conflicts
seankane-msft May 3, 2021
ed3f937
more conflicts
seankane-msft May 3, 2021
ccec23b
undoing changes to gen code
seankane-msft May 3, 2021
afa0c1b
pylint issues
seankane-msft May 4, 2021
0e2e335
consistent naming
seankane-msft May 4, 2021
24cb3a0
changes
seankane-msft May 4, 2021
0dcd6cd
anon test
seankane-msft May 4, 2021
62964e8
small changes to generated, eventually will be reflected in the swagger
seankane-msft May 5, 2021
64937b8
adding basics for anon
seankane-msft May 5, 2021
315c9f8
adding test infra
seankane-msft May 5, 2021
abd4e4e
adding async tests
seankane-msft May 5, 2021
119575e
adding more tests for anon container repo and reg artifact
seankane-msft May 5, 2021
7c31693
added async anon client
seankane-msft May 6, 2021
0c9e77a
asserting credential is false
seankane-msft May 6, 2021
7f57d03
fixing scrubber
seankane-msft May 6, 2021
d260ff9
new swagger
seankane-msft May 6, 2021
8fbf308
merge conflicts
seankane-msft May 6, 2021
dc033e9
merge conflicts reflected in tests
seankane-msft May 6, 2021
9a93a9c
lint
seankane-msft May 6, 2021
c06fecd
updating tests and resource for anonymous access
seankane-msft May 6, 2021
2b78a40
updating generated code
seankane-msft May 7, 2021
77aed4b
merge conflicts
seankane-msft May 9, 2021
67887d6
undoing generated code changes
seankane-msft May 9, 2021
4e7c9b6
shouldnt have done that oops
seankane-msft May 9, 2021
86f86aa
undoing unnecessary changes to recordings
seankane-msft May 9, 2021
87b1928
changelog
seankane-msft May 9, 2021
3255a2d
merge conflicts
seankane-msft May 11, 2021
68f7bfd
anna and mccoys comments
seankane-msft May 11, 2021
8a254ab
lint fixes
seankane-msft May 11, 2021
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
Prev Previous commit
Next Next commit
added async anon client
  • Loading branch information
seankane-msft committed May 6, 2021
commit 7c316937348113b38320b5cb7cc629f6043f9bfe
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import time
from typing import TYPE_CHECKING, Dict, List, Any

from azure.core.pipeline import PipelineRequest, PipelineResponse
from azure.core.pipeline.policies import SansIOHTTPPolicy

from ._async_exchange_client import ExchangeClientAuthenticationPolicy
from .._generated.aio import ContainerRegistry
from .._helpers import _parse_challenge
from .._user_agent import USER_AGENT
Expand All @@ -21,17 +19,8 @@
PASSWORD = u"password"


class ExchangeClientAuthenticationPolicy(SansIOHTTPPolicy):
"""Authentication policy for exchange client that does not modify the request"""

def on_request(self, request: PipelineRequest) -> None:
pass

def on_response(self, request: PipelineRequest, response: PipelineResponse) -> None:
pass


class ACRExchangeClient(object):
class AnonymousACRExchangeClient(object):
"""Class for handling oauth authentication requests

:param endpoint: Azure Container Registry endpoint
Expand All @@ -57,6 +46,7 @@ def __init__(self, endpoint: str, credential: "AsyncTokencredential"=None, **kwa
**kwargs
)
self._credential = credential

async def get_acr_access_token(self, challenge: str, **kwargs: Dict[str, Any]) -> str:
parsed_challenge = _parse_challenge(challenge)
parsed_challenge["grant_type"] = PASSWORD
Expand All @@ -68,15 +58,15 @@ async def get_acr_access_token(self, challenge: str, **kwargs: Dict[str, Any]) -
**kwargs
)

def exchange_refresh_token_for_access_token(
async def exchange_refresh_token_for_access_token(
self,
refresh_token: str = None,
service: str = None,
scope: str = None,
grant_type: str = PASSWORD,
**kwargs: Any
) -> str:
access_token = self._client.authentication.exchange_acr_refresh_token_for_acr_access_token(
access_token = await self._client.authentication.exchange_acr_refresh_token_for_acr_access_token(
service=service, scope=scope, refresh_token=refresh_token, grant_type=grant_type, **kwargs
)
return access_token.access_token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from azure.core.pipeline.policies import AsyncHTTPPolicy

from ._async_anonymous_exchange_client import AnonymousACRExchangeClient
from ._async_exchange_client import ACRExchangeClient
from .._helpers import _enforce_https

Expand All @@ -21,7 +22,10 @@ class ContainerRegistryChallengePolicy(AsyncHTTPPolicy):
def __init__(self, credential: "AsyncTokenCredential", endpoint: str) -> None:
super().__init__()
self._credential = credential
self._exchange_client = ACRExchangeClient(endpoint, self._credential)
if not self._credential:
self._exchange_client = AnonymousACRExchangeClient(endpoint)
else:
self._exchange_client = ACRExchangeClient(endpoint, self._credential)

async def on_request(self, request):
# type: (PipelineRequest) -> None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:53 GMT
- Thu, 06 May 2021 18:11:24 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -71,7 +71,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:54 GMT
- Thu, 06 May 2021 18:11:26 GMT
server:
- openresty
strict-transport-security:
Expand Down Expand Up @@ -114,7 +114,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:54 GMT
- Thu, 06 May 2021 18:11:26 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:54 GMT
- Thu, 06 May 2021 18:11:27 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -71,7 +71,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:55 GMT
- Thu, 06 May 2021 18:11:29 GMT
server:
- openresty
strict-transport-security:
Expand Down Expand Up @@ -158,7 +158,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:55 GMT
- Thu, 06 May 2021 18:11:29 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:56 GMT
- Thu, 06 May 2021 18:11:31 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -71,7 +71,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:56 GMT
- Thu, 06 May 2021 18:11:32 GMT
server:
- openresty
strict-transport-security:
Expand Down Expand Up @@ -110,7 +110,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:56 GMT
- Thu, 06 May 2021 18:11:33 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:57 GMT
- Thu, 06 May 2021 18:11:34 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -71,7 +71,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:57 GMT
- Thu, 06 May 2021 18:11:35 GMT
server:
- openresty
strict-transport-security:
Expand Down Expand Up @@ -110,7 +110,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:57 GMT
- Thu, 06 May 2021 18:11:36 GMT
docker-distribution-api-version:
- registry/2.0
link:
Expand Down Expand Up @@ -156,7 +156,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:57 GMT
- Thu, 06 May 2021 18:11:36 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -197,7 +197,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:57 GMT
- Thu, 06 May 2021 18:11:36 GMT
server:
- openresty
strict-transport-security:
Expand Down Expand Up @@ -236,7 +236,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:58 GMT
- Thu, 06 May 2021 18:11:37 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:58 GMT
- Thu, 06 May 2021 18:11:38 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -71,7 +71,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:58 GMT
- Thu, 06 May 2021 18:11:39 GMT
server:
- openresty
strict-transport-security:
Expand Down Expand Up @@ -130,7 +130,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:58 GMT
- Thu, 06 May 2021 18:11:40 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:59 GMT
- Thu, 06 May 2021 18:11:41 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -71,7 +71,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:59 GMT
- Thu, 06 May 2021 18:11:42 GMT
server:
- openresty
strict-transport-security:
Expand Down Expand Up @@ -110,7 +110,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:59 GMT
- Thu, 06 May 2021 18:11:43 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -154,7 +154,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:30:59 GMT
- Thu, 06 May 2021 18:11:43 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down Expand Up @@ -195,7 +195,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:31:00 GMT
- Thu, 06 May 2021 18:11:44 GMT
server:
- openresty
strict-transport-security:
Expand Down Expand Up @@ -234,7 +234,7 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Wed, 05 May 2021 20:31:00 GMT
- Thu, 06 May 2021 18:11:44 GMT
docker-distribution-api-version:
- registry/2.0
server:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b1 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://seankaneanon.azurecr.io/acr/v1/library%2Fhello-world
response:
body:
string: '{"errors": [{"code": "UNAUTHORIZED", "message": "authentication required,
visit https://aka.ms/acr/authorization for more information.", "detail": [{"Type":
"repository", "Name": "library/hello-world", "Action": "metadata_read"}]}]}'
headers:
access-control-expose-headers: X-Ms-Correlation-Request-Id
connection: keep-alive
content-length: '222'
content-type: application/json; charset=utf-8
date: Thu, 06 May 2021 18:24:19 GMT
docker-distribution-api-version: registry/2.0
server: openresty
strict-transport-security: max-age=31536000; includeSubDomains
www-authenticate: Bearer realm="https://fake_url.azurecr.io/oauth2/token",service="fake_url.azurecr.io",scope="fake_scope",error="invalid_token"
x-content-type-options: nosniff
status:
code: 401
message: Unauthorized
url: https://fake_url.azurecr.io/acr/v1/library%2Fhello-world
- request:
body:
grant_type: password
scope: repository:library/hello-world:metadata_read
service: fake_url.azurecr.io
headers:
Accept:
- application/json
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b1 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
method: POST
uri: https://seankaneanon.azurecr.io/oauth2/token
response:
body:
string: '{"access_token": "REDACTED"}'
headers:
connection: keep-alive
content-type: application/json; charset=utf-8
date: Thu, 06 May 2021 18:24:20 GMT
server: openresty
strict-transport-security: max-age=31536000; includeSubDomains
transfer-encoding: chunked
status:
code: 200
message: OK
url: https://fake_url.azurecr.io/oauth2/token
- request:
body: null
headers:
Accept:
- application/json
User-Agent:
- azsdk-python-azure-containerregistry/1.0.0b1 Python/3.9.0rc1 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://seankaneanon.azurecr.io/acr/v1/library%2Fhello-world
response:
body:
string: '{"registry": "seankaneanon.azurecr.io", "imageName": "library/hello-world",
"createdTime": "2021-05-05T18:00:19.7101132Z", "lastUpdateTime": "2021-05-05T18:00:17.5345755Z",
"manifestCount": 10, "tagCount": 5, "changeableAttributes": {"deleteEnabled":
true, "writeEnabled": true, "readEnabled": true, "listEnabled": true, "teleportEnabled":
false}}'
headers:
access-control-expose-headers: X-Ms-Correlation-Request-Id
connection: keep-alive
content-length: '326'
content-type: application/json; charset=utf-8
date: Thu, 06 May 2021 18:24:20 GMT
docker-distribution-api-version: registry/2.0
server: openresty
strict-transport-security: max-age=31536000; includeSubDomains
x-content-type-options: nosniff
status:
code: 200
message: OK
url: https://fake_url.azurecr.io/acr/v1/library%2Fhello-world
version: 1
Loading