Skip to content

Commit c01c55b

Browse files
Niloth-ptimabbott
authored andcommitted
google-calendar: Use a constant for the tokens filename.
Instead of using the hardcoded file name value everywhere directly. This enables us to edit the file name with a single change in the following commit.
1 parent 7901153 commit c01c55b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

zulip/integrations/google/get-google-credentials

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ from google.oauth2.credentials import Credentials
66
from google_auth_oauthlib.flow import InstalledAppFlow
77

88
SCOPES = ["https://www.googleapis.com/auth/calendar.events.readonly"]
9+
# File containing user's access and refresh tokens for Google application requests.
10+
# If it does not exist, e.g., first run, it is generated on user authorization.
11+
TOKENS_FILE = "google-credentials.json"
912
# This file contains the information that google uses to figure out which application is requesting
1013
# this client's data.
1114
CLIENT_SECRET_FILE = "client_secret.json" # noqa: S105
@@ -29,7 +32,7 @@ def get_credentials() -> Credentials:
2932
"""
3033

3134
creds = None
32-
credential_path = os.path.join(HOME_DIR, "google-credentials.json")
35+
credential_path = os.path.join(HOME_DIR, TOKENS_FILE)
3336

3437
if os.path.exists(credential_path):
3538
creds = Credentials.from_authorized_user_file(credential_path, SCOPES)

zulip/integrations/google/google-calendar

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ sys.path.append(os.path.join(os.path.dirname(__file__), "../../"))
2222
import zulip
2323

2424
SCOPES = ["https://www.googleapis.com/auth/calendar.events.readonly"]
25+
# File containing user's access and refresh tokens for Google application requests.
26+
# If it does not exist, e.g., first run, it is generated on user authorization.
27+
TOKENS_FILE = "google-credentials.json"
2528
CLIENT_SECRET_FILE = "client_secret.json" # noqa: S105
2629
HOME_DIR = os.path.expanduser("~")
2730

@@ -93,10 +96,10 @@ def get_credentials() -> Credentials:
9396
Credentials, the obtained credential.
9497
"""
9598
try:
96-
credential_path = os.path.join(HOME_DIR, "google-credentials.json")
99+
credential_path = os.path.join(HOME_DIR, TOKENS_FILE)
97100
return Credentials.from_authorized_user_file(credential_path, SCOPES)
98101
except ValueError:
99-
logging.exception("Error while trying to open the `google-credentials.json` file.")
102+
logging.exception("Error while trying to open the %s file.", TOKENS_FILE)
100103
sys.exit(1)
101104
except OSError:
102105
logging.error("Run the get-google-credentials script from this directory first.")

0 commit comments

Comments
 (0)