Skip to content

Commit 057f0e8

Browse files
committed
Add docstring comments to functions
1 parent 7f92e7b commit 057f0e8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

authenticating-users/main.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222

2323

2424
def certs():
25+
"""Returns a dictionary of current Google public key certificates for
26+
validating Google-signed JWTs. Since these change rarely, the result
27+
is cached on first request for faster subsequent responses.
28+
"""
2529
import requests
2630

2731
global CERTS
@@ -34,6 +38,10 @@ def certs():
3438

3539

3640
def get_metadata(item_name):
41+
"""Returns a string with the project metadata value for the item_name.
42+
See https://cloud.google.com/compute/docs/storing-retrieving-metadata for
43+
possible item_name values.
44+
"""
3745
import requests
3846

3947
endpoint = 'http://metadata.google.internal'
@@ -48,6 +56,10 @@ def get_metadata(item_name):
4856

4957

5058
def audience():
59+
"""Returns the audience value (the JWT 'aud' property) for the current
60+
running instance. Since this involves a metadata lookup, the result is
61+
cached when first requested for faster future responses.
62+
"""
5163
global AUDIENCE
5264
if AUDIENCE is None:
5365
project_number = get_metadata('numeric-project-id')
@@ -59,6 +71,10 @@ def audience():
5971

6072

6173
def validate_assertion(assertion):
74+
"""Checks that the JWT assertion is valid (properly signed, for the
75+
correct audience) and if so, returns strings for the requesting user's
76+
email and a persistent user ID. If not valid, returns None for each field.
77+
"""
6278
from jose import jwt
6379

6480
try:

0 commit comments

Comments
 (0)