Commit c791278b authored by Martin van Es's avatar Martin van Es
Browse files

Add cache duration and load xml file on start

parent 40da18c2
......@@ -8,6 +8,7 @@ from flask import Flask
from urllib.parse import unquote
from dateutil import parser, tz
from datetime import datetime
from isoduration import parse_duration
import traceback
from utils import hasher, signer, Entity
......@@ -73,6 +74,7 @@ def read_metadata(signum, frm):
validUntil = root.get('validUntil')
cacheDuration = root.get('cacheDuration')
valid_until = parser.isoparse(validUntil)
cache_duration = parse_duration(cacheDuration)
if valid_until > datetime.now(tz.tzutc()):
for entity_descriptor in root.findall('md:EntityDescriptor', ns):
entityID = entity_descriptor.attrib.get('entityID', 'none')
......@@ -83,6 +85,7 @@ def read_metadata(signum, frm):
entity = Entity()
entity.md = entity_descriptor
entity.valid_until = valid_until
entity.cache_duration = cache_duration
idps[sha1] = entity
old_idps.pop(sha1, None)
# signed.pop(sha1, None)
......@@ -96,6 +99,9 @@ def read_metadata(signum, frm):
print(f"Removed: {removed} entities")
print(f"validUntil: {validUntil}")
signal.signal(signal.SIGHUP, read_metadata)
app.run(host='0.0.0.0', port=5001)
read_metadata(None, None)
app.run(host='127.0.0.1', port=5001)
[Unit]
Description=MDServer
After=syslog.target network.target
[Service]
Type=simple
WorkingDirectory=/opt/alternate-mdx
ExecStart=/opt/alternate-mdx/bin/python -u mdserver.py md.xml
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=10
SyslogIdentifier=mdserver
[Install]
WantedBy=multi-user.target
......@@ -5,6 +5,7 @@ from signxml import XMLSigner
class Entity(object):
md = None
valid_until = 0
cache_duration = 0
def hasher(entity_id):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment