Skip to content

Commit 0a95237

Browse files
committed
Update existing example code.
Changes: - Update requirements.txt files to pegged versions for all modules. - Update .posts references to .courseWork endpoints. - Fix behavior since `hd` was removed. - Reformat to comply with updated go/pystyle. - Launch an https server by default. Change-Id: I93e455a712265fc81e2a1bc1d09030fb4880a0bc
1 parent c5710c3 commit 0a95237

38 files changed

+3114
-2863
lines changed

flask/01-basic-app/config.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818

1919

2020
class Config(object):
21-
# Note: A secret key is included in the sample so that it works.
22-
# If you use this code in your application, replace this with a truly secret
23-
# key. See https://flask.palletsprojects.com/quickstart/#sessions.
24-
SECRET_KEY = os.environ.get(
25-
'SECRET_KEY') or "REPLACE ME - this value is here as a placeholder."
21+
# Note: A secret key is included in the sample so that it works.
22+
# If you use this code in your application, replace this with a truly secret
23+
# key. See https://flask.palletsprojects.com/quickstart/#sessions.
24+
SECRET_KEY = (
25+
os.environ.get("SECRET_KEY")
26+
or "REPLACE ME - this value is here as a placeholder."
27+
)

flask/01-basic-app/main.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,31 @@
2020
import os
2121

2222
if __name__ == "__main__":
23-
# You have several options for running the web server.
24-
25-
### OPTION 1: Unsecured localhost
26-
# When running locally on unsecured HTTP, use this line to disable
27-
# OAuthlib's HTTPs verification.
28-
29-
# Important: When running in production *do not* leave this option enabled.
30-
# os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
31-
32-
# Run the application on a local server, defaults to http://localhost:5000.
33-
# Note: the OAuth flow requires a TLD, *not* an IP address; "localhost" is
34-
# acceptable, but http://127.0.0.1 is not.
35-
# app.run(debug=True)
36-
37-
### OPTION 2: Secure localhost
38-
# Run the application over HTTPs with a locally stored certificate and key.
39-
# Defaults to https://localhost:5000.
40-
app.run(
41-
host="localhost",
42-
ssl_context=("localhost.pem", "localhost-key.pem"),
43-
debug=True)
44-
45-
### OPTION 3: Production- or cloud-ready server
46-
# Start a Gunicorn server, which is appropriate for use in production or a
47-
# cloud deployment.
48-
# server_port = os.environ.get("PORT", "8080")
49-
# app.run(debug=True, port=server_port, host="0.0.0.0")
23+
# You have several options for running the web server.
24+
25+
### OPTION 1: Unsecured localhost
26+
# When running locally on unsecured HTTP, use this line to disable
27+
# OAuthlib's HTTPs verification.
28+
29+
# Important: When running in production *do not* leave this option enabled.
30+
# os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
31+
32+
# Run the application on a local server, defaults to http://localhost:5000.
33+
# Note: the OAuth flow requires a TLD, *not* an IP address; "localhost" is
34+
# acceptable, but http://127.0.0.1 is not.
35+
# app.run(debug=True)
36+
37+
### OPTION 2: Secure localhost
38+
# Run the application over HTTPs with a locally stored certificate and key.
39+
# Defaults to https://localhost:5000.
40+
app.run(
41+
host="localhost",
42+
ssl_context=("localhost.pem", "localhost-key.pem"),
43+
debug=True,
44+
)
45+
46+
### OPTION 3: Production- or cloud-ready server
47+
# Start a Gunicorn server, which is appropriate for use in production or a
48+
# cloud deployment.
49+
# server_port = os.environ.get("PORT", "8080")
50+
# app.run(debug=True, port=server_port, host="0.0.0.0")
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
Flask==2.0.2
1+
Flask==2.2.2
2+
SQLAlchemy==1.4
23
Flask_SQLAlchemy==2.5.1
34
Flask_WTF==1.0.0
45
google_api_python_client==2.56.0
56
google_auth_oauthlib==0.4.6
67
protobuf==4.21.5
78
requests==2.27.1
89
WTForms==3.0.1
10+
Werkzeug==2.3.7

flask/01-basic-app/webapp/routes.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,25 @@
2020

2121
@app.route("/")
2222
def index():
23-
"""
24-
Render the index page from the "index.html" template. This is meant to act
25-
as a facsimile of a company's home page. The Add-on Discovery URL should be
26-
set to the /classroom-addon route below.
27-
"""
23+
"""
24+
Render the index page from the "index.html" template. This is meant to act
25+
as a facsimile of a company's home page. The Add-on Discovery URL should be
26+
set to the /addon-discovery route below.
27+
"""
2828

29-
return flask.render_template(
30-
"index.html", message="You've reached the index page.")
29+
return flask.render_template(
30+
"index.html", message="You've reached the index page."
31+
)
3132

3233

33-
@app.route("/classroom-addon")
34+
@app.route("/addon-discovery")
3435
def classroom_addon():
35-
"""
36-
Renders the addon discovery page from the "addon-discovery.html" template.
37-
This is meant to be the landing page when opening the web app in the
38-
Classroom add-on iframe.
39-
"""
36+
"""
37+
Renders the addon discovery page from the "addon-discovery.html" template.
38+
This is meant to be the landing page when opening the web app in the
39+
Classroom add-on iframe.
40+
"""
4041

41-
return flask.render_template(
42-
"addon-discovery.html",
43-
message="You've reached the addon discovery page.")
42+
return flask.render_template(
43+
"addon-discovery.html", message="You've reached the addon discovery page."
44+
)

flask/02-sign-in/config.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818

1919

2020
class Config(object):
21-
# Note: A secret key is included in the sample so that it works.
22-
# If you use this code in your application, replace this with a truly secret
23-
# key. See https://flask.palletsprojects.com/quickstart/#sessions.
24-
SECRET_KEY = os.environ.get(
25-
'SECRET_KEY') or "REPLACE ME - this value is here as a placeholder."
21+
# Note: A secret key is included in the sample so that it works.
22+
# If you use this code in your application, replace this with a truly secret
23+
# key. See https://flask.palletsprojects.com/quickstart/#sessions.
24+
SECRET_KEY = (
25+
os.environ.get("SECRET_KEY")
26+
or "REPLACE ME - this value is here as a placeholder."
27+
)
2628

27-
# Configure the flask cookie settings per the iframe security recommendations:
28-
# https://developers.google.com/classroom/eap/add-ons-alpha/iframes#iframe_security_guidelines
29-
SESSION_COOKIE_SECURE = True
30-
SESSION_COOKIE_HTTPONLY = True
31-
SESSION_COOKIE_SAMESITE = "None"
29+
# Configure the flask cookie settings per the iframe security recommendations:
30+
# https://developers.google.com/classroom/add-ons/developer-guides/iframes#iframe_security_guidelines
31+
SESSION_COOKIE_SECURE = True
32+
SESSION_COOKIE_HTTPONLY = True
33+
SESSION_COOKIE_SAMESITE = "None"

flask/02-sign-in/main.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,31 @@
3737
import os
3838

3939
if __name__ == "__main__":
40-
# You have several options for running the web server.
40+
# You have several options for running the web server.
4141

42-
### OPTION 1: Unsecured localhost
43-
# When running locally on unsecured HTTP, use this line to disable
44-
# OAuthlib's HTTPs verification.
42+
### OPTION 1: Unsecured localhost
43+
# When running locally on unsecured HTTP, use this line to disable
44+
# OAuthlib's HTTPs verification.
4545

46-
# Important: When running in production *do not* leave this option enabled.
47-
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
46+
# Important: When running in production *do not* leave this option enabled.
47+
# os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
4848

49-
# Run the application on a local server, defaults to http://localhost:5000.
50-
# Note: the OAuth flow requires a TLD, *not* an IP address; "localhost" is
51-
# acceptable, but http://127.0.0.1 is not.
52-
app.run(debug=True)
49+
# Run the application on a local server, defaults to http://localhost:5000.
50+
# Note: the OAuth flow requires a TLD, *not* an IP address; "localhost" is
51+
# acceptable, but http://127.0.0.1 is not.
52+
# app.run(debug=True)
5353

54-
### OPTION 2: Secure localhost
55-
# Run the application over HTTPs with a locally stored certificate and key.
56-
# Defaults to https://localhost:5000.
57-
# app.run(
58-
# host="localhost",
59-
# ssl_context=("localhost.pem", "localhost-key.pem"),
60-
# debug=True)
54+
### OPTION 2: Secure localhost
55+
# Run the application over HTTPs with a locally stored certificate and key.
56+
# Defaults to https://localhost:5000.
57+
app.run(
58+
host="localhost",
59+
ssl_context=("localhost.pem", "localhost-key.pem"),
60+
debug=True,
61+
)
6162

62-
### OPTION 3: Production- or cloud-ready server
63-
# Start a Gunicorn server, which is appropriate for use in production or a
64-
# cloud deployment.
65-
# server_port = os.environ.get("PORT", "8080")
66-
# app.run(debug=True, port=server_port, host="0.0.0.0")
63+
### OPTION 3: Production- or cloud-ready server
64+
# Start a Gunicorn server, which is appropriate for use in production or a
65+
# cloud deployment.
66+
# server_port = os.environ.get("PORT", "8080")
67+
# app.run(debug=True, port=server_port, host="0.0.0.0")

flask/02-sign-in/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
Flask==2.0.2
1+
Flask==2.2.2
2+
SQLAlchemy==1.4
23
Flask_SQLAlchemy==2.5.1
34
Flask_WTF==1.0.0
45
google_api_python_client==2.56.0
56
google_auth_oauthlib==0.4.6
67
protobuf==4.21.5
78
requests==2.27.1
89
WTForms==3.0.1
10+
Werkzeug==2.3.7

0 commit comments

Comments
 (0)