forked from metabrainz/listenbrainz-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
consul_config.py.ctmpl
289 lines (240 loc) · 11.5 KB
/
consul_config.py.ctmpl
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
{{- define "KEY" -}}
{{ keyOrDefault (printf "docker-server-configs/LB/config.%s.json/%s" (env "DEPLOY_ENV") .) (printf "KEYDOESNOTEXIST_%s" .) }}
{{- end -}}
{{- define "KEY_ARRAY" -}}
{{- range $index, $element := (keyOrDefault (printf "docker-server-configs/LB/config.%s.json/%s" (env "DEPLOY_ENV") .) (printf "[\"KEYDOESNOTEXIST_%s\"]" .) | parseJSON) -}}
"{{.}}",
{{- end -}}
{{- end -}}
{{- define "KEY_JSON" -}}
json.loads('''{{template "KEY" .}}''')
{{- end -}}
# Put everything after the defines otherwise the rendered config might eat up some newlines
import os
import json
DEBUG = False
SECRET_KEY = '''{{template "KEY" "secret_key"}}'''
# Remember cookie is 'Strict' by default and not configurable currently
SESSION_COOKIE_SAMESITE = "Lax"
SESSION_COOKIE_SECURE = True
REMEMBER_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
REMEMBER_COOKIE_HTTPONLY = True
{{if service "pgbouncer-master"}}
{{with index (service "pgbouncer-master") 0}}
SQLALCHEMY_DATABASE_URI = "postgresql://listenbrainz:listenbrainz@{{.Address}}:{{.Port}}/listenbrainz"
POSTGRES_ADMIN_URI="postgresql://postgres@{{.Address}}:{{.Port}}/postgres"
SQLALCHEMY_METABRAINZ_URI = "postgresql://metabrainz:metabrainz@{{.Address}}:{{.Port}}/metabrainz_db"
{{end}}
{{else}}
SQLALCHEMY_DATABASE_URI = "SERVICEDOESNOTEXIST_pgbouncer-master"
POSTGRES_ADMIN_URI = "SERVICEDOESNOTEXIST_pgbouncer-master"
SQLALCHEMY_METABRAINZ_URI = "SERVICEDOESNOTEXIST_pgbouncer-master"
{{end}}
IS_MUSICBRAINZ_UP = {{template "KEY_JSON" "musicbrainz_up"}}
# Use a key '$musicbrainz_up' in consul (json boolean true or false) to decide if we connect to musicbrainz.
# If we set MB_DATABASE_URI to an empty string, then the @mb_database_needed decorator will prevent the
# webserver from accessing the musicbrainz database.
{{- /* This needs to use key/printf again here instead of our pre-defined template at the top of the file as you cannot
call a template in an if statement or variable declaration */}}
{{- $musicbrainz_up := (key (printf "docker-server-configs/LB/config.%s.json/musicbrainz_up" (env "DEPLOY_ENV"))) }}
{{- if $musicbrainz_up | parseBool}}
{{if service "pgbouncer-slave"}}
{{with index (service "pgbouncer-slave") 0}}
MB_DATABASE_URI = 'postgresql://musicbrainz_ro@{{.Address}}:{{.Port}}/musicbrainz_db'
MB_DATABASE_MAPPING_URI = 'postgresql://mbid_mapper@{{.Address}}:{{.Port}}/musicbrainz_db'
{{end}}
{{else if service "pgbouncer-master"}}
{{with index (service "pgbouncer-master") 0}}
MB_DATABASE_URI = 'postgresql://musicbrainz_ro@{{.Address}}:{{.Port}}/musicbrainz_db'
MB_DATABASE_MAPPING_URI = 'postgresql://mbid_mapper@{{.Address}}:{{.Port}}/musicbrainz_db'
{{end}}
{{else}}
MB_DATABASE_URI = "SERVICEDOESNOTEXIST_pgbouncer-slave_pgbouncer-master"
MB_DATABASE_MAPPING_URI = "SERVICEDOESNOTEXIST_pgbouncer-slave_pgbouncer-master"
{{end}}
{{else}}
MB_DATABASE_URI = ""
{{end}}
# Use a key 'listenstore_up' in consul (json boolean true or false) to decide if we connect to timescale.
# If we set SQLALCHEMY_TIMESCALE_URI to an empty string, then the @api_listenstore_needed and @web_listenstore_needed
# decorators will prevent the webserver from accessing the timescale database
{{- /* This needs to use key/printf again here instead of our pre-defined template at the top of the file as you cannot
call a template in an if statement or variable declaration */}}
{{- $listenstore_up := (key (printf "docker-server-configs/LB/config.%s.json/listenstore_up" (env "DEPLOY_ENV"))) }}
{{- if $listenstore_up | parseBool}}
{{- if service "timescale-listenbrainz"}}
{{with index (service "timescale-listenbrainz") 0}}
SQLALCHEMY_TIMESCALE_URI = """postgresql://listenbrainz_ts:{{template "KEY" "timescale_lb_password"}}@{{.Address}}:{{.Port}}/listenbrainz_ts"""
TIMESCALE_ADMIN_URI = """postgresql://postgres:{{template "KEY" "timescale_admin_password"}}@{{.Address}}:{{.Port}}/postgres"""
TIMESCALE_ADMIN_LB_URI = """postgresql://postgres:{{template "KEY" "timescale_admin_password"}}@{{.Address}}:{{.Port}}/listenbrainz_ts"""
# for use in playlists admin view
SQLALCHEMY_BINDS = {
'timescale': SQLALCHEMY_TIMESCALE_URI
}
{{end}}
{{else}}
SQLALCHEMY_TIMESCALE_URI = "SERVICEDOESNOTEXIST_timescale-listenbrainz"
TIMESCALE_ADMIN_URI = "SERVICEDOESNOTEXIST_timescale-listenbrainz"
TIMESCALE_ADMIN_LB_URI = "SERVICEDOESNOTEXIST_timescale-listenbrainz"
SQLALCHEMY_BINDS = {}
{{end}}
{{else}}
SQLALCHEMY_TIMESCALE_URI = ""
TIMESCALE_ADMIN_URI=""
TIMESCALE_ADMIN_LB_URI=""
SQLALCHEMY_BINDS = {}
{{end}}
{{if service "pgbouncer-aretha"}}
{{with index (service "pgbouncer-aretha") 0}}
MBID_MAPPING_DATABASE_URI = "dbname=musicbrainz_json_dump user=musicbrainz host={{.Address}} port={{.Port}} password=musicbrainz"
{{end}}
{{else}}
MBID_MAPPING_DATABASE_URI = ""
{{end}}
{{if service "typesense-listenbrainz-new"}}
{{with index (service "typesense-listenbrainz-new") 0}}
TYPESENSE_HOST = "{{.Address}}"
TYPESENSE_PORT = {{.Port}}
{{end}}
{{else}}
TYPESENSE_HOST = "localhost"
TYPESENSE_PORT = 80
{{end}}
TYPESENSE_API_KEY = '''{{template "KEY" "typesense_api_key"}}'''
{{if service "couchdb-listenbrainz"}}
{{with index (service "couchdb-listenbrainz") 0}}
COUCHDB_HOST = "{{.Address}}"
COUCHDB_PORT = {{.Port}}
{{end}}
{{else}}
COUCHDB_HOST = "localhost"
COUCHDB_PORT = 5984
{{end}}
COUCHDB_USER = "listenbrainz"
COUCHDB_ADMIN_KEY = '''{{template "KEY" "couchdb_admin_key"}}'''
{{if service "listenbrainz-redis"}}
{{with index (service "listenbrainz-redis") 0}}
REDIS_HOST = "{{.Address}}"
REDIS_PORT = {{.Port}}
REDIS_NAMESPACE = "listenbrainz"
{{end}}
{{else}}
REDIS_HOST = "SERVICEDOESNOTEXIST_listenbrainz-redis"
REDIS_PORT = "SERVICEDOESNOTEXIST_listenbrainz-redis"
REDIS_NAMESPACE = "SERVICEDOESNOTEXIST_listenbrainz-redis"
{{end}}
{{ $rabbitmq_key := (printf "docker-server-configs/LB/config.%s.json/rabbitmq_service" (env "DEPLOY_ENV")) }}
{{- with $rabbitmq_service_name := keyOrDefault $rabbitmq_key "rabbitmq"}}
{{- if service $rabbitmq_service_name}}
{{- with index (service $rabbitmq_service_name) 0}}
RABBITMQ_HOST = "{{.Address}}"
RABBITMQ_PORT = {{.Port}}
{{end}}
{{else}}
RABBITMQ_HOST = "SERVICEDOESNOTEXIST_rabbitmq"
RABBITMQ_PORT = "SERVICEDOESNOTEXIST_rabbitmq"
{{end}}
{{end}}
RABBITMQ_USERNAME = '''{{template "KEY" "rabbitmq_user"}}'''
RABBITMQ_PASSWORD = '''{{template "KEY" "rabbitmq_pass"}}'''
RABBITMQ_VHOST = '''{{template "KEY" "rabbitmq_vhost"}}'''
MAXIMUM_RABBITMQ_CONNECTIONS = 20
INCOMING_EXCHANGE = '''{{template "KEY" "incoming_exchange"}}'''
INCOMING_QUEUE = '''{{template "KEY" "incoming_queue"}}'''
UNIQUE_EXCHANGE = '''{{template "KEY" "unique_exchange"}}'''
UNIQUE_QUEUE = '''{{template "KEY" "unique_queue"}}'''
WEBSOCKETS_QUEUE = '''{{template "KEY" "websockets_queue"}}'''
PLAYING_NOW_EXCHANGE = '''{{template "KEY" "playing_now_exchange"}}'''
PLAYING_NOW_QUEUE = '''{{template "KEY" "playing_now_queue"}}'''
SPOTIFY_METADATA_QUEUE = '''{{template "KEY" "spotify_metadata_queue"}}'''
SPARK_RESULT_EXCHANGE = '''{{template "KEY" "spark_result_exchange"}}'''
SPARK_RESULT_QUEUE = '''{{template "KEY" "spark_result_queue"}}'''
SPARK_REQUEST_EXCHANGE = '''{{template "KEY" "spark_request_exchange"}}'''
SPARK_REQUEST_QUEUE = '''{{template "KEY" "spark_request_queue"}}'''
EXTERNAL_SERVICES_EXCHANGE = '''{{template "KEY" "external_services_exchange"}}'''
EXTERNAL_SERVICES_SPOTIFY_CACHE_QUEUE = '''{{template "KEY" "external_services_spotify_cache"}}'''
EXTERNAL_SERVICES_APPLE_CACHE_QUEUE = '''{{template "KEY" "external_services_apple_cache"}}'''
EXTERNAL_SERVICES_SOUNDCLOUD_CACHE_QUEUE = '''{{template "KEY" "external_services_soundcloud_cache"}}'''
MUSICBRAINZ_CLIENT_ID = '''{{template "KEY" "musicbrainz/client_id"}}'''
MUSICBRAINZ_CLIENT_SECRET = '''{{template "KEY" "musicbrainz/client_secret"}}'''
MUSICBRAINZ_BASE_URL = "https://musicbrainz.org"
MUSICBRAINZ_OAUTH_URL = f"{MUSICBRAINZ_BASE_URL}/oauth2/userinfo"
LASTFM_API_URL = '''{{template "KEY" "lastfm_api_url"}}'''
LASTFM_API_KEY = '''{{template "KEY" "lastfm_api_key"}}'''
LIBREFM_API_URL = '''{{template "KEY" "librefm_api_url"}}'''
LIBREFM_API_KEY = '''{{template "KEY" "librefm_api_key"}}'''
# Default is fine for now
PLAYING_NOW_MAX_DURATION = 10 * 60
# MAX file size to be allowed for the lastfm-backup import, default is infinite
# Size is in bytes
MAX_CONTENT_LENGTH = 16 * 1024 * 1024 # 16MB
# Specify the upload folder where all the lastfm-backup will be stored
# The path must be absolute path
UPLOAD_FOLDER = '''{{template "KEY" "upload_folder"}}'''
API_URL = '''{{template "KEY" "api_url"}}'''
LASTFM_PROXY_URL = '''{{template "KEY" "lastfm_proxy_url"}}'''
SERVER_ROOT_URL = '''{{template "KEY" "server_root_url"}}'''
LISTENBRAINZ_LABS_API_URL = 'https://labs.api.listenbrainz.org'
WEBSOCKETS_SERVER_URL = SERVER_ROOT_URL
# Sentry config
LOG_SENTRY = {
'dsn': '''{{template "KEY" "sentry/dsn"}}''',
'environment': '''{{template "KEY" "sentry/environment"}}''',
'release': os.getenv('GIT_SHA', None),
'traces_sample_rate': {{template "KEY" "sentry/traces_sample_rate"}},
}
DATASETS_SENTRY_DSN = '''{{template "KEY" "sentry/datasets_dsn"}}'''
# Stats
STATS_ENTITY_LIMIT = 100 # the number of entities to calculate at max with BQ
STATS_CALCULATION_LOGIN_TIME = 30 # users must have logged in to LB in the past 30 days for stats to be calculated
STATS_CALCULATION_INTERVAL = 7 # stats are calculated every 7 days
MUSICBRAINZ_IMPORT_DRY_RUN = True
ADMINS = [
{{template "KEY_ARRAY" "admins"}}
]
APPROVED_PLAYLIST_BOTS = [
{{template "KEY_ARRAY" "approved_playlist_bots"}}
]
WHITELISTED_AUTH_TOKENS = [
{{template "KEY_ARRAY" "whitelisted_auth_tokens"}}
]
# SPOTIFY
SPOTIFY_CLIENT_ID = '''{{template "KEY" "spotify/client_id"}}'''
SPOTIFY_CLIENT_SECRET = '''{{template "KEY" "spotify/client_secret"}}'''
SPOTIFY_CALLBACK_URL = '''{{template "KEY" "spotify/redirect_uri"}}'''
# SPOTIFY METADATA CACHE
SPOTIFY_CACHE_CLIENT_ID = '''{{template "KEY" "spotify_cache/client_id"}}'''
SPOTIFY_CACHE_CLIENT_SECRET = '''{{template "KEY" "spotify_cache/client_secret"}}'''
# APPLE MUSIC
APPLE_MUSIC_TEAM_ID = '''{{template "KEY" "apple/team_id"}}'''
APPLE_MUSIC_KID = '''{{template "KEY" "apple/kid"}}'''
APPLE_MUSIC_KEY = '''{{template "KEY" "apple/key"}}'''
# CRITIQUEBRAINZ
CRITIQUEBRAINZ_CLIENT_ID = '''{{template "KEY" "critiquebrainz/client_id"}}'''
CRITIQUEBRAINZ_CLIENT_SECRET = '''{{template "KEY" "critiquebrainz/client_secret"}}'''
CRITIQUEBRAINZ_REDIRECT_URI = '''{{template "KEY" "critiquebrainz/redirect_uri"}}'''
# SOUNDCLOUD
SOUNDCLOUD_CLIENT_ID = '''{{template "KEY" "soundcloud/client_id"}}'''
SOUNDCLOUD_CLIENT_SECRET = '''{{template "KEY" "soundcloud/client_secret"}}'''
SOUNDCLOUD_REDIRECT_URI = '''{{template "KEY" "soundcloud/redirect_uri"}}'''
# YOUTUBE
YOUTUBE_API_KEY = '''{{template "KEY" "youtube/api_key"}}'''
SQLALCHEMY_TRACK_MODIFICATIONS = False
TESTING = False
{{if service "listenbrainz-org.exim-relay"}}
{{with index (service "listenbrainz-org.exim-relay") 0}}
SMTP_SERVER = '''{{.Address}}'''
SMTP_PORT = {{.Port}}
{{end}}
{{else}}
SMTP_SERVER = "SERVICEDOESNOTEXIST_listenbrainz-org.exim-relay"
SMTP_PORT = "SERVICEDOESNOTEXIST_listenbrainz-org.exim-relay"
{{end}}
MAIL_FROM_DOMAIN = '''{{template "KEY" "mail_from_domain"}}'''
SESSION_REMEMBER_ME_DURATION = 365
LISTEN_DUMP_TEMP_DIR_ROOT = '''{{template "KEY" "listen_dump_temp_dir"}}'''
# If set to True, reject listens from users who do not have an email
REJECT_LISTENS_WITHOUT_USER_EMAIL = {{template "KEY_JSON" "reject_listens_without_email"}}
# If set to True, do not allow new users without email to register and warn existing without email
REJECT_NEW_USERS_WITHOUT_EMAIL = {{template "KEY_JSON" "reject_new_users_without_email"}}