[sysadmin-bin] Make use of the python-gitlab API, rename sync-ssh-keys to gitlab-operations as we'll be landing cod
- From: Andrea Veri <av src gnome org>
- To: gnome-sysadmin gnome org,commits-list gnome org
- Subject: [sysadmin-bin] Make use of the python-gitlab API, rename sync-ssh-keys to gitlab-operations as we'll be landing cod
- Date: Fri, 27 Oct 2017 17:20:17 +0000 (UTC)
commit 7bf524e3f8387cdfc1c44a80a98abfc179da493e
Author: Andrea Veri <averi redhat com>
Date: Fri Oct 27 19:11:57 2017 +0200
Make use of the python-gitlab API, rename sync-ssh-keys to gitlab-operations as we'll be landing code to
deal with multiple other gitlab related tasks
gitlab/gitlab-operations.py | 30 ++++++++++++++
gitlab/gitlab.py | 93 -------------------------------------------
gitlab/sync-ssh-keys.py | 22 ----------
3 files changed, 30 insertions(+), 115 deletions(-)
---
diff --git a/gitlab/gitlab-operations.py b/gitlab/gitlab-operations.py
new file mode 100755
index 0000000..e578020
--- /dev/null
+++ b/gitlab/gitlab-operations.py
@@ -0,0 +1,30 @@
+#!/usr/bin/python
+
+import sys
+import gitlab
+
+sys.path.append('/home/admin/bin')
+from gnome_ldap_utils import *
+
+execfile('/home/admin/secret/freeipa')
+
+glu = Gnome_ldap_utils(LDAP_GROUP_BASE, LDAP_HOST, LDAP_USER_BASE, 'cn=Directory Manager', ldap_password)
+gl = gitlab.Gitlab('https://gitlab.gnome.org', GITLAB_PRIVATE_TOKEN, api_version=4)
+
+ldapusers = gl.users.list(all=True)
+ldapusers_dict = {}
+
+for user in ldapusers:
+ for index, _ in enumerate(user.attributes['identities']):
+ if user.attributes['identities'][index]['provider'] == 'ldapmain':
+ ldapusers_dict[user.attributes['id']] =
user.attributes['identities'][index]['extern_uid'].split(',')[0].replace('uid=', '')
+
+for id, username in ldapusers_dict.iteritems():
+ ssh_key = glu.get_attributes_from_ldap(username, 'ipaSshPubKey')
+ user = gl.users.get(id)
+ try:
+ user.keys.create({'title': 'Imported from account.gnome.org', 'key': ssh_key})
+
+ print 'Key for username with id %i has been added' % id
+ except gitlab.exceptions.GitlabCreateError:
+ pass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]