bundlewrap/bundles/infobeamer-cms/metadata.py

69 lines
2 KiB
Python
Raw Normal View History

from datetime import datetime, timedelta, timezone
2022-03-20 11:35:00 +00:00
assert node.has_bundle('redis')
2021-12-23 12:48:44 +00:00
defaults = {
'infobeamer-cms': {
'config': {
'MAX_UPLOADS': 5,
2022-03-20 11:35:00 +00:00
'PREFERRED_URL_SCHEME': 'https',
'REDIS_HOST': '127.0.0.1',
2022-03-20 11:35:00 +00:00
'SESSION_COOKIE_NAME': '__Host-sess',
'STATIC_PATH': '/opt/infobeamer-cms/static',
2021-12-23 18:36:50 +00:00
'URL_KEY': repo.vault.password_for(f'{node.name} infobeamer-cms url key'),
2021-12-23 12:48:44 +00:00
'VERSION': 1,
},
'workers': 4,
2021-12-23 12:48:44 +00:00
},
}
@metadata_reactor.provides(
'nginx/vhosts',
)
def nginx(metadata):
if not node.has_bundle('nginx'):
raise DoNotRunAgain
return {
'nginx': {
'vhosts': {
'infobeamer-cms': {
'domain': node.metadata.get('infobeamer-cms/domain'),
'locations': {
'/': {
'target': 'http://127.0.0.1:8000',
},
'/static': {
'alias': '/opt/infobeamer-cms/static',
},
},
'website_check_path': '/',
'website_check_string': 'Share your projects',
'do_not_set_content_security_headers': True,
},
},
2021-12-23 12:48:44 +00:00
},
}
2022-03-20 11:35:00 +00:00
@metadata_reactor.provides(
'infobeamer-cms/config/DOMAIN',
2022-03-20 11:35:00 +00:00
'infobeamer-cms/config/TIME_MAX',
'infobeamer-cms/config/TIME_MIN',
)
def event_times(metadata):
event_start = datetime.strptime(metadata.get('infobeamer-cms/event_start_date'), '%Y-%m-%d').replace(tzinfo=timezone.utc)
2022-03-20 11:35:00 +00:00
event_duration = metadata.get('infobeamer-cms/event_duration_days', 4)
event_end = event_start + timedelta(days=event_duration)
return {
'infobeamer-cms': {
'config': {
'DOMAIN': metadata.get('infobeamer-cms/domain'),
2022-03-20 11:35:00 +00:00
'TIME_MAX': int(event_end.timestamp()),
'TIME_MIN': int(event_start.timestamp()),
},
},
}