-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[webpubsub] support AAD, Api management proxy #20533
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
Conversation
iscai-msft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
overall @msyyc since a lot of this API is handwritten, generating autorest deleted a lot of the handwritten code. We don't want to delete any of the handwritten code, can you go back and add it back? thanks!
sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/__init__.py
Show resolved
Hide resolved
...ebpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_configuration.py
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_version.py
Outdated
Show resolved
Hide resolved
...e-messaging-webpubsubservice/azure/messaging/webpubsubservice/_web_pub_sub_service_client.py
Outdated
Show resolved
Hide resolved
Got it. I add necessary code back, including |
...e-messaging-webpubsubservice/azure/messaging/webpubsubservice/_web_pub_sub_service_client.py
Outdated
Show resolved
Hide resolved
...e-messaging-webpubsubservice/azure/messaging/webpubsubservice/_web_pub_sub_service_client.py
Outdated
Show resolved
Hide resolved
...ebpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_configuration.py
Outdated
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_policies.py
Outdated
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_policies.py
Outdated
Show resolved
Hide resolved
...re-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/operations/_operations.py
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/examples/send_messages_aad.py
Outdated
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/examples/send_messages_aad.py
Outdated
Show resolved
Hide resolved
...ebpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_configuration.py
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| @classmethod | ||
| def from_connection_string(cls, connection_string, **kwargs): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than modifying the generated code (and thus it being susceptible to being overwritten when regenerating), we should attempt to use the patch_sdk() method in the _patch.py file to make modifications. Not needed for this release, however.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense. But I can't find an example what patch_sdk() should look like in Azure/azure-sdk-for-python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add all the handwritten code into patch_sdk() to avoid changing generated code. Two problems left:
(1) aio does not have _patch.py and it will be deleted by codegen. I think we need to add it in autorest @iscai-msft
(2) do not have better ways to change __all__ in __init__ (). So every time these code will be covered.
...ebpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_configuration.py
Outdated
Show resolved
Hide resolved
319d416 to
be9026e
Compare
vicancy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the effort! Some little comments from service team.
...azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/operations/__init__.py
Outdated
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/examples/send_messages_aad.py
Outdated
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/examples/send_messages_aad.py
Outdated
Show resolved
Hide resolved
…essages_aad.py Co-authored-by: Liangying.Wei <[email protected]>
…essages_aad.py Co-authored-by: Liangying.Wei <[email protected]>
sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_patch.py
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/_patch.py
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/tests/test_send_requests.py
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/tests/test_smoke_async.py
Outdated
Show resolved
Hide resolved
...bsub/azure-messaging-webpubsubservice/examples/send_messages_connection_string_apim_proxy.py
Outdated
Show resolved
Hide resolved
| """Create a new WebPubSubServiceClient from a connection string. | ||
| :param connection_string: Connection string | ||
| :type connection_string: ~str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ~str will render weirdly in the docs, this can be flattened into one line and just be :param str connection_string: Connection string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is better to keep same annotation style with generated code. Anyway, I change ~str to str
sdk/webpubsub/azure-messaging-webpubsubservice/azure/messaging/webpubsubservice/aio/_patch.py
Show resolved
Hide resolved
sdk/webpubsub/azure-messaging-webpubsubservice/samples/send_messages_aad_apim_proxy.py
Outdated
Show resolved
Hide resolved
| exit() | ||
|
|
||
| # Build a client through AAD | ||
| client = WebPubSubServiceClient(credential=DefaultAzureCredential(), endpoint=endpoint, reverse_proxy_endpoint=reverse_proxy_endpoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@msyyc looking at this sample, I'm still not sure what a reverse proxy endpoint is, and why I should use it. Can you highlight why I would add a reverse proxy endpoint? Since this sample is the same as the AAD one, I don't know why I would add these extra lines of code. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iscai-msft actually I don't have rich domain knowledge to explain the usage about Api management proxy. @vicancy could you help to update the sample?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
|
||
| # Build a client from the connection string. And for this example, we have enabled debug | ||
| # tracing. For production code, this should be turned off. | ||
| client = WebPubSubServiceClient.from_connection_string(connection_string, logging_enable=True, reverse_proxy_endpoint=reverse_proxy_endpoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also one thing I noticed in these samples: The actual calls you're doing with webpubsub are the same, the only difference is how to authenticate them. Do you think a better sample structure would be to have one sample with all of the different ways to authenticate (thinking something like this, where we show multiple ways to authenticate), and then having one sample that is client.send_to_all, with just one way of authenticating (either DefaultAzureCredential or AzureKeyCredential, since those are the ones that most people will use)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I also think about that way. I hope customers could run sample file directly so the sample code should be simple asap. And for overall description about authentication, there is detailed info in README.md. So I hope to keep the sample like this format.
autorest --version=3.4.5 --python --track2 --use=D:\dev3\autorest.python --use=@autorest\[email protected] --python-sdks-folder=D:\dev3\azure-sdk-for-python\sdk --python-mode=update D:\dev3\azure-sdk-for-python\sdk\webpubsub\azure-messaging-webpubsubservice\swagger\README.md --version-tolerant