Skip to content

Commit

Permalink
feat(api): add support for GitLab OAuth Applications API
Browse files Browse the repository at this point in the history
  • Loading branch information
filipowm committed Mar 1, 2020
1 parent f071390 commit 4e12356
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/api-objects.rst
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions 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()
1 change: 1 addition & 0 deletions gitlab/__init__.py
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions gitlab/tests/test_gitlab.py
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions gitlab/v4/objects.py
Expand Up @@ -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",))

0 comments on commit 4e12356

Please sign in to comment.