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

[Container Registry] Anonymous Access Client #18550

Merged
merged 48 commits into from
May 11, 2021

Conversation

seankane-msft
Copy link
Member

No description provided.

@seankane-msft
Copy link
Member Author

#17755

@seankane-msft seankane-msft added this to the [2021] May milestone May 6, 2021
@seankane-msft
Copy link
Member Author

Dependent on #18392

@seankane-msft seankane-msft marked this pull request as ready for review May 6, 2021 20:29
@seankane-msft
Copy link
Member Author

/azp run python - containerregistry - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@seankane-msft
Copy link
Member Author

/azp run python - containerregistry - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -25,6 +26,8 @@ def __init__(self, credential, endpoint):
super(ContainerRegistryChallengePolicy, self).__init__()
self._credential = credential
self._exchange_client = ACRExchangeClient(endpoint, self._credential)
if self._credential is None:
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this check move before line 28? Otherwise we are building the ACRExchangeClient for nothing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes I can move it, I originally didn't like the if/else flow but I don't see a way around it with this design.

AUTHENTICATION_CHALLENGE_PARAMS_PATTERN = re.compile('(?:(\\w+)="([^""]*)")+')

def __init__(self, endpoint, credential=None, **kwargs):
# type: (str, TokenCredential, Dict[str, Any]) -> None
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious why this client takes a credential at all if it must be None?
At a minimum, that type hint should probably be Optional[...]

Copy link
Member Author

Choose a reason for hiding this comment

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

It definitely does not need to be there, I will remove it. Thank you

from azure.core.credentials import TokenCredential


PASSWORD = u"password"
Copy link
Member

Choose a reason for hiding this comment

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

Isn't there already a generated enum for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, added in

"""

BEARER = "Bearer"
AUTHENTICATION_CHALLENGE_PARAMS_PATTERN = re.compile('(?:(\\w+)="([^""]*)")+')
Copy link
Member

Choose a reason for hiding this comment

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

These seem to be defined on all 4 ExchangeClients - perhaps they could be refactored out somewhere?
Not a big deal - doesn't need to be changed now.

Copy link
Member Author

Choose a reason for hiding this comment

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

They can all be removed, I parse the challenge policy in a separate file with everything properly scoped

if not endpoint.startswith("https://") and not endpoint.startswith("http://"):
endpoint = "https://" + endpoint
self._endpoint = endpoint
self._credential_scope = "https://management.core.windows.net/.default"
Copy link
Member

Choose a reason for hiding this comment

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

This could probably be a constant somewhere to be shared between the ExchangeClients

Copy link
Member Author

Choose a reason for hiding this comment

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

The credential scope needs to be fixed in the next release to handle foreign clouds as well. I'm going to address this in our next beta.

Copy link
Member

@mccoyp mccoyp left a comment

Choose a reason for hiding this comment

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

Nitpicks more than anything -- looks good!


def __init__(self, endpoint, credential=None, **kwargs):
# type: (str, TokenCredential, Dict[str, Any]) -> None
if not endpoint.startswith("https://") and not endpoint.startswith("http://"):
Copy link
Member

Choose a reason for hiding this comment

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

This feels like it could be veering into client-side validation territory, but if there are other clients that do this then it's probably okay for now

Copy link
Member Author

Choose a reason for hiding this comment

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

I believe we do this in all four tier-1 languages, and the biggest reason being the value given in the portal when you create an account does not prefix the endpoint with https:// or http://

@@ -4,7 +4,7 @@
# Licensed under the MIT License.
# ------------------------------------
from enum import Enum
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Dict, Any
Copy link
Member

@mccoyp mccoyp May 11, 2021

Choose a reason for hiding this comment

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

nit: it looks like Dict and Any can just be imported if type checking

AUTHENTICATION_CHALLENGE_PARAMS_PATTERN = re.compile('(?:(\\w+)="([^""]*)")+')

def __init__(self, endpoint: str, credential: "AsyncTokencredential" = None, **kwargs: Dict[str, Any]) -> None:
if not endpoint.startswith("https://") and not endpoint.startswith("http://"):
Copy link
Member

Choose a reason for hiding this comment

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

Same comment about parameter validation, but I realize that this may be kind of ACR-specific

@@ -122,6 +122,11 @@ def process_request(self, request):
if "seankane.azurecr.io" in request.url:
request.url = request.url.replace("seankane.azurecr.io", "fake_url.azurecr.io")

if "seankaneanon.azurecr.io" in request.uri:
request.uri = request.uri.replace("seankaneanon.azurecr.io", "fake_url.azurecr.io")
if "seankaneanon.azurecr.io" in request.url:
Copy link
Member

Choose a reason for hiding this comment

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

Looks like an accidental duplication

Copy link
Member Author

Choose a reason for hiding this comment

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

The scrubbers are a work in progress, but one checks the uri and the other checks the url

Copy link
Member

Choose a reason for hiding this comment

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

Ah, good point! I knew there must be a character difference in there somewhere that I was missing

@Azure Azure deleted a comment from check-enforcer bot May 11, 2021
@seankane-msft seankane-msft merged commit a4545c1 into Azure:master May 11, 2021
@seankane-msft seankane-msft deleted the acr-anon-access branch May 11, 2021 20:34
iscai-msft added a commit to iscai-msft/azure-sdk-for-python that referenced this pull request May 12, 2021
…into fix_confidentialledger_aiohttp

* 'master' of https://github.com/Azure/azure-sdk-for-python:
  regenerate (Azure#18647)
  [formrecognizer] remove polling interval from doc comments (Azure#18645)
  [formrecognizer] regenerates on v2.1 (Azure#18551)
  adding images to anonymous client (Azure#18646)
  Confidential Ledger: Update README samples and CHANGELOG (Azure#18644)
  [Container Registry] Anonymous Access Client (Azure#18550)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants