Commit 116fa91f authored by Martin van Es's avatar Martin van Es
Browse files

Equalize variables between server and proxy

parent 7df4d4f5
......@@ -87,31 +87,31 @@ def serve_all(realm):
@app.route('/<realm>/entities/<path:eid>',
methods=['GET'])
def serve_one(realm, eid):
entityID = unquote(eid)
if entityID[:6] == "{sha1}":
entityID = entityID[6:]
entity = unquote(eid)
if entity[:6] == "{sha1}":
sha1 = entity[6:]
else:
entityID = hasher(entityID)
sha1 = hasher(entity)
response = Response()
response.headers['Content-Type'] = "application/samlmetadata+xml"
response.headers['Content-Disposition'] = "filename = \"metadata.xml\""
cached[realm] = cached.get(realm, {})
if entityID in cached[realm]:
if cached[realm][entityID].expires > datetime.now(tz.tzutc()):
print(f"cache {entityID}")
max_age = int((cached[realm][entityID].expires -
if sha1 in cached[realm]:
if cached[realm][sha1].expires > datetime.now(tz.tzutc()):
print(f"cache {sha1}")
max_age = int((cached[realm][sha1].expires -
datetime.now(tz.tzutc())).total_seconds())
last_modified = cached[realm][entityID].last_modified
last_modified = cached[realm][sha1].last_modified
response.headers['Cache-Control'] = f"max-age={max_age}"
response.headers['Last-Modified'] = last_modified
response.data = cached[realm][entityID].md
response.data = cached[realm][sha1].md
return response
print(f"request {entityID}")
print(f"request {sha1}")
request = requests.get(f"{config[realm]['signer']}/{realm}"
f"/entities/{{sha1}}{entityID}")
f"/entities/{{sha1}}{sha1}")
data = request.text
last_modified = request.headers.get('Last-Modified',
formatdate(timeval=None,
......@@ -130,12 +130,13 @@ def serve_one(realm, eid):
cached_entity.valid_until)
cached_entity.last_modified = last_modified
if cached_entity.expires > datetime.now(tz.tzutc()):
cached[realm][entityID] = cached_entity
cached[realm][sha1] = cached_entity
max_age = int((cached_entity.expires -
datetime.now(tz.tzutc())).total_seconds())
else:
raise KeyError
except Exception:
except KeyError as e:
print(f" {sha1} {e}")
data = "No valid metadata\n"
max_age = 60
response.headers['Content-type'] = "text/html"
......
......@@ -182,9 +182,8 @@ class Realm:
data.md = signed_xml
else:
raise KeyError
except Exception as e:
print(sha1)
print(f" {e}")
except KeyError as e:
print(f" {sha1} {e}")
data.max_age = int((signed_entity.expires -
datetime.now(tz.tzutc())).total_seconds())
......
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