Skip to content

Commit 7717d67

Browse files
authored
Merge pull request #283 from geoadmin/develop
Release v1.4.0
2 parents 4487e48 + 70e886b commit 7717d67

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+10973
-5293
lines changed

.pylintrc

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ limit-inference-results=100
3333
# List of plugins (as comma separated values of python module names) to load,
3434
# usually to register additional checkers.
3535
load-plugins=pylint_django
36+
django-settings-module=stac_api.settings
3637

3738
# Pickle collected data for later comparisons.
3839
persistent=yes
@@ -72,6 +73,7 @@ disable=missing-docstring,
7273
# yapf correct indentation continuation issue
7374
useless-object-inheritance,
7475
no-self-use, # method signature often defined by django
76+
similarities # currently similarities has a bug when running pylint with jobs>=2
7577

7678

7779
# Enable the message, report, category or checker with the given id(s). You can
@@ -321,7 +323,7 @@ module-naming-style=snake_case
321323

322324
# Regular expression matching correct module names. Overrides module-naming-
323325
# style.
324-
module-rgx=^(?:(?P<snake>[a-z]+[a-z_]*)|(?P<migration>\d+_[_a-z0-9]+))$
326+
module-rgx=^(?:(?P<snake>[a-z]+[a-z_\d]*)|(?P<migration>\d+_[_a-z0-9]+))$
325327

326328
# Colon-delimited sets of names that determine each other's naming style when
327329
# the name regexes allow several styles.
@@ -384,10 +386,10 @@ ignore-comments=yes
384386
ignore-docstrings=yes
385387

386388
# Ignore imports when computing similarities.
387-
ignore-imports=no
389+
ignore-imports=yes
388390

389391
# Minimum lines number of a similarity.
390-
min-similarity-lines=4
392+
min-similarity-lines=8
391393

392394

393395
[VARIABLES]

Dockerfile

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ RUN groupadd -r geoadmin \
1717
&& pip3 install pipenv \
1818
&& pipenv --version
1919

20-
COPY Pipfile* multihash.patch /tmp/
20+
COPY Pipfile* /tmp/
2121
RUN cd /tmp && \
22-
pipenv install --system --deploy --ignore-pipfile && \
23-
# Patch multihash for md5 support
24-
pipenv run pypatch apply ./multihash.patch multihash
22+
pipenv install --system --deploy --ignore-pipfile
2523

2624
# Set the working dir and copy the app
2725
WORKDIR /app
@@ -92,4 +90,4 @@ USER geoadmin
9290
EXPOSE $HTTP_PORT
9391

9492
# Use a real WSGI server
95-
ENTRYPOINT ["python3"]
93+
ENTRYPOINT ["python3"]

Makefile

-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ SHELL = /bin/bash
55
SERVICE_NAME := service-stac
66

77
CURRENT_DIR := $(shell pwd)
8-
VENV := $(CURRENT_DIR)/.venv
98

109
# Django specific
1110
APP_SRC_DIR := app
@@ -104,8 +103,6 @@ $(SETTINGS_TIMESTAMP): $(TIMESTAMPS)
104103
setup: $(SETTINGS_TIMESTAMP)
105104
# Create virtual env with all packages for development
106105
pipenv install --dev
107-
# Patch multihash for md5 support
108-
pipenv run pypatch apply ./multihash.patch multihash
109106
# Create volume directories for postgres and minio
110107
# Note that the '/service_stac_local' part is already the bucket name
111108
mkdir -p .volumes/minio/service-stac-local
@@ -119,8 +116,6 @@ setup: $(SETTINGS_TIMESTAMP)
119116
ci: $(SETTINGS_TIMESTAMP)
120117
# Create virtual env with all packages for development using the Pipfile.lock
121118
pipenv sync --dev
122-
# Patch multihash for md5 support
123-
pipenv run pypatch apply ./multihash.patch multihash
124119

125120

126121
# call yapf to make sure your code is easier to read and respects some conventions.

Pipfile

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ verify_ssl = true
55

66
[dev-packages]
77
yapf = "~=0.30.0"
8-
pylint = "~=2.5.3"
98
isort = "~=4.3.21"
10-
pylint-django = "~=2.3.0"
11-
django-extensions = "~=3.0.9"
9+
pylint = "*"
10+
pylint-django = "*"
11+
django-extensions = "*"
12+
django-debug-toolbar = ">=3.2.1"
1213
pip = "*"
13-
django-debug-toolbar = "*"
14-
mock = "==4.0.2"
1514
tblib = "*" # needed for traceback when running tests in parallel
15+
mock = "~=4.0.2"
1616
responses = "!=0.12.1" # skip version 0.12.1 which has a bug see https://github.com/getsentry/responses/issues/358
1717
moto = {extras = [ "s3",], version = "*"}
1818
requests-mock = "*"
@@ -25,8 +25,8 @@ logging-utilities = "~=1.2.0"
2525
numpy = "~=1.19.2"
2626
python-dotenv = "~=0.14.0"
2727
djangorestframework = "~=3.12.1"
28-
Django = "~=3.1"
29-
PyYAML = "~=5.3.1"
28+
Django = "~=3.1.8"
29+
PyYAML = "~=5.4"
3030
whitenoise = "~=5.2.0"
3131
djangorestframework-gis = "~=0.16"
3232
python-dateutil = "~=2.8.1"
@@ -38,6 +38,7 @@ requests = "~=2.25.0"
3838
py-multihash = "~=2.0.1"
3939
pypatch = "*"
4040
django-prometheus = "*"
41+
django-admin-autocomplete-filter = "~=0.6.1"
4142

4243
[requires]
4344
python_version = "3.7"

Pipfile.lock

+408-548
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+23-8
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,30 @@
77

88
## Table of Content
99

10+
- [Table of Content](#table-of-content)
1011
- [Summary of the project](#summary-of-the-project)
11-
- [Specs](spec/README.md)
1212
- [Local development](#local-development)
1313
- [Dependencies](#dependencies)
14+
- [Python3.7](#python37)
15+
- [pipenv](#pipenv)
16+
- [Using Postgres on local host](#using-postgres-on-local-host)
1417
- [Creating the local environment](#creating-the-local-environment)
1518
- [Setting up the local database](#setting-up-the-local-database)
1619
- [Using a local PostGres database instead of a container](#using-a-local-postgres-database-instead-of-a-container)
1720
- [Starting dev server](#starting-dev-server)
1821
- [Running tests](#running-tests)
22+
- [Unit test logging](#unit-test-logging)
1923
- [Using Django shell](#using-django-shell)
24+
- [Migrate DB with Django](#migrate-db-with-django)
2025
- [Linting and formatting your work](#linting-and-formatting-your-work)
26+
- [Initial Setup up the RDS database and the user](#initial-setup-up-the-rds-database-and-the-user)
2127
- [Deploying the project and continuous integration](#deploying-the-project-and-continuous-integration)
2228
- [Docker](#docker)
23-
- [Configuration](#configuration)
29+
- [Configuration](#configuration)
30+
- [**General settings**](#general-settings)
31+
- [**Database settings**](#database-settings)
32+
- [**Asset Storage settings (AWS S3)**](#asset-storage-settings-aws-s3)
33+
- [**Development settings (only for local environment and DEV staging)**](#development-settings-only-for-local-environment-and-dev-staging)
2434

2535
## Summary of the project
2636

@@ -33,17 +43,20 @@
3343
Prerequisites on host for development and build:
3444

3545
- python version 3.7
46+
- libgdal-dev
3647
- [pipenv](https://pipenv-fork.readthedocs.io/en/latest/install.html)
3748
- `docker` and `docker-compose`
3849

3950
#### Python3.7
4051

4152
If your Ubuntu distribution is missing Python 3.7, you may use the `deadsnakes` PPA and install it:
4253

43-
sudo add-apt-repository ppa:deadsnakes/ppa
44-
sudo apt-get update
45-
sudo apt-get install python3.7
46-
54+
```bash
55+
sudo add-apt-repository ppa:deadsnakes/ppa
56+
sudo apt-get update
57+
sudo apt-get install python3.7
58+
```
59+
4760
#### pipenv
4861

4962
Generally, all modern distribution have already a [pipenv](https://pipenv-fork.readthedocs.io) package. If no, install from hand.
@@ -52,7 +65,7 @@ The other services that are used (Postgres with PostGIS extension for metadata a
5265

5366
Starting postgres and MinIO is done with a simple
5467

55-
```
68+
```bash
5669
docker-compose up
5770
```
5871

@@ -101,7 +114,7 @@ These steps will ensure you have everything needed to start working locally.
101114
```
102115

103116
An alternative to ```pipenv install``` is to use the ```make setup``` command, which will install the environment,
104-
apply a patch to the multihash package to support md5, create the volumes needed by the Postgres and MinIO containers
117+
create the volumes needed by the Postgres and MinIO containers
105118
and run those containers. ```Make setup``` assume a standard local installation with a dev environment.
106119

107120
### Setting up the local database
@@ -146,6 +159,7 @@ some default values to be able to start working with it. (From the root)
146159
```
147160

148161
the ```pipenv shell``` command activate the virtual environment provided by pipenv.
162+
149163
### Using a local PostGres database instead of a container
150164

151165
To use a local postgres instance rather than a container, once you've ensured you've the needed dependencies, you should :
@@ -432,6 +446,7 @@ The service is configured by Environment Variable:
432446
| AWS_S3_REGION_NAME | - | |
433447
| AWS_S3_ENDPOINT_URL | `None` | |
434448
| AWS_S3_CUSTOM_DOMAIN | `None` | |
449+
| AWS_PRESIGNED_URL_EXPIRES | 3600 | AWS presigned url for asset upload expire time in seconds |
435450
436451
#### **Development settings (only for local environment and DEV staging)**
437452

app/config/settings_prod.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
'rest_framework.authtoken',
7777
# Note: If you use TokenAuthentication in production you must ensure
7878
# that your API is only available over https.
79+
'admin_auto_filters',
7980
'solo.apps.SoloAppConfig',
8081
'storages',
8182
'whitenoise.runserver_nostatic',
@@ -108,7 +109,7 @@
108109
try:
109110
CACHE_MIDDLEWARE_SECONDS = int(os.environ.get('HTTP_CACHE_SECONDS', '600'))
110111
except ValueError as error:
111-
raise ValueError('Invalid HTTP_CACHE_SECONDS environment value: must be an integer')
112+
raise ValueError('Invalid HTTP_CACHE_SECONDS environment value: must be an integer') from error
112113

113114
ROOT_URLCONF = 'config.urls'
114115
API_BASE = 'api'
@@ -194,7 +195,9 @@
194195
try:
195196
WHITENOISE_MAX_AGE = int(os.environ.get('HTTP_STATIC_CACHE_SECONDS', '3600'))
196197
except ValueError as error:
197-
raise ValueError('Invalid HTTP_STATIC_CACHE_SECONDS environment value: must be an integer')
198+
raise ValueError(
199+
'Invalid HTTP_STATIC_CACHE_SECONDS environment value: must be an integer'
200+
) from error
198201
WHITENOISE_MIMETYPES = {
199202
# These sets the mime types for the api/stac/static/spec/v0.9/openapi.yaml static file
200203
# otherwise a default application/octet-stream is used.
@@ -226,11 +229,13 @@
226229
except KeyError as err:
227230
raise KeyError(f'AWS configuration {err} missing') from err
228231

232+
AWS_PRESIGNED_URL_EXPIRES = int(os.environ.get('AWS_PRESIGNED_URL_EXPIRES', '3600'))
233+
229234
# Configure the admin upload caching
230235
try:
231236
STORAGE_ASSETS_CACHE_SECONDS = int(os.environ.get('HTTP_ASSETS_CACHE_SECONDS', '7200'))
232237
except ValueError as err:
233-
raise ValueError('Invalid HTTP_ASSETS_CACHE_SECONDS, must be an integer')
238+
raise ValueError('Invalid HTTP_ASSETS_CACHE_SECONDS, must be an integer') from err
234239

235240
# Logging
236241
# https://docs.djangoproject.com/en/3.1/topics/logging/
@@ -289,6 +294,6 @@ def get_logging_config():
289294
# data.geo.admin.ch/collection/item/asset to check if asset exists.
290295
EXTERNAL_SERVICE_TIMEOUT = 3
291296

292-
# By default django_promtheus tracks the number of migrations
297+
# By default django_prometheus tracks the number of migrations
293298
# This causes troubles in various places so we disable it
294299
PROMETHEUS_EXPORT_MIGRATIONS = False

app/config/urls.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,27 @@ def checker(request):
3737

3838
if settings.DEBUG:
3939
import debug_toolbar
40-
from stac_api.views import TestHttp500
40+
from stac_api.views_test import TestHttp500
41+
from stac_api.views_test import TestCollectionUpsertHttp500
42+
from stac_api.views_test import TestItemUpsertHttp500
43+
from stac_api.views_test import TestAssetUpsertHttp500
4144

4245
urlpatterns = [
4346
path('__debug__/', include(debug_toolbar.urls)),
4447
path('tests/test_http_500', TestHttp500.as_view()),
48+
path(
49+
'tests/test_collection_upsert_http_500/<collection_name>',
50+
TestCollectionUpsertHttp500.as_view(),
51+
name='test-collection-detail-http-500'
52+
),
53+
path(
54+
'tests/test_item_upsert_http_500/<collection_name>/<item_name>',
55+
TestItemUpsertHttp500.as_view(),
56+
name='test-item-detail-http-500'
57+
),
58+
path(
59+
'tests/test_asset_upsert_http_500/<collection_name>/<item_name>/<asset_name>',
60+
TestAssetUpsertHttp500.as_view(),
61+
name='test-asset-detail-http-500'
62+
),
4563
] + urlpatterns

app/config/version.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,17 @@
1111
# the tag is directly related to the commit or has an additional
1212
# suffix 'v[0-9]+\.[0-9]+\.[0-9]+-beta.[0-9]-[0-9]+-gHASH' denoting
1313
# the 'distance' to the latest tag
14-
proc = subprocess.Popen(["git", "describe", "--tags"],
15-
stdout=subprocess.PIPE,
16-
stderr=subprocess.PIPE)
17-
stdout, stderr = proc.communicate()
14+
with subprocess.Popen(["git", "describe", "--tags"], stdout=subprocess.PIPE,
15+
stderr=subprocess.PIPE) as proc:
16+
stdout, stderr = proc.communicate()
1817
GIT_VERSION = stdout.decode('utf-8').strip()
1918
if GIT_VERSION == '':
2019
# If theres no git tag found in the history we simply use the short
2120
# version of the latest git commit hash
22-
proc = subprocess.Popen(["git", "rev-parse", "--short", "HEAD"],
23-
stdout=subprocess.PIPE,
24-
stderr=subprocess.PIPE)
25-
stdout, stderr = proc.communicate()
21+
with subprocess.Popen(["git", "rev-parse", "--short", "HEAD"],
22+
stdout=subprocess.PIPE,
23+
stderr=subprocess.PIPE) as proc:
24+
stdout, stderr = proc.communicate()
2625
APP_VERSION = f"v_{stdout.decode('utf-8').strip()}"
2726
else:
2827
APP_VERSION = GIT_VERSION

0 commit comments

Comments
 (0)