Commit 64eaa802 authored by Jonathan Schaeffer's avatar Jonathan Schaeffer

Better management of network mapping

From EPOS name to resifInv internal ID
parent e4510718
......@@ -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, 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()
......@@ -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)
......
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