-
Notifications
You must be signed in to change notification settings - Fork 79
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
use tls_set() in addition to tls_context #126
Conversation
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 opening this PR. 👍 I only have one minor comment (see the review). Other than that, it LGTM. Well done!
# TLS set parameter class | ||
class TLSParameters: | ||
def __init__( | ||
self, |
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.
Change to __init__(self, *, ca_certs, ...)
. This way, we force the user to supply the keyword argument, which is a good thing IMHO when there are this many options. 👍
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.
Since there are default values to these parameters (even in paho-mqtt), then is it okay to add *
which will force the user to give the values even if it is none? I looked up the usage of *
in function calls, which forces the user to give value to an argument that has no default value.
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.
Yes, the *
simply forces the user to use keyword arguments instead of positional arguments. All other semantics stay the same (including defaults). 👍
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.
Oh makes sense. Added and committed. Please review it :)
asyncio_mqtt/client.py
Outdated
ca_certs: Optional[str] = None, | ||
certfile: Optional[str] = None, | ||
keyfile: Optional[str] = None, | ||
cert_reqs: Optional[ssl.VerifyMode] = ssl.CERT_REQUIRED, |
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 more change I just saw in paho-mqtt is that I dont have to provide the default values, these should be None
as well. So I will change this as well
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.
Well spotted. 👍 I missed that one.
All that's left is the |
asyncio_mqtt/client.py
Outdated
@@ -117,6 +139,7 @@ def __init__( | |||
logger: Optional[logging.Logger] = None, | |||
client_id: Optional[str] = None, | |||
tls_context: Optional[ssl.SSLContext] = None, | |||
tls_set_params: Optional[TLSParameters] = None, |
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.
One last nitpick here, and then I promise it's good to merge. 😅 Can we change the name of the parameter from tls_set_params
to simply tls_params
? 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.
Of course. That makes more sense now that I think of it
Thank you for your patience and thank you for your contribution to asyncio-mqtt. 👍 |
Learned a lot and thank you for the library. It is a great help to so many :) |
I use the comments about the design of adding
tls_set
toasyncio-mqtt
from #14 (comment) and try to implement in the light of that.My implementation allows the use of a
TLSParameters
object to invoketls_set()
function of paho-mqtt client in asyncio-mqtt. Let me know if it makes sense. I would also like some pointers in regards to testing this