Commit 0de255b0 authored by Jonathan Schaeffer's avatar Jonathan Schaeffer

Uniform expiration column names

parent f39a0033
......@@ -45,28 +45,18 @@ alter table users add column if not exists expires_at timestamp default value nu
```
Table `credentials` :
No modification to the resifAuth schema
``` sql
alter table credentials add column if not exists expires_at timestamp default value null;
```
#### PRIVILEDGEDB
Table `aut_user`.
No modification to the resifInv-Prod schema.
#### PRIVILEDGEDB
Table `eida_temp_users` :
``` sql
Colonne | Type | Collationnement | NULL-able | Par défaut | Stockage |
------------+---------+-----------------+-----------+-------------------------------------------+----------+
user_id | integer | | not null | nextval('aut_user_user_id_seq'::regclass) | plain |
network_id | bigint | | | 0 | plain |
network | text | | not null | | extended |
start_year | integer | | not null | 0 | plain |
end_year | integer | | not null | 0 | plain |
name | text | | not null | | extended |
Index :
"aut_user_pkey" PRIMARY KEY, btree (user_id)
"uniq_aut_user" UNIQUE CONSTRAINT, btree (network, start_year, end_year, name)
Contraintes de clés étrangères :
"aut_user_network_id_fkey" FOREIGN KEY (network_id) REFERENCES networks(network_id) ON DELETE SET DEFAULT
alter table aut_user add column if not exists expires_at timestamp default value null;
```
## Playing around
After the Database initialisation, the application can be run in a virtual environment.
......
......@@ -82,15 +82,15 @@ def register_login(login, password):
raise e
cur.execute("""
INSERT INTO users VALUES (DEFAULT, %(login)s, 'Temp', 'EIDA', %(tmpmail)s, %(expiration)s);
INSERT INTO users VALUES (DEFAULT, %(login)s, 'Temp', 'EIDA', %(tmpmail)s, %(expires_at)s);
""",
{'login': login, 'tmpmail': "%s@eida"%(login),'expiration': expiration_time }
{'login': login, 'tmpmail': "%s@eida"%(login),'expires_at': expiration_time }
)
cur.execute("""
INSERT INTO credentials VALUES (CURRVAL('users_user_index_seq'), NULL, %(wsshash)s, %(expiration)s);
INSERT INTO credentials VALUES (CURRVAL('users_user_index_seq'), NULL, %(wsshash)s, %(expires_at)s);
""",
{'wsshash': wsshash(login, password), 'expiration': expiration_time }
{'wsshash': wsshash(login, password), 'expires_at': expiration_time }
)
conn.commit()
conn.close()
......@@ -118,14 +118,14 @@ def register_privileges(login, fdsn_refs):
# Get the network id
for ref in fdsn_refs:
ref['login'] = login
ref['expiration'] = datetime.datetime.now()+datetime.timedelta(days=1)
ref['expires_at'] = datetime.datetime.now()+datetime.timedelta(days=1)
cur.execute("""
select network_id from networks where start_year=%(startyear)s and end_year=%(endyear)s and network=%(networkcode)s;
""", 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, expiration) values (%(networkid)s, %(networkcode)s, %(startyear)s, %(endyear)s, %(login)s, %(expiration)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)
conn.commit()
conn.close()
......@@ -150,7 +150,7 @@ def cleanup():
password = application.config['AUTHDBPASSWORD'])
cur = conn.cursor()
logging.debug("Connected to users database")
cur.execute("delete from credentials where expiration < now();")
cur.execute("delete from credentials where expires_at < now();")
cur.execute("delete from users where expires_at < now();")
rows_deleted = cur.rowcount
conn.commit()
......@@ -171,7 +171,7 @@ def cleanup():
cur = conn.cursor()
logging.debug("Connected to privlieges database")
logging.debug("Deleting from privileges database: %s", old_users)
cur.execute("delete from eida_temp_users where expiration < now();")
cur.execute("delete from eida_temp_users where expires_at < now();")
conn.commit()
conn.close()
except Exception as e:
......
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