Skip to content

Commit 3711f19

Browse files
author
Gauvain Pocentek
committed
Add sudo support
1 parent c579c80 commit 3711f19

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

docs/api-usage.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,13 @@ Use the ``all`` parameter to get all the items:
117117
.. code-block:: python
118118
119119
all_groups = gl.groups.list(all=True)
120+
121+
Sudo
122+
====
123+
124+
If you have the administrator status, you can use ``sudo`` to act as another
125+
user. For example:
126+
127+
.. code-block:: python
128+
129+
p = gl.projects.create({'name': 'awesome_project'}, sudo='user1')

docs/cli.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,9 @@ Define the status of a commit (as would be done from a CI tool for example):
189189
--commit-id a43290c --state success --name ci/jenkins \
190190
--target-url http://server/build/123 \
191191
--description "Jenkins build succeeded"
192+
193+
Use sudo to act as another user (admin only):
194+
195+
.. code-block:: console
196+
197+
$ gitlab project create --name user_project1 --sudo username

gitlab/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def _populate_sub_parser_by_class(cls, sub_parser):
7373
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),
7474
required=True)
7575
for x in cls.requiredUrlAttrs]
76+
sub_parser_action.add_argument("--sudo", required=False)
7677

7778
if action_name == LIST:
7879
[sub_parser_action.add_argument("--%s" % x.replace('_', '-'),

gitlab/objects.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def _data_for_gitlab(self, extra_parameters={}, update=False):
227227
else:
228228
attributes = itertools.chain(self.requiredCreateAttrs,
229229
self.optionalCreateAttrs)
230+
attributes = list(attributes) + ['sudo', 'page', 'per_page']
230231
for attribute in attributes:
231232
if hasattr(self, attribute):
232233
data[attribute] = getattr(self, attribute)

tools/python_test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@
9898
'namespace_id': group1.id})
9999
gr2_project = gl.projects.create({'name': 'gr2_project',
100100
'namespace_id': group2.id})
101+
sudo_project = gl.projects.create({'name': 'sudo_project'}, sudo=user1.name)
101102

102-
assert(len(gl.projects.all()) == 3)
103+
assert(len(gl.projects.all()) == 4)
103104
assert(len(gl.projects.owned()) == 2)
104105
assert(len(gl.projects.search("admin")) == 1)
105106

0 commit comments

Comments
 (0)