Skip to content

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

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)

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).

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

_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

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

with pytest.raises(ValueError, match="The provided credential should be an instance of a TokenCredential, AzureSasCredential or AzureKeyCredential"):
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