Skip to content

Instantly share code, notes, and snippets.

@xiaopeng163
Created January 13, 2017 06:29
Show Gist options
  • Save xiaopeng163/2e6e4d07c00709da6d6e066317b9bd5b to your computer and use it in GitHub Desktop.
Save xiaopeng163/2e6e4d07c00709da6d6e066317b9bd5b to your computer and use it in GitHub Desktop.
# Copyright 2016 Cisco Systems, Inc.
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import gitlab
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def get_all_users(gl):
"""
get all users
"""
users = gl.users.list(all=True)
user_dict = dict()
for user in users:
user_dict[user.id] = dict(
username=user.username,
email=user.email,
name=user.name)
return user_dict
def get_all_groups(gl):
groups = gl.groups.list(all=True)
group_dict = dict()
for group in groups:
group_dict[group.id] = dict(
web_url=group.web_url,
visibility_level=group.visibility_level,
description=group.description,
name=group.name)
member_dict = dict()
for mem in group.members.list():
member_dict[mem.id] = dict(access_level=mem.access_level)
group_dict[group.id]['members'] = member_dict
project_dict = dict()
for project in group.projects.list():
print project
return group_dict
def main():
gl = gitlab.Gitlab(os.environ.get('GITLAB_URL'), os.environ.get('GITLAB_TOKEN'), ssl_verify=False)
gl.auth()
get_all_users(gl)
get_all_groups(gl)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment