-
Notifications
You must be signed in to change notification settings - Fork 43
/
config.py
78 lines (63 loc) · 2.89 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""Flask config and env vars.
https://flask.palletsprojects.com/en/latest/config/
"""
import logging
import os
import re
import traceback
from oauth_dropins.webutil import appengine_config, appengine_info, util
# This is primarily for flashed messages, since we don't use session data
# otherwise.
SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
# Not strict because we flash messages after cross-site redirects for OAuth,
# which strict blocks.
SESSION_COOKIE_SAMESITE = 'Lax'
CACHE_THRESHOLD = 3000
# 10MiB. default is 500KiB, and we hit that on receive tasks for some web posts
# https://github.com/snarfed/bridgy-fed/issues/1593
MAX_FORM_MEMORY_SIZE = 10000000
config_logger = logging.getLogger(__name__)
if appengine_info.DEBUG:
ENV = 'development'
CACHE_TYPE = 'NullCache'
SECRET_KEY = 'sooper seekret'
else:
ENV = 'production'
CACHE_TYPE = 'SimpleCache'
SECRET_KEY = util.read('flask_secret_key')
logging.getLogger().setLevel(logging.INFO)
if logging_client := getattr(appengine_config, 'logging_client'):
logging_client.setup_logging(log_level=logging.INFO)
for logger in ('atproto_firehose', 'lexrpc', 'oauth_dropins.webutil.webmention'):
logging.getLogger(logger).setLevel(logging.DEBUG)
# for debugging ndb. also needs NDB_DEBUG env var.
# https://github.com/googleapis/python-ndb/blob/c55ec62b5153787404488b046c4bf6ffa02fee64/google/cloud/ndb/utils.py#L78-L81
# logging.getLogger('google.cloud.ndb').setLevel(logging.DEBUG)
logging.getLogger('google.cloud.ndb._cache').setLevel(logging.DEBUG)
KEYS_ID_RE = re.compile(f'name: "([^"]+)"')
def only_lookups(record):
msg = record.getMessage()
if '\nkeys {' in msg:
if id := KEYS_ID_RE.search(msg):
stack = [frame for frame in traceback.extract_stack()[:-1]
if frame.filename.startswith('/workspace/')
or (frame.filename.startswith('/Users/ryan/src/')
and '/lib/' not in frame.filename)]
new_msg = id.group(1) + '\n' + ''.join(traceback.format_list(stack))
config_logger.info(new_msg)
# ideally I'd return a new log record here and let the
# _datastore_api logger emit it, or just modify the record passed in
# here and return True, but that makes tests try to talk to google
# cloud's production logging (?)
#
# return logging.LogRecord(record.name, record.level, record.pathname,
# record.lineno, new_msg, record.args,
# record.exc_info))
return False
api_logger = logging.getLogger('google.cloud.ndb._datastore_api')
api_logger.setLevel(logging.DEBUG)
api_logger.addFilter(only_lookups)
os.environ.setdefault('APPVIEW_HOST', 'api.bsky.local')
os.environ.setdefault('BGS_HOST', 'bgs.bsky.local')
os.environ.setdefault('PLC_HOST', 'plc.bsky.local')