schedulebot: Take creds as a file

Avoids needing to put the creds in docker-compose.jsonnet.
The existing "import" trick didn't work due to the way we run jsonnet in docker.
pull/418/head
Mike Lang 1 month ago
parent e00e716927
commit 4cd0ef1327

@ -273,7 +273,7 @@
// Creds for accessing the schedule google sheet // Creds for accessing the schedule google sheet
schedule_sheet_id: "", schedule_sheet_id: "",
schedule_sheet_name: "All-Everything", schedule_sheet_name: "All-Everything",
google_credentials: import "./google_creds.json", google_credentials_file: "./google_creds.json",
// Map from group names to zulip internal ids // Map from group names to zulip internal ids
groups: { groups: {
Sheeter: 16, Sheeter: 16,
@ -726,8 +726,9 @@
url: $.zulip_url, url: $.zulip_url,
start_time: $.bustime_start, start_time: $.bustime_start,
schedule: "/schedule", schedule: "/schedule",
google_credentials_file: "/creds.json",
}, $.schedulebot.args) + { }, $.schedulebot.args) + {
volumes: ["%s:/schedule" % $.schedulebot.schedule_path], volumes: ["%s:/creds.json" % $.schedulebot.google_credentials_file],
}, },
[if $.enabled.tootbot then "tootbot"]: [if $.enabled.tootbot then "tootbot"]:

@ -2,6 +2,7 @@
import gevent.monkey import gevent.monkey
gevent.monkey.patch_all() gevent.monkey.patch_all()
import json
import logging import logging
import time import time
from calendar import timegm from calendar import timegm
@ -241,10 +242,11 @@ def main(conf_file, hour=-1, no_groups=False, stream="General", no_mentions=Fals
start_time: Time of the first hour, as UTC timestamp string start_time: Time of the first hour, as UTC timestamp string
schedule_sheet_id: Google Sheet ID schedule_sheet_id: Google Sheet ID
schedule_sheet_name: Google Sheet tab name schedule_sheet_name: Google Sheet tab name
google_credentials: (With Read access to schedule_sheet_id) google_credentials_file: (With Read access to schedule_sheet_id)
client_id Path to json file containing at least:
client_secret client_id
refresh_token client_secret
refresh_token
members: members:
NAME: USER_ID NAME: USER_ID
groups: groups:
@ -260,10 +262,12 @@ def main(conf_file, hour=-1, no_groups=False, stream="General", no_mentions=Fals
send_auth = config.get("send_user", config["api_user"]) send_auth = config.get("send_user", config["api_user"])
send_client = Client(config["url"], send_auth["email"], send_auth["api_key"]) send_client = Client(config["url"], send_auth["email"], send_auth["api_key"])
group_ids = config["groups"] group_ids = config["groups"]
with open(config["google_credentials_file"]) as f:
sheets_creds = json.load(f)
sheets_client = Sheets( sheets_client = Sheets(
config["google_credentials"]["client_id"], sheets_creds["client_id"],
config["google_credentials"]["client_secret"], sheets_creds["client_secret"],
config["google_credentials"]["refresh_token"], sheets_creds["refresh_token"],
) )
reload_schedule = lambda: parse_schedule( reload_schedule = lambda: parse_schedule(
sheets_client, sheets_client,

Loading…
Cancel
Save