Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

use tls_set() in addition to tls_context #126

Merged
merged 4 commits into from
Aug 31, 2022

Conversation

Sohaib90
Copy link
Contributor

I use the comments about the design of adding tls_set to asyncio-mqtt from #14 (comment) and try to implement in the light of that.

My implementation allows the use of a TLSParameters object to invoke tls_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

Copy link
Collaborator

@frederikaalund frederikaalund left a 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,
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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

Copy link
Contributor Author

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

ca_certs: Optional[str] = None,
certfile: Optional[str] = None,
keyfile: Optional[str] = None,
cert_reqs: Optional[ssl.VerifyMode] = ssl.CERT_REQUIRED,
Copy link
Contributor Author

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

Copy link
Collaborator

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.

@frederikaalund
Copy link
Collaborator

All that's left is the * to force the user to supply keyword arguments. 👍

@@ -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,
Copy link
Collaborator

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.

Copy link
Contributor Author

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

@frederikaalund frederikaalund merged commit 0291b62 into empicano:master Aug 31, 2022
@frederikaalund
Copy link
Collaborator

Thank you for your patience and thank you for your contribution to asyncio-mqtt. 👍

@Sohaib90
Copy link
Contributor Author

Learned a lot and thank you for the library. It is a great help to so many :)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants