Skip to content

Commit 006c50e

Browse files
authored
Merge pull request #13 from justmobilize/remove-secrets
Remove secrets
2 parents 35e3fab + 6afd7a5 commit 006c50e

File tree

3 files changed

+26
-40
lines changed

3 files changed

+26
-40
lines changed

examples/oauth2_simpletest.py

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
# SPDX-FileCopyrightText: 2020 Brent Rubell, written for Adafruit Industries
22
#
33
# SPDX-License-Identifier: Unlicense
4+
5+
from os import getenv
46
import ssl
57
import wifi
68
import socketpool
79
import adafruit_requests
810
from adafruit_oauth2 import OAuth2
911

10-
# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
11-
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
12-
# source control.
13-
# pylint: disable=no-name-in-module,wrong-import-order
14-
try:
15-
from secrets import secrets
16-
except ImportError:
17-
print("Credentials and tokens are kept in secrets.py, please add them there!")
18-
raise
12+
# Get WiFi details and Google keys, ensure these are setup in settings.toml
13+
ssid = getenv("CIRCUITPY_WIFI_SSID")
14+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
15+
google_client_id = getenv("google_client_id")
16+
google_client_secret = getenv("google_client_secret")
1917

20-
print("Connecting to %s" % secrets["ssid"])
21-
wifi.radio.connect(secrets["ssid"], secrets["password"])
22-
print("Connected to %s!" % secrets["ssid"])
18+
print(f"Connecting to {ssid}")
19+
wifi.radio.connect(ssid, password)
20+
print(f"Connected to {ssid}")
2321

2422
pool = socketpool.SocketPool(wifi.radio)
2523
requests = adafruit_requests.Session(pool, ssl.create_default_context())
@@ -29,9 +27,7 @@
2927
scopes = ["email"]
3028

3129
# Initialize an OAuth2 object
32-
google_auth = OAuth2(
33-
requests, secrets["google_client_id"], secrets["google_client_secret"], scopes
34-
)
30+
google_auth = OAuth2(requests, google_client_id, google_client_secret, scopes)
3531

3632
# Request device and user codes
3733
# https://developers.google.com/identity/protocols/oauth2/limited-input-device#step-1:-request-device-and-user-codes

examples/oauth2_simpletest_cpython.py

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
11
# SPDX-FileCopyrightText: 2020 Brent Rubell, written for Adafruit Industries
22
#
33
# SPDX-License-Identifier: Unlicense
4+
5+
from os import getenv
46
import socket
57
import ssl
68
import adafruit_requests
79
from adafruit_oauth2 import OAuth2
810

9-
# Add a secrets.py to your filesystem that has a dictionary called secrets with Google
10-
# application tokens. DO NOT share that file or commit it into Git or other
11-
# source control.
12-
# pylint: disable=no-name-in-module,wrong-import-order
13-
try:
14-
from secrets import secrets
15-
except ImportError:
16-
print("Credentials and tokens are kept in secrets.py, please add them there!")
17-
raise
11+
# Get Google keys, ensure these are setup in settings.toml
12+
google_client_id = getenv("google_client_id")
13+
google_client_secret = getenv("google_client_secret")
1814

1915
requests = adafruit_requests.Session(socket, ssl.create_default_context())
2016

2117
# Set scope(s) of access required by the API you're using
2218
scopes = ["email"]
2319

2420
# Initialize an OAuth2 object
25-
google_auth = OAuth2(
26-
requests, secrets["google_client_id"], secrets["google_client_secret"], scopes
27-
)
21+
google_auth = OAuth2(requests, google_client_id, google_client_secret, scopes)
2822

2923
# Request device and user codes
3024
# https://developers.google.com/identity/protocols/oauth2/limited-input-device#step-1:-request-device-and-user-codes

examples/oauth2_simpletest_esp32spi.py

+9-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# SPDX-FileCopyrightText: 2020 Brent Rubell, written for Adafruit Industries
22
#
33
# SPDX-License-Identifier: Unlicense
4+
5+
from os import getenv
46
import board
57
import busio
68
from digitalio import DigitalInOut
@@ -10,15 +12,11 @@
1012
import adafruit_requests
1113
from adafruit_oauth2 import OAuth2
1214

13-
# Add a secrets.py to your filesystem that has a dictionary called secrets with "ssid" and
14-
# "password" keys with your WiFi credentials. DO NOT share that file or commit it into Git or other
15-
# source control.
16-
# pylint: disable=no-name-in-module,wrong-import-order
17-
try:
18-
from secrets import secrets
19-
except ImportError:
20-
print("Credentials and tokens are kept in secrets.py, please add them there!")
21-
raise
15+
# Get WiFi details and Google keys, ensure these are setup in settings.toml
16+
ssid = getenv("CIRCUITPY_WIFI_SSID")
17+
password = getenv("CIRCUITPY_WIFI_PASSWORD")
18+
google_client_id = getenv("google_client_id")
19+
google_client_secret = getenv("google_client_secret")
2220

2321
esp32_cs = DigitalInOut(board.ESP_CS)
2422
esp32_ready = DigitalInOut(board.ESP_BUSY)
@@ -30,7 +28,7 @@
3028
print("Connecting to AP...")
3129
while not esp.is_connected:
3230
try:
33-
esp.connect_AP(secrets["ssid"], secrets["password"])
31+
esp.connect_AP(ssid, password)
3432
except RuntimeError as e:
3533
print("could not connect to AP, retrying: ", e)
3634
continue
@@ -45,9 +43,7 @@
4543
scopes = ["email"]
4644

4745
# Initialize an OAuth2 object
48-
google_auth = OAuth2(
49-
requests, secrets["google_client_id"], secrets["google_client_secret"], scopes
50-
)
46+
google_auth = OAuth2(requests, google_client_id, google_client_secret, scopes)
5147

5248
# Request device and user codes
5349
# https://developers.google.com/identity/protocols/oauth2/limited-input-device#step-1:-request-device-and-user-codes

0 commit comments

Comments
 (0)