From 1f3895315f1444959648d69599db3e8c49011554 Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Sun, 2 Jun 2019 20:00:47 -0400 Subject: [PATCH] Make the API page size configurable Instead of hard coding the page size to 100, make it configurable. Change-Id: I399ff5a8d9f8fa6c61fcaabc6fafb0c30cc1dc55 --- ara/server/settings.py | 4 +++- doc/source/api-configuration.rst | 13 +++++++++++++ roles/ara_api/defaults/main.yaml | 3 +++ roles/ara_api/tasks/config.yaml | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/ara/server/settings.py b/ara/server/settings.py index b7a137e6..678bf318 100644 --- a/ara/server/settings.py +++ b/ara/server/settings.py @@ -187,9 +187,10 @@ WSGI_APPLICATION = "ara.server.wsgi.application" ROOT_URLCONF = "ara.server.urls" APPEND_SLASH = False +PAGE_SIZE = settings.get("PAGE_SIZE", 100) REST_FRAMEWORK = { "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination", - "PAGE_SIZE": 100, + "PAGE_SIZE": PAGE_SIZE, "DEFAULT_FILTER_BACKENDS": ("django_filters.rest_framework.DjangoFilterBackend",), "DEFAULT_RENDERER_CLASSES": ( "rest_framework.renderers.JSONRenderer", @@ -232,6 +233,7 @@ if not os.path.exists(DEFAULT_SETTINGS) and "ARA_SETTINGS" not in os.environ: LOGGING=LOGGING, READ_LOGIN_REQUIRED=READ_LOGIN_REQUIRED, WRITE_LOGIN_REQUIRED=WRITE_LOGIN_REQUIRED, + PAGE_SIZE=PAGE_SIZE, ) with open(DEFAULT_SETTINGS, "w+") as settings_file: comment = f""" diff --git a/doc/source/api-configuration.rst b/doc/source/api-configuration.rst index b74e0cfc..17faf244 100644 --- a/doc/source/api-configuration.rst +++ b/doc/source/api-configuration.rst @@ -48,6 +48,8 @@ For more details, click on the configuration parameters. +--------------------------------+--------------------------------------------------------+------------------------------------------------------+ | ARA_LOG_LEVEL_ | ``INFO`` | Log level of the different components | +--------------------------------+--------------------------------------------------------+------------------------------------------------------+ +| ARA_PAGE_SIZE_ | ``100`` | Amount of results returned per page by the API | ++--------------------------------+--------------------------------------------------------+------------------------------------------------------+ | ARA_READ_LOGIN_REQUIRED_ | ``False`` | Whether authentication is required for reading data | +--------------------------------+--------------------------------------------------------+------------------------------------------------------+ | ARA_SECRET_KEY_ | Randomized token, see ARA_SECRET_KEY_ | Django's SECRET_KEY_ setting | @@ -346,6 +348,17 @@ python library. .. _dynaconf: https://github.com/rochacbruno/dynaconf +ARA_PAGE_SIZE +~~~~~~~~~~~~~ + +- **Environment variable**: ``ARA_PAGE_SIZE`` +- **Configuration file variable**: ``PAGE_SIZE`` +- **Type**: ``integer`` +- **Default**: ``50`` +- **Provided by**: django-rest-framework `pagination `_ + +When querying the API server, the amount of items per page returned. + ARA_READ_LOGIN_REQUIRED ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/roles/ara_api/defaults/main.yaml b/roles/ara_api/defaults/main.yaml index 6d6945f6..e9aca0e6 100644 --- a/roles/ara_api/defaults/main.yaml +++ b/roles/ara_api/defaults/main.yaml @@ -96,6 +96,9 @@ ara_api_read_login_required: false # ARA_WRITE_LOGIN_REQUIRED - Whether authentication is required for writing data ara_api_write_login_required: false +# ARA_PAGE_SIZE - Amount of results returned per page by the API +ara_api_page_size: 100 + # ARA_LOG_LEVEL - Log level of the different components ara_api_log_level: INFO diff --git a/roles/ara_api/tasks/config.yaml b/roles/ara_api/tasks/config.yaml index 459b072c..4267d4bb 100644 --- a/roles/ara_api/tasks/config.yaml +++ b/roles/ara_api/tasks/config.yaml @@ -79,6 +79,7 @@ SECRET_KEY: "{{ ara_api_secret_key }}" READ_LOGIN_REQUIRED: "{{ ara_api_read_login_required }}" WRITE_LOGIN_REQUIRED: "{{ ara_api_write_login_required }}" + PAGE_SIZE: "{{ ara_api_page_size }}" set_fact: ara_api_configuration: "{'{{ ara_api_env }}': {{ reconciled_configuration }} }" no_log: yes