Skip to content

Conversation

@janborch
Copy link

*Description of changes:
Made minor changes to the mqtt_connection_builder.py to allow connecting to an AWS IoT endpoint with a custom authorizer. I added one helper function tls_custom_auth to establish a tls connection without using client side certs/keys.
I also changed the logic to force port 443 and set ALPN to mqtt when a password field is specified in the connection parameters.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

"""
Builder functions to create a :class:`awscrt.mqtt.Connection`, configured for use with AWS IoT Core.
The following keyword arguments are common to all builder functions:
Copy link
Contributor

Choose a reason for hiding this comment

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

Logical change looks good but can we undo all these white space changes?

Copy link
Contributor

Choose a reason for hiding this comment

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

Changing the whitespace up here affects how the docs are generated. Please undo this


port = _get(kwargs, 'port')
password = _get(kwargs, 'password')
use_customAuth = True if password is not None else False
Copy link
Contributor

Choose a reason for hiding this comment

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

trivial/style: use_customAuth -> use_custom_auth

# prefer 443, even for direct MQTT connections, since it's less likely to be blocked by firewalls
if use_websockets or awscrt.io.is_alpn_available():
# If a password is specified for a custom authorizd, force port 443
if use_websockets or awscrt.io.is_alpn_available() or use_customAuth :
Copy link
Contributor

Choose a reason for hiding this comment

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

trivial/style: we use autopep8 to format our code. Unfortunately, we haven't hooked it up to CI in this repo yet

anyway, python3 -m pip install autopep8 and run python3 -m autopep8 --in-place awsiot/mqtt_connection_builder.py

"""
This builder creates an :class:`awscrt.mqtt.Connection`, configured for an mTLS MQTT connection to AWS IoT.
TLS arguments are passed as filepaths.
Copy link
Contributor

Choose a reason for hiding this comment

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

again. stop removing blank lines from docstrings, it messes up the generated HTML docs

websocket_handshake_transform=websocket_handshake_transform,
websocket_proxy_options=websocket_proxy_options,
**kwargs)
**kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

trivial: put back blank line at end of file

This builder creates an :class:`awscrt.mqtt.Connection`, configured for an TLS MQTT connection to AWS IoT without
using client side certificates and keys for authentication using AWS IoT custom authorizer and MQTT userid,passsword parameter.
This function takes all :mod:`common arguments<awsiot.mqtt_connection_builder>`
described at the top of this doc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Be sure to document the new arguments

described at the top of this doc, as well as... Keyword Args: username (str): username for custom auth password (str): password for custom auth 
@jmklix jmklix added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 2 days. and removed needs-review labels Sep 28, 2021
@janborch
Copy link
Author

@graebm Thanks for reviewing, do you need anything else from me? Not sure if the white space changes is a task for me

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 2 days. label Oct 1, 2021
@jmklix
Copy link
Member

jmklix commented Oct 25, 2021

@janbroch can you make all of the changes that have been suggested?

@jmklix jmklix added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 2 days. label Jan 14, 2022
@github-actions
Copy link

Greetings! It looks like this PR hasn’t been active in longer than a week, add a comment or an upvote to prevent automatic closure, or if the issue is already closed, please feel free to open a new one.

@github-actions github-actions bot added closing-soon This issue will automatically close in 5 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 5 days unless further comments are made. labels Jan 14, 2022
@github-actions github-actions bot closed this Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closed-for-staleness response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 2 days.

4 participants