Users

Use User objects to manipulate repository branches.

To create User objects use the gitlab.Gitlab.users manager.

Examples

Get the list of users:

users = gl.users.list()

Search users whose username match the given string:

users = gl.users.list(search='oo')

Get a single user:

# by ID
user = gl.users.get(2)
# by username
user = gl.users.list(username='root')[0]

Create a user:

user = gl.users.create({'email': 'john@doe.com',
                        'password': 's3cur3s3cr3T',
                        'username': 'jdoe',
                        'name': 'John Doe'})

Update a user:

user.name = 'Real Name'
user.save()

Delete a user:

gl.users.delete(2)
user.delete()

Block/Unblock a user:

user.block()
user.unblock()

SSH keys

Use the UserKey objects to manage user keys.

To create UserKey objects use the User.keys or gitlab.Gitlab.user_keys managers.

Exemples

List SSH keys for a user:

keys = gl.user_keys.list(user_id=1)
# or
keys = user.keys.list()

Get an SSH key for a user:

key = gl.user_keys.list(1, user_id=1)
# or
key = user.keys.get(1)

Create an SSH key for a user:

k = gl.user_keys.create({'title': 'my_key',
                         'key': open('/home/me/.ssh/id_rsa.pub').read()},
                        user_id=2)
# or
k = user.keys.create({'title': 'my_key',
                      'key': open('/home/me/.ssh/id_rsa.pub').read()})

Delete an SSH key for a user:

gl.user_keys.delete(1, user_id=1)
# or
user.keys.delete(1)
# or
key.delete()

Emails

Use the UserEmail objects to manage user emails.

To create UserEmail objects use the User.emails or gitlab.Gitlab.user_emails managers.

Exemples

List emails for a user:

emails = gl.user_emails.list(user_id=1)
# or
emails = user.emails.list()

Get an email for a user:

email = gl.user_emails.list(1, user_id=1)
# or
email = user.emails.get(1)

Create an email for a user:

k = gl.user_emails.create({'email': 'foo@bar.com'}, user_id=2)
# or
k = user.emails.create({'email': 'foo@bar.com'})

Delete an email for a user:

gl.user_emails.delete(1, user_id=1)
# or
user.emails.delete(1)
# or
email.delete()

Current User

Use the CurrentUser object to get information about the currently logged-in user.

Use the CurrentUserKey objects to manage user keys.

To create CurrentUserKey objects use the gitlab.objects.CurrentUser.keys manager.

Use the CurrentUserEmail objects to manage user emails.

To create CurrentUserEmail objects use the gitlab.objects.CurrentUser.emails manager.

Examples

Get the current user:

gl.auth()
current_user = gl.user

List the current user SSH keys:

keys = gl.user.keys.list()

Get a key for the current user:

key = gl.user.keys.get(1)

Create a key for the current user:

key = gl.user.keys.create({'id': 'my_key', 'key': key_content})

Delete a key for the current user:

gl.user.keys.delete(1)
# or
key.delete()

List the current user emails:

emails = gl.user.emails.list()

Get an email for the current user:

email = gl.user.emails.get(1)

Create an email for the current user:

email = gl.user.emails.create({'email': 'foo@bar.com'})

Delete an email for the current user:

gl.user.emails.delete(1)
# or
email.delete()