-
-
Notifications
You must be signed in to change notification settings - Fork 229
[feature] REST API for main controller features #379 #386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nemesifier
merged 32 commits into
openwisp:master
from
ManishShah120:issues/379-REST_API-for-main-controller
May 12, 2021
Merged
Changes from 30 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
9e97015
[feature] REST API for main controller features #379
ManishShah120 5ead323
[docs] Added the documentation for the rest API feature
ManishShah120 b04bd83
[tests] Tests for main controller API feature
ManishShah120 38f4816
[api] Improvements and Handled Corner Cases
ManishShah120 9d779db
[api] Enhancements and Improvemesnts
ManishShah120 e45685f
[api] Improvements
ManishShah120 9c25048
[fix] Return all the objects to admin
ManishShah120 fb44b20
[fix] Minor code enhancement
ManishShah120 6d5984f
[fix] Restrict who can set Organization=None
ManishShah120 cd2ca57
[fix] Minor bug fix related to required Templates
ManishShah120 22ad25b
[fix] Fixed the representation of JSON fields
ManishShah120 3cdd17d
[api] Improvements of corner casses
ManishShah120 2ea8207
[api] Fixed transalatable strings and readonly fields
ManishShah120 b3bbdd1
[api] Added config field in the device list endpoint
ManishShah120 8caa48f
[api] Reverted the last_ip, management_ip to prev representation
ManishShah120 846d6ce
[api] Simplified `create` function of `DeviceListSerializer`
ManishShah120 af7b407
[api] Added ` vpn` field in `TemplateSerializer`
ManishShah120 4fde2f8
[api] Code quality improvements
ManishShah120 48b7697
[api] Removed white trailing spaces
ManishShah120 f5154dc
[api] Handled a corner case related to vpn type template
ManishShah120 6e4cf9c
[api] Minor Code improvements
ManishShah120 a005738
[api] Fixed variable name issue
ManishShah120 06b183f
[api] Fixed config representation for DeviceList endpoint
ManishShah120 efebb91
[api] Fixed a validation issue in template Serilaizer
ManishShah120 c592b3e
[api] Simplified Template filtering for Device Serializer
ManishShah120 718e414
[api] Added tests for template creation of VPN type
ManishShah120 4eacd3c
[api] Added `include_shared` and added new tests for post request wit…
ManishShah120 3eed885
[api] Minor improvements
ManishShah120 15405eb
[api] Added Extensibility feat for the config api
ManishShah120 7e1d9ca
[chores] Fix field name while validation in template serializer
ManishShah120 c742290
[tests] Fixed build failing issue
ManishShah120 28f1622
[chores] Point screenshots to master
nemesifier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -593,6 +593,251 @@ For example, if we want to change the verbose name to "Hotspot", we could write: | |
|
|
||
| OPENWISP_CONTROLLER_DEVICE_VERBOSE_NAME = ('Hotspot', 'Hotspots') | ||
|
|
||
| ``OPENWISP_CONTROLLER_API`` | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| +--------------+-----------+ | ||
| | **type**: | ``bool`` | | ||
| +--------------+-----------+ | ||
| | **default**: | ``True`` | | ||
| +--------------+-----------+ | ||
|
|
||
| Indicates whether the API for Openwisp Controller is enabled or not. | ||
| To disable the API by default add `OPENWISP_CONTROLLER_API = False` in `settings.py` file. | ||
|
|
||
| REST API | ||
| -------- | ||
|
|
||
| Live documentation | ||
| ~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| .. image:: https://raw.githubusercontent.com/ManishShah120/openwisp-controller/issues/379-REST_API-for-main-controller/docs/live-docu-api.png | ||
|
|
||
| A general live API documentation (following the OpenAPI specification) at ``/api/v1/docs/``. | ||
|
|
||
| Browsable web interface | ||
| ~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| .. image:: https://raw.githubusercontent.com/ManishShah120/openwisp-controller/issues/379-REST_API-for-main-controller/docs/browsable-api-ui.png | ||
|
|
||
| Additionally, opening any of the endpoints `listed below <#list-of-endpoints>`_ | ||
| directly in the browser will show the `browsable API interface of Django-REST-Framework | ||
| <https://www.django-rest-framework.org/topics/browsable-api/>`_, | ||
| which makes it even easier to find out the details of each endpoint. | ||
|
|
||
| Authentication | ||
| ~~~~~~~~~~~~~~ | ||
|
|
||
| See openwisp-users: `authenticating with the user token | ||
| <https://github.com/openwisp/openwisp-users#authenticating-with-the-user-token>`_. | ||
|
|
||
| When browsing the API via the `Live documentation <#live-documentation>`_ | ||
| or the `Browsable web page <#browsable-web-interface>`_, you can also use | ||
| the session authentication by logging in the django admin. | ||
|
|
||
| Pagination | ||
| ~~~~~~~~~~ | ||
|
|
||
| All *list* endpoints support the ``page_size`` parameter that allows paginating | ||
| the results in conjunction with the ``page`` parameter. | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| GET /api/v1/controller/template/?page_size=10 | ||
| GET /api/v1/controller/template/?page_size=10&page=2 | ||
|
|
||
| List of endpoints | ||
| ~~~~~~~~~~~~~~~~~ | ||
|
|
||
| Since the detailed explanation is contained in the `Live documentation <#live-documentation>`_ | ||
| and in the `Browsable web page <#browsable-web-interface>`_ of each point, | ||
| here we'll provide just a list of the available endpoints, | ||
| for further information please open the URL of the endpoint in your browser. | ||
|
|
||
| List devices | ||
| ^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| GET /api/v1/controller/device/ | ||
|
|
||
| Create device | ||
| ^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| POST /api/v1/controller/device/ | ||
|
|
||
| Get device detail | ||
| ^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| GET /api/v1/controller/device/{pk}/ | ||
|
|
||
| Download device configuration | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| GET /api/v1/controller/device/{pk}/configuration/ | ||
|
|
||
| The above endpoint triggers the download of a ``tar.gz`` file containing the generated configuration for that specific device. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try to make sure lines are not longer than 70/80 characters as in the rest of the text please (applies to all other lines as well). |
||
|
|
||
| Change details of device | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| PUT /api/v1/controller/device/{pk}/ | ||
|
|
||
| Patch details of device | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| PATCH /api/v1/controller/device/{pk}/ | ||
|
|
||
| **Note**: To assign, unassign, and change the order of the assigned templates add, | ||
| remove, and change the order of the ``{pk}`` of the templates under the ``config`` field in the JSON response respectively. | ||
ManishShah120 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Moreover, you can also select and unselect templates in the HTML Form of the Browsable API. | ||
|
|
||
| The required template(s) from the organization(s) of the device will added automatically | ||
| to the ``config`` and cannot be removed. | ||
|
|
||
| **Example usage**: For assigning template(s) add the/their {pk} to the config of a device, | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| echo '{"config":{"templates": ["4791fa4c-2cef-4f42-8bb4-c86018d71bd3"]}}' | \ | ||
| http PATCH http://127.0.0.1:8000/api/v1/controller/device/76b7d9cc-4ffd-4a43-b1b0-8f8befd1a7c0/ \ | ||
| "Authorization: Bearer 9b5e40da02d107cfdb9d6b69b26dc00332ec2fbc" | ||
|
|
||
| **Example usage**: For removing assigned templates, simply remove the/their {pk} from the config of a device, | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| echo '{"config":{"templates": []}}' | \ | ||
| http PATCH http://127.0.0.1:8000/api/v1/controller/device/76b7d9cc-4ffd-4a43-b1b0-8f8befd1a7c0/ \ | ||
| "Authorization: Bearer 9b5e40da02d107cfdb9d6b69b26dc00332ec2fbc" | ||
|
|
||
| **Example usage**: For reordering the templates simply change their order from the config of a device, | ||
|
|
||
| .. code-block:: shell | ||
|
|
||
| echo '{"config":{"templates": ["c5bbc697-170e-44bc-8eb7-b944b55ee88f","4791fa4c-2cef-4f42-8bb4-c86018d71bd3"]}}' | \ | ||
| http PATCH http://127.0.0.1:8000/api/v1/controller/device/76b7d9cc-4ffd-4a43-b1b0-8f8befd1a7c0/ \ | ||
| "Authorization: Bearer 9b5e40da02d107cfdb9d6b69b26dc00332ec2fbc" | ||
|
|
||
| Delete device | ||
| ^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| DELETE /api/v1/controller/device/{pk}/ | ||
|
|
||
| List templates | ||
ManishShah120 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| GET /api/v1/controller/template/ | ||
|
|
||
| Create template | ||
| ^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| POST /api/v1/controller/template/ | ||
|
|
||
| Get template detail | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| GET /api/v1/controller/template/{pk}/ | ||
|
|
||
| Download template configuration | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
ManishShah120 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| GET /api/v1/controller/template/{pk}/configuration/ | ||
|
|
||
| The above endpoint triggers the download of a ``tar.gz`` file containing the generated configuration for that specific template. | ||
|
|
||
| Change details of template | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| PUT /api/v1/controller/template/{pk}/ | ||
|
|
||
| Patch details of template | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| PATCH /api/v1/controller/template/{pk}/ | ||
|
|
||
| Delete template | ||
| ^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| DELETE /api/v1/controller/template/{pk}/ | ||
|
|
||
| List VPNs | ||
| ^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| GET /api/v1/controller/vpn/ | ||
|
|
||
| Create VPN | ||
| ^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| POST /api/v1/controller/vpn/ | ||
|
|
||
| Get VPN detail | ||
| ^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| GET /api/v1/controller/vpn/{pk}/ | ||
|
|
||
| Download VPN configuration | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| GET /api/v1/controller/vpn/{pk}/configuration/ | ||
|
|
||
| The above endpoint triggers the download of a ``tar.gz`` file containing the generated configuration for that specific VPN. | ||
|
|
||
| Change details of VPN | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| PUT /api/v1/controller/vpn/{pk}/ | ||
|
|
||
| Patch details of VPN | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| PATCH /api/v1/controller/vpn/{pk}/ | ||
|
|
||
| Delete VPN | ||
| ^^^^^^^^^^ | ||
|
|
||
| .. code-block:: text | ||
|
|
||
| DELETE /api/v1/controller/vpn/{pk}/ | ||
|
|
||
| Default Alerts / Notifications | ||
| ------------------------------ | ||
|
|
||
|
|
||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reminder that we'll have to update these screenshots to point to master once we're ready to merge
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, Once we are ready to merge, I'll Update it.