Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OSUG
RESIF
ws-eidaauth
Commits
e43b852e
Commit
e43b852e
authored
Jun 16, 2021
by
Jonathan Schaeffer
Browse files
Change users'table name (resif_users)
parent
620e73e6
Pipeline
#69149
passed with stage
in 1 minute and 24 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
eidawsauth/eidawsauth.py
View file @
e43b852e
...
@@ -55,19 +55,19 @@ def register_privileges(login, tokendict):
...
@@ -55,19 +55,19 @@ def register_privileges(login, tokendict):
- Connect to PRIVILEGEDB
- Connect to PRIVILEGEDB
- For each fdsn reference, insert the privilege in the access table if not already there
- For each fdsn reference, insert the privilege in the access table if not already there
"""
"""
fdsn_membership
s
=
[]
authorization
s
=
[]
for
em
in
tokendict
[
'memberof'
].
split
(
';'
):
for
em
in
tokendict
[
'memberof'
].
split
(
';'
):
application
.
logger
.
debug
(
"EPOS membership: "
+
em
)
application
.
logger
.
debug
(
"EPOS membership: "
+
em
)
if
em
in
application
.
config
[
'EPOS_FDSN_MAP'
]:
if
em
in
application
.
config
[
'EPOS_FDSN_MAP'
]:
application
.
logger
.
debug
(
" ... is in epos fdsn map"
)
application
.
logger
.
debug
(
" ... is in epos fdsn map"
)
fdsn_membership
s
.
append
(
application
.
config
[
'EPOS_FDSN_MAP'
][
em
])
authorization
s
.
append
(
application
.
config
[
'EPOS_FDSN_MAP'
][
em
])
#
TODO
Now get localy defined autorizations, from email adress
# Now get localy defined autorizations, from email adress
# 1. Chercher tous les users ayant cet email dans la table resifAuth.users
# 1. Chercher tous les users ayant cet email dans la table resifAuth.users
# select login from users where email = '' and expires_at is NULL
# select login from users where email = '' and expires_at is NULL
# 2. Pour chaque login récupéré, prendre la liste des réseaux autorisés dans resifInv
# 2. Pour chaque login récupéré, prendre la liste des réseaux autorisés dans resifInv
# select network_id, network, start_year, end_year from
aut
_user where name=%(login)s
# select network_id, network, start_year, end_year from
resif
_user
s
where name=%(login)s
# Ajouter ces tuples à
fdsn_
membership pour que les autorisations soient accordées à cet utilisateur
# Ajouter ces tuples à membership pour que les autorisations soient accordées à cet utilisateur
#
#
#
#
# Step 1 :
# Step 1 :
...
@@ -85,7 +85,7 @@ def register_privileges(login, tokendict):
...
@@ -85,7 +85,7 @@ def register_privileges(login, tokendict):
permanent_logins
.
append
(
l
[
0
])
permanent_logins
.
append
(
l
[
0
])
# Step 2
# Step 2
# Maintenant, on enregistre les
membership
s
# Maintenant, on enregistre les
authorization
s
try
:
try
:
conn
=
psycopg2
.
connect
(
dbname
=
application
.
config
[
'RESIFINV_PGDATABASE'
],
conn
=
psycopg2
.
connect
(
dbname
=
application
.
config
[
'RESIFINV_PGDATABASE'
],
port
=
application
.
config
[
'RESIFINV_PGPORT'
],
port
=
application
.
config
[
'RESIFINV_PGPORT'
],
...
@@ -103,16 +103,16 @@ def register_privileges(login, tokendict):
...
@@ -103,16 +103,16 @@ def register_privileges(login, tokendict):
for
l
in
permanent_logins
:
for
l
in
permanent_logins
:
application
.
logger
.
debug
(
"Searching for privileges on login %s"
,
l
)
application
.
logger
.
debug
(
"Searching for privileges on login %s"
,
l
)
cur
.
execute
(
"select network_id, network, start_year, end_year from
aut
_user where name=%s"
,
(
l
,))
cur
.
execute
(
"select network_id, network, start_year, end_year from
resif
_user
s
where name=%s"
,
(
l
,))
for
ref
in
cur
:
for
ref
in
cur
:
fdsn_membership
s
.
append
({
'networkid'
:
ref
[
0
],
'networkcode'
:
ref
[
1
],
'startyear'
:
ref
[
2
],
'endyear'
:
ref
[
3
]
})
authorization
s
.
append
({
'networkid'
:
ref
[
0
],
'networkcode'
:
ref
[
1
],
'startyear'
:
ref
[
2
],
'endyear'
:
ref
[
3
]
})
if
len
(
fdsn_membership
s
)
==
0
:
if
len
(
authorization
s
)
==
0
:
application
.
logger
.
debug
(
"No membership for user %s"
,
login
)
application
.
logger
.
debug
(
"No membership for user %s"
,
login
)
return
return
application
.
logger
.
debug
(
"FDSN
memberships: %s"
%
(
fdsn_membership
s
))
application
.
logger
.
debug
(
"FDSN
authorizations: %s"
%
(
authorization
s
))
# Get the network id
# Get the network id
for
ref
in
fdsn_membership
s
:
for
ref
in
authorization
s
:
ref
[
'login'
]
=
login
ref
[
'login'
]
=
login
ref
[
'expires_at'
]
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
days
=
1
)
ref
[
'expires_at'
]
=
datetime
.
datetime
.
now
()
+
datetime
.
timedelta
(
days
=
1
)
application
.
logger
.
info
(
ref
)
application
.
logger
.
info
(
ref
)
...
@@ -129,7 +129,9 @@ def register_privileges(login, tokendict):
...
@@ -129,7 +129,9 @@ def register_privileges(login, tokendict):
ref
[
'networkid'
]
=
cur
.
fetchone
()[
0
]
ref
[
'networkid'
]
=
cur
.
fetchone
()[
0
]
application
.
logger
.
info
(
"Inserting tupple in %s.eida_temp_users: %s"
,
application
.
config
[
'RESIFINV_PGDATABASE'
],
ref
)
application
.
logger
.
info
(
"Inserting tupple in %s.eida_temp_users: %s"
,
application
.
config
[
'RESIFINV_PGDATABASE'
],
ref
)
cur
.
execute
(
"""
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) ON CONFLICT DO NOTHING;
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)
ON CONFLICT DO NOTHING;
"""
,
ref
)
"""
,
ref
)
conn
.
commit
()
conn
.
commit
()
conn
.
close
()
conn
.
close
()
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment