Skip to content

Commit 8e122d1

Browse files
Add Admin API (#1137)
* Add Admin API - Create `admin.py` to serve as Admin API Core - Create `flask_admin.py` to create flask blueprint for admin API - Consolidate configuration getter - Add Pathlib serializing - Add docker example * Add integration tests - Amend admin example to allow writing to configuration. If FS is read only admin API does not work. Returns a 500 and logs `OSError: [Errno 30] Read-only file system: '/pygeoapi/local.config.yml' ` * Preserve env variables in configuration * Use common accessor functions - Use common configuration accessor methods for Django and Starlette * GET returns raw config file Return configuration with environment variables preserved on GET requests * Safeguard env variables for root cfg view "bind": { "host": "localhost", "port": "6000" } -> "bind": { "host": "${HOST}", "port": "${PORT}" } * Simplify admin HTML imports - Use jinja recursion to expand the configuration - Remove vue from templates * Create admin API documentation * Use render_item_value in admin template * Add Admin API - Create `admin.py` to serve as Admin API Core - Create `flask_admin.py` to create flask blueprint for admin API - Consolidate configuration getter - Add Pathlib serializing - Add docker example * Update GitHub Actions deployment * Update admin entrypoint Update admin entrypoint to align with upstream pygeoapi implementation * Make requested changes Co-Authored-By: Tom Kralidis <[email protected]> * Amend test url Co-Authored-By: Tom Kralidis <[email protected]> * Fix Admin CI tests * Add PUT and PATCH for root configuration - Add put and patch for root configuration - Add CI tests for PUT and PATCH of root * Update OpenAPI document wording * Update entrypoint.sh Replace tabs with spaces * Remove unused step Error from rebasing. Admin API tests are moved to their own job. * Use jsonpatch - Use debian supported packaging - Use custom merge function * Move test data location * Create Starlette and Django app - Fold flask_admin.py into flask_app.py Co-Authored-By: Tom Kralidis <[email protected]> * Make requirements-admin.txt Move admin dependencies to requirements-admin.txt * Delete guiblock.html * Update test count for STAC Update expected test count for addt'l admin test data * Relegate config warning to config.py * Move admin tests out of example * Delete admin docker example * Update admin-api.rst * Update pygeoapi-config-0.x.yml * Update configuration.rst * Update config.py * Update admin.py * Update admin.py --------- Co-authored-by: Tom Kralidis <[email protected]>
1 parent 649a02e commit 8e122d1

27 files changed

+1719
-51
lines changed

Diff for: .github/workflows/main.yml

+42
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ jobs:
9494
- name: Install requirements 📦
9595
run: |
9696
pip3 install -r requirements.txt
97+
pip3 install -r requirements-admin.txt
9798
pip3 install -r requirements-starlette.txt
9899
pip3 install -r requirements-dev.txt
99100
pip3 install -r requirements-provider.txt
@@ -151,3 +152,44 @@ jobs:
151152
if: ${{ failure() }}
152153
run: |
153154
pip3 list -v
155+
156+
admin:
157+
needs: [flake8_py3]
158+
runs-on: ubuntu-20.04
159+
strategy:
160+
matrix:
161+
include:
162+
- python-version: 3.8
163+
env:
164+
PYGEOAPI_CONFIG: "tests/pygeoapi-test-config-admin.yml"
165+
PYGEOAPI_OPENAPI: "tests/pygeoapi-test-openapi-admin.yml"
166+
steps:
167+
- uses: actions/checkout@v2
168+
- uses: actions/setup-python@v2
169+
name: Setup Python ${{ matrix.python-version }}
170+
with:
171+
python-version: ${{ matrix.python-version }}
172+
- uses: awalsh128/cache-apt-pkgs-action@latest
173+
with:
174+
packages: gunicorn python3-gevent
175+
version: 1.0
176+
- name: Install requirements 📦
177+
run: |
178+
pip3 install -r requirements.txt
179+
pip3 install -r requirements-dev.txt
180+
pip3 install -r requirements-admin.txt
181+
python3 setup.py install
182+
- name: Run pygeoapi with admin API ⚙️
183+
run: |
184+
pygeoapi openapi generate ${PYGEOAPI_CONFIG} --output-file ${PYGEOAPI_OPENAPI}
185+
gunicorn --bind 0.0.0.0:5000 \
186+
--reload \
187+
--reload-extra-file ${PYGEOAPI_CONFIG} \
188+
pygeoapi.flask_app:APP &
189+
- name: run integration tests ⚙️
190+
run: |
191+
pytest tests/test_admin_api.py
192+
- name: failed tests 🚩
193+
if: ${{ failure() }}
194+
run: |
195+
pip3 list -v

Diff for: Dockerfile

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ ARG ADD_DEB_PACKAGES="\
6464
python3-elasticsearch \
6565
python3-fiona \
6666
python3-gdal \
67+
python3-jsonpatch \
6768
python3-netcdf4 \
6869
python3-pandas \
6970
python3-psycopg2 \
@@ -121,6 +122,7 @@ RUN \
121122

122123
# Install remaining pygeoapi deps
123124
&& pip3 install -r requirements-docker.txt \
125+
&& pip3 install -r requirements-admin.txt \
124126

125127
# Install pygeoapi
126128
&& pip3 install -e . \

Diff for: docs/source/admin-api.rst

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
.. _admin-api:
2+
3+
Admin API
4+
=========
5+
6+
pygeoapi provides the ability to manage configuration through an API.
7+
8+
When enabled, :ref:`transactions` can be made on pygeoapi's configured resources. This allows for API based modification of the pygeoapi configuration.
9+
10+
The API is enabled with the following server configuration:
11+
12+
.. code-block:: yaml
13+
14+
server:
15+
admin: true # boolean on whether to enable Admin API.
16+
17+
For pygeoapi to hot reload the configuration as changes are made, the pygeoapi configuration file must be included as
18+
demonstrated for a gunicorn deployment of pygeoapi via flask:
19+
20+
.. code-block:: bash
21+
22+
gunicorn \
23+
--workers ${WSGI_WORKERS} \
24+
--worker-class=${WSGI_WORKER_CLASS} \
25+
--timeout ${WSGI_WORKER_TIMEOUT} \
26+
--name=${CONTAINER_NAME} \
27+
--bind ${CONTAINER_HOST}:${CONTAINER_PORT} \
28+
--reload \
29+
--reload-extra-file ${PYGEOAPI_CONFIG} \
30+
pygeoapi.flask_app:APP

Diff for: docs/source/configuration.rst

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ For more information related to API design rules (the ``api_rules`` property in
5050
cors: true # boolean on whether server should support CORS
5151
pretty_print: true # whether JSON responses should be pretty-printed
5252
limit: 10 # server limit on number of items to return
53+
admin: false # whether to enable the Admin API
5354
5455
templates: # optional configuration to specify a different set of templates for HTML pages. Recommend using absolute paths. Omit this to use the default provided templates
5556
path: /path/to/jinja2/templates/folder # path to templates folder containing the Jinja2 template HTML files

Diff for: docs/source/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ reference documentation on all aspects of the project.
3939
openapi
4040
data-publishing/index
4141
transactions
42+
admin-api
4243
plugins
4344
html-templating
4445
crs

0 commit comments

Comments
 (0)