Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
nomad-lab
nomad-FAIR
Commits
c45fac1f
Commit
c45fac1f
authored
Jan 15, 2020
by
Markus Scheidgen
Browse files
Added username normalization script. [skip-ci]
parent
f0bdb9cb
Pipeline
#67118
skipped
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
nomad/infrastructure.py
View file @
c45fac1f
...
...
@@ -295,11 +295,11 @@ class Keycloak():
created
=
datetime
.
fromtimestamp
(
keycloak_user
[
'createdTimestamp'
]
/
1000
),
**
kwargs
)
def
search_user
(
self
,
query
:
str
=
None
,
**
kwargs
):
def
search_user
(
self
,
query
:
str
=
None
,
max
=
1000
,
**
kwargs
):
if
query
is
not
None
:
kwargs
[
'query'
]
=
dict
(
search
=
query
)
kwargs
[
'query'
]
=
dict
(
search
=
query
,
max
=
max
)
else
:
kwargs
[
'query'
]
=
dict
(
max
=
1000
)
kwargs
[
'query'
]
=
dict
(
max
=
max
)
try
:
keycloak_results
=
self
.
_admin_client
.
get_users
(
**
kwargs
)
except
Exception
as
e
:
...
...
ops/scripts/keycloak_create_usernames.py
0 → 100644
View file @
c45fac1f
import
re
import
unidecode
from
nomad
import
infrastructure
infrastructure
.
setup_logging
()
existing
=
set
()
for
user
in
infrastructure
.
keycloak
.
search_user
(
max
=
2000
):
if
not
re
.
match
(
r
'^[a-zA-Z0-9_\-\.]+$'
,
user
.
username
):
# need to replace username
if
user
.
first_name
is
not
None
and
user
.
last_name
is
not
None
:
user
.
username
=
'%s%s'
%
(
user
.
first_name
[:
1
],
user
.
last_name
)
elif
user
.
last_name
is
not
None
:
user
.
username
=
user
.
last_name
elif
'@'
in
user
.
username
:
user
.
username
=
user
.
username
.
split
(
'@'
)[
0
]
user
.
username
=
unidecode
.
unidecode
(
user
.
username
.
lower
())
user
.
username
=
re
.
sub
(
'[^0-9a-zA-Z_\-\.]+'
,
''
,
user
.
username
)
index
=
1
while
user
.
username
in
existing
:
user
.
username
+=
'%d'
%
index
index
+=
1
existing
.
add
(
user
.
username
)
infrastructure
.
keycloak
.
_admin_client
.
update_user
(
user_id
=
user
.
user_id
,
payload
=
dict
(
username
=
user
.
username
))
print
(
user
.
username
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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