diff --git a/docs/api-objects.rst b/docs/api-objects.rst index 569435c96..32f0d0c4c 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 000000000..146b6e801 --- /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 32aa2658a..5a5943251 100644 --- a/gitlab/__init__.py +++ b/gitlab/__init__.py @@ -144,6 +144,7 @@ def __init__( 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 e7f193217..249d0c50d 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -964,6 +964,33 @@ def resp_import_github(url, request): 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 92650b1ec..a349aff28 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -5141,3 +5141,14 @@ def current_failures(self, **kwargs): 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",))