Skip to content

Commit 4e12356

Browse files
committed
feat(api): add support for GitLab OAuth Applications API
1 parent f071390 commit 4e12356

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

docs/api-objects.rst

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ API examples
77

88
gl_objects/access_requests
99
gl_objects/appearance
10+
gl_objects/applications
1011
gl_objects/emojis
1112
gl_objects/badges
1213
gl_objects/branches

docs/gl_objects/applications.rst

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
############
2+
Applications
3+
############
4+
5+
Reference
6+
---------
7+
8+
* v4 API:
9+
10+
+ :class:`gitlab.v4.objects.Applications`
11+
+ :class:`gitlab.v4.objects.ApplicationManager`
12+
+ :attr:`gitlab.Gitlab.applications`
13+
14+
* GitLab API: https://docs.gitlab.com/ce/api/applications.html
15+
16+
Examples
17+
--------
18+
19+
List all OAuth applications::
20+
21+
applications = gl.applications.list()
22+
23+
Create an application::
24+
25+
gl.applications.create({'name': 'your_app', 'redirect_uri': 'http://application.url', 'scopes': ['api']})
26+
27+
Delete an applications::
28+
29+
gl.applications.delete(app_id)
30+
# or
31+
application.delete()

gitlab/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ def __init__(
144144
self.features = objects.FeatureManager(self)
145145
self.pagesdomains = objects.PagesDomainManager(self)
146146
self.user_activities = objects.UserActivitiesManager(self)
147+
self.applications = objects.ApplicationManager(self)
147148

148149
def __enter__(self):
149150
return self

gitlab/tests/test_gitlab.py

+27
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,33 @@ def resp_import_github(url, request):
964964
self.assertEqual(ret["full_path"], "/".join((base_path, name)))
965965
self.assertTrue(ret["full_name"].endswith(name))
966966

967+
def test_applications(self):
968+
content = '{"name": "test_app", "redirect_uri": "http://localhost:8080", "scopes": ["api", "email"]}'
969+
json_content = json.loads(content)
970+
971+
@urlmatch(
972+
scheme="http",
973+
netloc="localhost",
974+
path="/api/v4/applications",
975+
method="post",
976+
)
977+
def resp_application_create(url, request):
978+
headers = {"content-type": "application/json"}
979+
return response(200, json_content, headers, None, 5, request)
980+
981+
with HTTMock(resp_application_create):
982+
application = self.gl.applications.create(
983+
{
984+
"name": "test_app",
985+
"redirect_uri": "http://localhost:8080",
986+
"scopes": ["api", "email"],
987+
"confidential": False,
988+
}
989+
)
990+
self.assertEqual(application.name, "test_app")
991+
self.assertEqual(application.redirect_uri, "http://localhost:8080")
992+
self.assertEqual(application.scopes, ["api", "email"])
993+
967994
def _default_config(self):
968995
fd, temp_path = tempfile.mkstemp()
969996
os.write(fd, valid_config)

gitlab/v4/objects.py

+11
Original file line numberDiff line numberDiff line change
@@ -5141,3 +5141,14 @@ def current_failures(self, **kwargs):
51415141
list: The list of failures
51425142
"""
51435143
return self.gitlab.http_list("/geo_nodes/current/failures", **kwargs)
5144+
5145+
5146+
class Application(ObjectDeleteMixin, RESTObject):
5147+
_url = "/applications"
5148+
_short_print_attr = "name"
5149+
5150+
5151+
class ApplicationManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
5152+
_path = "/applications"
5153+
_obj_cls = Application
5154+
_create_attrs = (("name", "redirect_uri", "scopes"), ("confidential",))

0 commit comments

Comments
 (0)