Commit 2e136f4d authored by Jonathan Schaeffer's avatar Jonathan Schaeffer

Merge branch 'fix_enddate' into 'master'

Fix enddate

See merge request resif/ws-eidaauth!3
parents 2c2065e6 8d27076d
......@@ -92,7 +92,7 @@ What does this program do ?
4. Register this in the resifAuth database, along with the `expires_at` value (24h)
5. From the `member-of` field in the token :
- do the mapping from EPOS names to FDSN reference from the epos_fdsn table in the resifAuth database
the FDSN reference is the network name, startyear
the FDSN reference is the network name, startyear, endyear
- register the login along with the FDSN references and the expiration date in the resifInv-Prod database, table `access`
6. Return the `login:password` to the client
......
import os
class default():
class config():
"""
Default conifguration
"""
......@@ -26,5 +26,5 @@ class default():
PRIVILEGEDBPASSWORD=_dbpassword
EPOS_FDSN_MAP={
'/epos/alparray': {'networkcode':'Z3', 'startyear':2015},
'/epos/alparray': {'networkcode':'Z3', 'startyear':2015, 'endyear': 2022},
}
......@@ -124,19 +124,21 @@ def register_privileges(login, fdsn_refs):
ref['login'] = login
ref['expires_at'] = datetime.datetime.now()+datetime.timedelta(days=1)
logging.info(ref)
sql_request = "select network_id from networks where start_year=%(startyear)s and network=%(networkcode)s"
sql_request = "select network_id from networks where start_year=%(startyear)s and end_year=%(endyear)s and network=%(networkcode)s"
try:
cur.execute(sql_request, ref)
except psycopg2.Error as e:
logging.error(e.pgerror)
else:
if cur.rowcount != 1:
logging.info(cur.mogrify(sql_request, ref))
logging.error("No network found for %s", ref)
logging.error("%d networks found for %s", cur.rowcount, ref)
raise NameError(f"{cur.rowcount} networks found for {ref}")
ref['networkid'] = cur.fetchone()[0]
logging.info("Inserting tupple in %s.eida_temp_users: %s", application.config['PRIVILEGEDBNAME'], ref)
cur.execute("""
insert into eida_temp_users (network_id, network, start_year, name, expires_at) values (%(networkid)s, %(networkcode)s, %(startyear)s, %(login)s, %(expires_at)s);
insert into eida_temp_users (network_id, network, start_year, end_year, name, expires_at) values (%(networkid)s, %(networkcode)s, %(startyear)s, %(endyear)s, %(login)s, %(expires_at)s);
""", ref)
except psycopg2.Error as e:
logging.error(e.pgerror)
conn.commit()
conn.close()
......@@ -205,7 +207,7 @@ def auth():
expiration_ts= datetime.datetime.strptime(tokendict['valid_until'], '%Y-%m-%dT%H:%M:%S.%fZ')
if (expiration_ts - datetime.datetime.now()).total_seconds() < 0:
logging.info("Token is expired")
return Response('Token is expired. Please generate a new one at https://geofon.gfz-potsdam.de/eas/', status=415)
return Response('Token is expired. Please generate a new one at https://geofon.gfz-potsdam.de/eas/', status=400)
logging.info("Token is valid")
# Compute a random login and password
......@@ -226,7 +228,10 @@ def auth():
if len(fdsn_memberships) > 0:
logging.debug("FDSN memberships: %s"%(fdsn_memberships))
register_privileges(login, fdsn_memberships)
try:
register_privileges(login, fdsn_memberships)
except NameError as n:
return "Internal error at RESIF. Please contact resif-dc@univ-grenoble-alpes.fr specifying the URL"
return "%s:%s"%(login, password)
......
__version__='0.4.2'
__version__='0.4.0'
-i https://pypi.org/simple
click==7.1.1
Flask==1.1.1
flask==1.1.1
itsdangerous==1.1.0
Jinja2==2.11.1
MarkupSafe==1.1.1
psycopg2-binary
jinja2==2.11.1
markupsafe==1.1.1
psycopg2-binary==2.8.5
python-gnupg==0.4.5
Werkzeug==1.0.0
werkzeug==1.0.0
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