Skip to content

Commit

Permalink
tools: Fix script overwrite credentials behaviour
Browse files Browse the repository at this point in the history
This commit makes the script correctly ask before overwriting
credentials.
Previously, the script checked for 'dummy_thingname' and the default
endpoint in 'aws_clientcredential.h' and only asked if these defaults
were not present.
These strings occur in more than one place in the header file so so
this check is not sufficient to say the credentials #define'd have not
been modified by the user.
This commit makes the script check the entirety of the #define line.

Signed-off-by: Reuben Cartwright <[email protected]>
  • Loading branch information
RC-Repositories authored and aggarg committed Sep 15, 2024
1 parent eab88f1 commit 177caff
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions tools/scripts/createIoTThings.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,17 +510,12 @@ def _write_aws_clientcredential_h(flags):
Parameters:
flags (Flags): contains metadata needed for AWS and OTA updates
(e.g. credentials).
fileDir (str): the project's base directory. E.g. contains top-level README.md.
"""
fileDir = os.path.dirname(os.path.realpath("__file__"))
template_has_correct_format = (
lambda contents: "clientcredentialMQTT_BROKER_ENDPOINT " in contents
and "clientcredentialIOT_THING_NAME " in contents
)
template_has_been_edited = (
lambda contents: "dummy.endpointid.amazonaws.com" not in contents
or "dummy_thingname" not in contents
)
# Try to find a template for 'aws_clientcredential.h'
template = ""
# We assume flags.targetApplication is not ApplicationType.UNDEFINED
Expand Down Expand Up @@ -550,7 +545,22 @@ def _write_aws_clientcredential_h(flags):
)
logging.warning(err_msg)
return False
if template_has_been_edited(template):
# if template has been edited, ask before overwriting.
DEFAULT_ENDPOINT = (
"#define clientcredentialMQTT_BROKER_ENDPOINT "
+ 'dummy.endpointid.amazonaws.com"'
)
DEFAULT_THING_NAME = (
"#define clientcredentialIOT_THING_NAME " '"dummy_thingname"'
)
# Remove spaces for robustness.
template_without_spaces = template.replace(" ", "")
if (
DEFAULT_ENDPOINT.replace(" ", "") in template_without_spaces
and DEFAULT_THING_NAME.replace(" ", "") in template_without_spaces
):
logging.debug("aws_clientcredential.h has not been edited. Overwriting.")
else:
warn_msg = (
"Your aws_clientcredential.h file at "
+ credentialFileTemplate
Expand Down

0 comments on commit 177caff

Please sign in to comment.