Skip to content

Commit b66d6aa

Browse files
Code review changes: fixed naming and cleaned up code
1 parent 4993107 commit b66d6aa

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

awsiot/mqtt_connection_builder.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -427,15 +427,16 @@ def websockets_with_custom_handshake(
427427
websocket_proxy_options=websocket_proxy_options,
428428
**kwargs)
429429

430-
def _add_username_parameter(input_string, parameter_value, parameter_pretext, added_string_to_username):
430+
def _add_to_username_parameter(input_string, parameter_value, parameter_pretext):
431431
"""
432432
Helper function to add parameters to the username in the direct_with_custom_authorizer function
433433
"""
434434
return_string = input_string
435-
if added_string_to_username is False:
436-
return_string += "?"
437-
else:
435+
436+
if not return_string.find("?") is -1:
438437
return_string += "&"
438+
else:
439+
return_string += "?"
439440

440441
if not parameter_value.find(parameter_pretext) is -1:
441442
return return_string + parameter_value
@@ -474,7 +475,6 @@ def direct_with_custom_authorizer(
474475

475476
_check_required_kwargs(**kwargs)
476477
username_string = ""
477-
added_string_to_username = False
478478

479479
if auth_username is None:
480480
if not _get(kwargs, "username") is None:
@@ -483,12 +483,11 @@ def direct_with_custom_authorizer(
483483
username_string += auth_username
484484

485485
if not auth_authorizer_name is None:
486-
username_string = _add_username_parameter(
487-
username_string, auth_authorizer_name, "x-amz-customauthorizer-name=", added_string_to_username)
488-
added_string_to_username = True
486+
username_string = _add_to_username_parameter(
487+
username_string, auth_authorizer_name, "x-amz-customauthorizer-name=")
489488
if not auth_authorizer_signature is None:
490-
username_string = _add_username_parameter(
491-
username_string, auth_authorizer_signature, "x-amz-customauthorizer-signature=", added_string_to_username)
489+
username_string = _add_to_username_parameter(
490+
username_string, auth_authorizer_signature, "x-amz-customauthorizer-signature=")
492491

493492
kwargs["username"] = username_string
494493
kwargs["password"] = auth_password

0 commit comments

Comments
 (0)