[sysadmin-bin] Land a fetch-username script to be able to parse the GL_USERNAME env variable and fetch the username
- From: Andrea Veri <av src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Land a fetch-username script to be able to parse the GL_USERNAME env variable and fetch the username
- Date: Fri, 10 Nov 2017 13:04:38 +0000 (UTC)
commit ab1a80d91f986371514c36bff28293f78544f902
Author: Andrea Veri <averi redhat com>
Date: Fri Nov 10 14:03:25 2017 +0100
Land a fetch-username script to be able to parse the GL_USERNAME env variable and fetch the username
accordingly, either from LDAP or if missing from the username user attribute
gitlab/fetch-username.py | 31 +++++++++++++++++++++++++++++++
1 files changed, 31 insertions(+), 0 deletions(-)
---
diff --git a/gitlab/fetch-username.py b/gitlab/fetch-username.py
new file mode 100755
index 0000000..c327a4a
--- /dev/null
+++ b/gitlab/fetch-username.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+
+import gitlab
+import os
+
+execfile('/home/admin/secret/gitlab_ro')
+
+gl = gitlab.Gitlab('https://gitlab.gnome.org', GITLAB_PRIVATE_RO_TOKEN, api_version=4)
+
+def fetch_username():
+
+ user = os.environ['GL_USERNAME']
+ user = gl.users.list(username='%s' % user)
+ user = user[0]
+
+ identity_found = False
+ if len(user.attributes['identities']) > 0:
+ for index, _ in enumerate(user.attributes['identities']):
+ provider = user.attributes['identities'][index]['provider']
+ if provider not in ('google_oauth2', 'github'):
+ username = user.attributes['identities'][index]['extern_uid'].split(',')[0].replace('uid=', '')
+
+ identity_found = True
+ if not identity_found:
+ username = user.attributes['username']
+ else:
+ username = user.attributes['username']
+
+ print username
+
+fetch_username()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]