summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGauvain Pocentek <gauvain.pocentek@objectif-libre.com>2016-01-30 16:38:16 +0100
committerGauvain Pocentek <gauvain.pocentek@objectif-libre.com>2016-01-30 16:38:16 +0100
commit3711f198a4e02144d9d49b68420d24afc9f4f957 (patch)
treead6edd6bf91ac4196912ba3aecc59ce5b5a1bbbb
parentc579c8081af787945c24c75b9ed85b2f0d8bc6b9 (diff)
downloadgitlab-3711f198a4e02144d9d49b68420d24afc9f4f957.tar.gz
Add sudo support
-rw-r--r--docs/api-usage.rst10
-rw-r--r--docs/cli.rst6
-rw-r--r--gitlab/cli.py1
-rw-r--r--gitlab/objects.py1
-rw-r--r--tools/python_test.py3
5 files changed, 20 insertions, 1 deletions
diff --git a/docs/api-usage.rst b/docs/api-usage.rst
index 85e4b1f..b6a498d 100644
--- a/docs/api-usage.rst
+++ b/docs/api-usage.rst
@@ -117,3 +117,13 @@ Use the ``all`` parameter to get all the items:
.. code-block:: python
all_groups = gl.groups.list(all=True)
+
+Sudo
+====
+
+If you have the administrator status, you can use ``sudo`` to act as another
+user. For example:
+
+.. code-block:: python
+
+ p = gl.projects.create({'name': 'awesome_project'}, sudo='user1')
diff --git a/docs/cli.rst b/docs/cli.rst
index 2d150e6..53ef83f 100644
--- a/docs/cli.rst
+++ b/docs/cli.rst
@@ -189,3 +189,9 @@ Define the status of a commit (as would be done from a CI tool for example):
--commit-id a43290c --state success --name ci/jenkins \
--target-url http://server/build/123 \
--description "Jenkins build succeeded"
+
+Use sudo to act as another user (admin only):
+
+.. code-block:: console
+
+ $ gitlab project create --name user_project1 --sudo username
diff --git a/gitlab/cli.py b/gitlab/cli.py
index 8ac8e45..7843423 100644
--- a/gitlab/cli.py
+++ b/gitlab/cli.py
@@ -73,6 +73,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
required=True)
for x in cls.requiredUrlAttrs]
+ sub_parser_action.add_argument("--sudo", required=False)
if action_name == LIST:
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
diff --git a/gitlab/objects.py b/gitlab/objects.py
index a7105d2..28530a0 100644
--- a/gitlab/objects.py
+++ b/gitlab/objects.py
@@ -227,6 +227,7 @@ class GitlabObject(object):
else:
attributes = itertools.chain(self.requiredCreateAttrs,
self.optionalCreateAttrs)
+ attributes = list(attributes) + ['sudo', 'page', 'per_page']
for attribute in attributes:
if hasattr(self, attribute):
data[attribute] = getattr(self, attribute)
diff --git a/tools/python_test.py b/tools/python_test.py
index 5292ed9..fd93f89 100644
--- a/tools/python_test.py
+++ b/tools/python_test.py
@@ -98,8 +98,9 @@ gr1_project = gl.projects.create({'name': 'gr1_project',
'namespace_id': group1.id})
gr2_project = gl.projects.create({'name': 'gr2_project',
'namespace_id': group2.id})
+sudo_project = gl.projects.create({'name': 'sudo_project'}, sudo=user1.name)
-assert(len(gl.projects.all()) == 3)
+assert(len(gl.projects.all()) == 4)
assert(len(gl.projects.owned()) == 2)
assert(len(gl.projects.search("admin")) == 1)