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

Add AAD support for EG #19421

Merged
merged 11 commits into from
Jul 19, 2021
Merged

Add AAD support for EG #19421

merged 11 commits into from
Jul 19, 2021

Conversation

rakshith91
Copy link
Contributor

fixes #17963

@rakshith91
Copy link
Contributor Author

/azp run python - eventgrid - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Member

@swathipil swathipil left a comment

Choose a reason for hiding this comment

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

small nit, but o/w lgtm

from .. import _constants as constants
from .._signature_credential_policy import EventGridSasCredentialPolicy

def _get_authentication_policy_async(credential):
Copy link
Contributor

@yunhaoling yunhaoling Jun 28, 2021

Choose a reason for hiding this comment

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

nit: I think we could avoid duplicating the _get_authentication_policy method for async by adding a policy type argument in the sync helper.

def _get_authentication_policy(credential, bearer_token_policy=BearerTokenCredentialPolicy):
    if hasattr(credential, "get_token"):
        return bearer_token_policy(
            credential,
            constants.DEFAULT_EVENTGRID_SCOPE
        )

then in the async, we do

_get_authentication_policy(credential, AsyncBearerTokenCredentialPolicy)

def _get_authentication_policy_async(credential):
if credential is None:
raise ValueError("Parameter 'self._credential' must not be None.")
if hasattr(credential, "get_token"):
Copy link
Contributor

Choose a reason for hiding this comment

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

dumb question: what error would be raised if a user passed a sync AD credential into the async client?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'll be a type error

@rakshith91
Copy link
Contributor Author

/azp run python - eventgrid - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rakshith91
Copy link
Contributor Author

/azp run python - eventgrid - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rakshith91
Copy link
Contributor Author

/azp run python - eventgrid - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rakshith91
Copy link
Contributor Author

/azp run python - eventgrid - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -38,6 +38,34 @@ az eventgrid domain --create --location <location> --resource-group <resource-gr
In order to interact with the Event Grid service, you will need to create an instance of a client.
An **endpoint** and **credential** are necessary to instantiate the client object.

#### Using Azure Active Directory (AAD)
Copy link
Member

Choose a reason for hiding this comment

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

Nice, this reminds me I need to add this for .NET 😄


To send events to a topic or domain with a `TokenCredential`, the authenticated identity should have the "EventGrid Data Sender" role assigned.

With the `azure-identity` package, you can seamlessly authorize requests in both development and production environments. To learn more about Azure Active Directory, see the [`azure-identity` README](https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/identity/azure-identity/README.md).
Copy link
Member

@johanste johanste Jul 16, 2021

Choose a reason for hiding this comment

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

We shouldn't link to the old master branch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch - updated

_is_cloud_event,
_is_eventgrid_event,
_eventgrid_data_typecheck,
_build_request,
_cloud_event_to_generated,
_get_authentication_policy
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: missing trailing comma - did you run this through black?

Copy link
Contributor Author

@rakshith91 rakshith91 Jul 16, 2021

Choose a reason for hiding this comment

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

nope - i did not - can do that

EDIT: done

@@ -73,7 +78,7 @@ class EventGridPublisherClient:
def __init__(
self,
endpoint: str,
credential: Union[AzureKeyCredential, AzureSasCredential],
credential: Union["AsyncTokenCredential", AzureKeyCredential, AzureSasCredential],
Copy link
Member

Choose a reason for hiding this comment

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

That seems inconsistent, if not used those types should be in the TYPE_CHECKING as well, but I see now reason why some type would be string and some would be types


class AsyncEventGridTest(EventGridTest):

def generate_oauth_token(self):
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't need that, there is everything you need in devtools to care care of that for free

def get_oauth_endpoint(self):
return os.getenv("EG_TOPIC_HOSTNAME")

def generate_oauth_token(self):
Copy link
Member

Choose a reason for hiding this comment

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

Same, you don't need that

client = EventGridPublisherClient("eventgrid_endpoint", bad_credential)

@pytest.mark.live_test_only
Copy link
Member

Choose a reason for hiding this comment

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

why live only?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

little tricky to generate recording given we use resource group preparers and envvars for secrets

@rakshith91
Copy link
Contributor Author

/azp run python - eventgrid - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rakshith91 rakshith91 merged commit 95787ba into Azure:main Jul 19, 2021
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.

AAD support for eventgrid
6 participants