Skip to content
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

Remove secrets usage #32

Merged
merged 2 commits into from
Mar 5, 2025
Merged

Conversation

justmobilize
Copy link
Contributor

Remove secrets usage

@justmobilize justmobilize marked this pull request as ready for review February 27, 2025 23:50
@justmobilize
Copy link
Contributor Author

@FoamyGuy this should be the last batch (11) of secret removals.

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

this page needs updated when this gets merged https://learn.adafruit.com/bluetooth-le-broadcastnet-sensor-node-raspberry-pi-wifi-bridge/install-pi-bridge-software. It's 🛏️ ⌚ for me though. Will merge and update page tomorrow.

# Get Adafruit IO keys, ensure these are setup in your environment
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
aio_key = getenv("ADAFRUIT_AIO_KEY")
Copy link
Contributor

Choose a reason for hiding this comment

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

This example is meant for raspberry pi, so settings.toml is not going to automatically make it's way into environment variables in that environment.

We could instruct users to export the variables needed before running the script, but that would need to be done each time, so then we could point them to .bashrc or similar, but I'm not sure this is really the best option.

Maybe the script should be modified to parse the toml file and set environment variables from before accessing them. That way the user doesn't need to do anything manual and the experience is mostly the same as on MCU.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@FoamyGuy how about this (it's what I do for mine):

import tomllib

# Get Adafruit IO keys, ensure these are setup in settings.toml
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
with open("settings.toml", "rb") as toml_file:
    settings = tomllib.load(toml_file)
aio_username = settings("ADAFRUIT_AIO_USERNAME")
aio_key = settings("ADAFRUIT_AIO_KEY")

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks good to me, however until we raise the minimum supported python version of the libraries and Blinka I think we should have code that is compatible with both tomllib and toml. And I think have a note in the error message if it fails to import either that they can install it from pip.

I'll make a note to discuss minimum supported version in the weeds.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@FoamyGuy, do we need to add toml to Blink first?

Copy link
Contributor

Choose a reason for hiding this comment

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

If/when we add settings.toml loading to Blinka then yes I think we should add it as a req for any versions prior to it becoming built-in.

If the code is going to live in the example script like the one in this repo then I don't think we need to add it as a dependency for Blinka yet.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@FoamyGuy so this should now be:

from adafruit_blinka import load_settings_toml
...
# Get Adafruit IO keys, ensure these are setup in settings.toml
# (visit io.adafruit.com if you need to create an account, or if you need your Adafruit IO key.)
load_settings_toml()
aio_username = getenv("ADAFRUIT_AIO_USERNAME")
aio_key = getenv("ADAFRUIT_AIO_KEY")

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that looks correct to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here: dbd3761

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

Looking into this and thinking about the changes needed to the guide I think there is actually a little more to consider for this one.

@justmobilize justmobilize requested a review from FoamyGuy March 4, 2025 17:30
Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

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

Thank you!

@FoamyGuy FoamyGuy merged commit a8a97af into adafruit:main Mar 5, 2025
1 check passed
@justmobilize justmobilize deleted the remove-secrets-usage branch March 5, 2025 03:29
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants