summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/api-objects.rst1
-rw-r--r--docs/gl_objects/applications.rst31
-rw-r--r--gitlab/__init__.py1
-rw-r--r--gitlab/tests/test_gitlab.py27
-rw-r--r--gitlab/v4/objects.py11
5 files changed, 71 insertions, 0 deletions
diff --git a/docs/api-objects.rst b/docs/api-objects.rst
index 569435c..32f0d0c 100644
--- a/docs/api-objects.rst
+++ b/docs/api-objects.rst
@@ -7,6 +7,7 @@ API examples
gl_objects/access_requests
gl_objects/appearance
+ gl_objects/applications
gl_objects/emojis
gl_objects/badges
gl_objects/branches
diff --git a/docs/gl_objects/applications.rst b/docs/gl_objects/applications.rst
new file mode 100644
index 0000000..146b6e8
--- /dev/null
+++ b/docs/gl_objects/applications.rst
@@ -0,0 +1,31 @@
+############
+Applications
+############
+
+Reference
+---------
+
+* v4 API:
+
+ + :class:`gitlab.v4.objects.Applications`
+ + :class:`gitlab.v4.objects.ApplicationManager`
+ + :attr:`gitlab.Gitlab.applications`
+
+* GitLab API: https://docs.gitlab.com/ce/api/applications.html
+
+Examples
+--------
+
+List all OAuth applications::
+
+ applications = gl.applications.list()
+
+Create an application::
+
+ gl.applications.create({'name': 'your_app', 'redirect_uri': 'http://application.url', 'scopes': ['api']})
+
+Delete an applications::
+
+ gl.applications.delete(app_id)
+ # or
+ application.delete()
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index 96a3c13..7ea141e 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -144,6 +144,7 @@ class Gitlab(object):
self.features = objects.FeatureManager(self)
self.pagesdomains = objects.PagesDomainManager(self)
self.user_activities = objects.UserActivitiesManager(self)
+ self.applications = objects.ApplicationManager(self)
def __enter__(self):
return self
diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py
index e7f1932..249d0c5 100644
--- a/gitlab/tests/test_gitlab.py
+++ b/gitlab/tests/test_gitlab.py
@@ -964,6 +964,33 @@ class TestGitlab(unittest.TestCase):
self.assertEqual(ret["full_path"], "/".join((base_path, name)))
self.assertTrue(ret["full_name"].endswith(name))
+ def test_applications(self):
+ content = '{"name": "test_app", "redirect_uri": "http://localhost:8080", "scopes": ["api", "email"]}'
+ json_content = json.loads(content)
+
+ @urlmatch(
+ scheme="http",
+ netloc="localhost",
+ path="/api/v4/applications",
+ method="post",
+ )
+ def resp_application_create(url, request):
+ headers = {"content-type": "application/json"}
+ return response(200, json_content, headers, None, 5, request)
+
+ with HTTMock(resp_application_create):
+ application = self.gl.applications.create(
+ {
+ "name": "test_app",
+ "redirect_uri": "http://localhost:8080",
+ "scopes": ["api", "email"],
+ "confidential": False,
+ }
+ )
+ self.assertEqual(application.name, "test_app")
+ self.assertEqual(application.redirect_uri, "http://localhost:8080")
+ self.assertEqual(application.scopes, ["api", "email"])
+
def _default_config(self):
fd, temp_path = tempfile.mkstemp()
os.write(fd, valid_config)
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py
index 92650b1..a349aff 100644
--- a/gitlab/v4/objects.py
+++ b/gitlab/v4/objects.py
@@ -5141,3 +5141,14 @@ class GeoNodeManager(RetrieveMixin, UpdateMixin, DeleteMixin, RESTManager):
list: The list of failures
"""
return self.gitlab.http_list("/geo_nodes/current/failures", **kwargs)
+
+
+class Application(ObjectDeleteMixin, RESTObject):
+ _url = "/applications"
+ _short_print_attr = "name"
+
+
+class ApplicationManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
+ _path = "/applications"
+ _obj_cls = Application
+ _create_attrs = (("name", "redirect_uri", "scopes"), ("confidential",))