-
Notifications
You must be signed in to change notification settings - Fork 51
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 #245
Remove secrets usage #245
Conversation
There are 6 PRs that use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -61,7 +63,7 @@ def message(client, topic, message): | |||
|
|||
# Set up a MiniMQTT Client | |||
mqtt_client = MQTT.MQTT( | |||
broker=os.getenv("broker"), | |||
broker="io.adafruit.com", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we stick with broker env var lookup and fall back to io.adafruit.com using the second parameter / default value, as this example isn't really IO related (just a good test server if the user already has an account). Similarly here: https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT/pull/245/files#diff-afdace9507c758aee40533c5ef2f1cacbfe152f00f601e2fc07571931dfa63f8R16 which is examples/esp32spi/minimqtt_certificate_esp32spi.py
line 16.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, something like that. think i spotted "broker" in a few other places too (just glancing at the connect lines)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will find all of these and make sure they are updated correctly. Will hold until I get other answers to do the work
@@ -11,12 +11,12 @@ | |||
|
|||
import adafruit_minimqtt.adafruit_minimqtt as MQTT | |||
|
|||
# Add settings.toml to your filesystem CIRCUITPY_WIFI_SSID and CIRCUITPY_WIFI_PASSWORD keys | |||
# with your WiFi credentials. Add your Adafruit IO username and key as well. | |||
# DO NOT share that file or commit it into Git or other source control. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want these warnings back (line 16), regarding not commiting/sharing settings.toml, as these examples are more intended for new users.
I'm also less of a fan of just getenv and prefer the module qualified version (os.getenv) as it's clearer what's going on for new users (the from syntax is rarely mentioned in learn guides), but personal preference maybe (and we should educate users).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So these are copied from other example. Like Requests just has:
# Get WiFi details, ensure these are setup in settings.toml
ssid = os.getenv("CIRCUITPY_WIFI_SSID")
password = os.getenv("CIRCUITPY_WIFI_PASSWORD")
I did my best to merge them. Happy to update these to have the warnings if wanted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tyeth, as far as os.getenv
vs getenv
, I'm good either way. The examples across the libraries are a mix. Let me know what you want here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tyeth I'm happy with what ever you want here. Let me know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Only a couple of thoughts related to beginners, and using the broker address from os.getenv with a default value of io.adafruit.com wherever broker
is used.
I'd quite like to run all of the examples before release, just to be sure, but won't likely get around to it until the end of the week. Equally happy for others to do so instead.
Likewise, not too fussed, just thought worth the mention, and if memory
servers the guides mostly refer to os.getenv and then link to the examples
from github, but I only really recollect it in the "settings.toml /
internet connect" learn guide template page that most reuse.
Leave it to @brentru or @dhalbert to express a preference (or more likely
just leave as is), and same with the beginner warning about not
committing the settings file.
…On Wed, 26 Feb 2025 at 16:07, Justin Myers ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In examples/esp32spi/minimqtt_simpletest_esp32spi.py
<#245 (comment)>
:
> @@ -11,12 +11,12 @@
import adafruit_minimqtt.adafruit_minimqtt as MQTT
-# Add settings.toml to your filesystem CIRCUITPY_WIFI_SSID and CIRCUITPY_WIFI_PASSWORD keys
-# with your WiFi credentials. Add your Adafruit IO username and key as well.
-# DO NOT share that file or commit it into Git or other source control.
@tyeth <https://github.com/tyeth>, as far as os.getenv vs getenv, I'm
good either way. The examples across the libraries are a mix. Let me know
what you want here
—
Reply to this email directly, view it on GitHub
<#245 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTBZ42MA6NUUMUQLTGD46L2RXRCXAVCNFSM6AAAAABXZFATJ2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDMNBVGA2DSOJSGQ>
.
You are receiving this because you were mentioned.Message ID:
<adafruit/Adafruit_CircuitPython_MiniMQTT/pull/245/review/2645049924@
github.com>
|
port=os.getenv("port"), | ||
username=os.getenv("username"), | ||
password=os.getenv("password"), | ||
broker="io.adafruit.com", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example is actually meant to be optionally another server and port (just as it's simple test we might as well show the optional arg, you can use 1883 for insecure or 8883 for secure), as all it does it test callbacks and no IO specific behaviour.
broker=broker, | ||
port=broker_port, | ||
socket_pool=pool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we want to add the username and password here too, not sure how this ever worked unless it was a broker that doesn't require one (like test.mosquitto.org), but the aio_username used in topic later is now needed so we might as well offer it here too.
broker=broker, | |
port=broker_port, | |
socket_pool=pool, | |
broker=broker, | |
port=broker_port, | |
username=aio_username, | |
password=aio_key, | |
socket_pool=pool, |
@@ -106,14 +105,14 @@ def on_message(client, topic, message): | |||
client.on_subscribe = subscribe | |||
client.on_unsubscribe = unsubscribe | |||
client.on_message = on_message | |||
client.add_topic_callback(secrets["aio_username"] + "/feeds/device.batterylevel", on_battery_msg) | |||
client.add_topic_callback(aio_username + "/feeds/device.batterylevel", on_battery_msg) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (aio_username) doesn't exist, see comments earlier in file
ssid = getenv("CIRCUITPY_WIFI_SSID") | ||
password = getenv("CIRCUITPY_WIFI_PASSWORD") | ||
broker = getenv("broker") | ||
broker_port = getenv("broker_port") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we provide defaults here too for port/broker, in addition to getting the aio_username (and I've grabbed key too)
ssid = getenv("CIRCUITPY_WIFI_SSID") | |
password = getenv("CIRCUITPY_WIFI_PASSWORD") | |
broker = getenv("broker") | |
broker_port = getenv("broker_port") | |
ssid = getenv("CIRCUITPY_WIFI_SSID") | |
password = getenv("CIRCUITPY_WIFI_PASSWORD") | |
aio_username = getenv("ADAFRUIT_AIO_USERNAME") | |
aio_key = getenv("ADAFRUIT_AIO_KEY") | |
broker = getenv("broker", "io.adafruit.com") | |
broker_port = getenv("broker_port", 1883) # Port 1883 insecure, 8883 secure | |
@tyeth I updated all the places we needed |
ssid = getenv("CIRCUITPY_WIFI_SSID") | ||
password = getenv("CIRCUITPY_WIFI_PASSWORD") | ||
broker = getenv("broker") | ||
username = getenv("username") | ||
paswword = getenv("paswword") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getenv not defined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just that one missing import, apart from that looks great, thanks for all the hard work!
I can't deny I wanted to suggest the "broker" environment variable be uppercase, but seeing the older fona example use it I guess either we have that as the odd one out or just leave broker alone for now.
Happy to update, but the few places in the bundle it exists are all lowercase |
Leave it all lowercase.
I'm less impressed that it passed all CI tests but with broken examples.
This is my first direct experience of ruff Vs pylint, although discussed a
lot with peers [seems the rule categories are insanely grouped and I
dislike using numbers to disable rules as unintelligible] and can only
assume that our rules are not optimally chosen yet.
Attempting to use the official ruff plugin for vscode, it refuses to use ruff with this repo and in the logs shows:
2025-03-06 13:45:01.901962000 ERROR Failed to resolve settings for c:\dev\python\circuitpython\Adafruit_CircuitPython_MiniMQTT\ruff.toml: Rule `E999` was removed and cannot be selected.
2025-03-06 13:45:01.910285500 INFO Registering workspace: c:\dev\python\circuitpython\Adafruit_CircuitPython_MiniMQTT
2025-03-06 13:45:01.912912000 INFO Configuration file watcher successfully registered
@FoamyGuy have you seen this behaviour before, where an undefined method/variable is not picked up by ruff?
…On Thu, 6 Mar 2025, 05:14 Justin Myers, ***@***.***> wrote:
Just that one missing import, apart from that looks great, thanks for all
the hard work!
I can't deny I wanted to suggest the "broker" environment variable be
uppercase, but seeing the older fona example use it I guess either we have
that as the odd one out or just leave broker alone for now.
Happy to update, but the few places in the bundle it exists are all
lowercase
—
Reply to this email directly, view it on GitHub
<#245 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTBZ434Q7K7ROEMTEWLWHL2S7KRVAVCNFSM6AAAAABXZFATJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMBSHAZTKMBUGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
[image: justmobilize]*justmobilize* left a comment
(adafruit/Adafruit_CircuitPython_MiniMQTT#245)
<#245 (comment)>
Just that one missing import, apart from that looks great, thanks for all
the hard work!
I can't deny I wanted to suggest the "broker" environment variable be
uppercase, but seeing the older fona example use it I guess either we have
that as the odd one out or just leave broker alone for now.
Happy to update, but the few places in the bundle it exists are all
lowercase
—
Reply to this email directly, view it on GitHub
<#245 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABTBZ434Q7K7ROEMTEWLWHL2S7KRVAVCNFSM6AAAAABXZFATJ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMBSHAZTKMBUGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
E999 Was removed in ruff 0.8.0 (November 2024) because it's always on now (it's syntax errors). The cookiecutter pre-commit uses v0.3.4 (and therefore so does this repository). Note the pre-commit version seemingly matches the ruff version. Adafruit_CircuitPython_MiniMQTT/.pre-commit-config.yaml Lines 13 to 14 in 08253c4
|
@tyeth are you good with the code? I think we can bring up the ruff issues in discord |
I haven't seen much traction in discord for some things, probably as there are too many notifications in the circuitpython-dev channel to make it a pleasant experience catching up on all discussions (and my questions being poorly framed or with no definitive answer - plus I should maybe tag people even if occasionally unwanted). I'm happy to merge this, but I think I want a real issue raised that ruff is not working as expected possibly meaning errors are being introduced without automatic detection. Also please forgive my unfamiliarity of the circuitpython workings and processes, I normally live in arduino land and keep half an ear on circuitpython only occasionally do a bit of fixing/testing/maintenance (along with some weekend projects). |
@tyeth I'll dig into the ruff stuff and make sure it comes up next week during |
Yeah that's probably best place for it. Plus reorder the ruff format to after fix, to comply with the newest recommendation in 0.9.9 (thanks @Neradoc ) |
Okay, @justmobilize this is now the real ruff error messages (some rules were ignored without preview mode being on, and we still must be missing basic rules if I had to add F821 Undefined Name). I've taken out the class too long one, but the rest might be actually this PR (doesn't look like it though), please take a quick look. |
@tyeth I added ignores for the rest, which are valid for now (although could be cleaned up 1 by 1) |
Hero level work, thank you so much! Making a mental note to go back and remove those after we clear up the default circuitpython library ruff rules |
Updating https://github.com/adafruit/Adafruit_CircuitPython_MiniMQTT to 7.11.6 from 7.11.5: > Merge pull request adafruit/Adafruit_CircuitPython_MiniMQTT#245 from justmobilize/remove-secrets-usage
Remove usage of secrets and more:
secrets.py
toos.getenv
ESPSPI_WiFiManager
toWiFiManager
adafruit_connection_manager
like all the other examples