Skip to content

Commit fe3e249

Browse files
authored
Merge pull request #627 from geoadmin/develop
New Release v2.5.0 - #minor
2 parents 06b651d + 44df0fc commit fe3e249

8 files changed

Lines changed: 73 additions & 10 deletions

File tree

.env.default

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ SECRET_KEY=dummy
2020
HEALTHCHECK_ENDPOINT=healthcheck
2121
ALLOWED_HOSTS=*
2222
MANAGED_BUCKET_COLLECTION_PATTERNS=ch.meteoschweiz.ogd-,ch.bgdi-test.
23+
MANAGED_BUCKET_COLLECTION_PATTERNS_BLACKLIST=ch.meteoschweiz.ogd-precipitation
2324

2425
# these are just here for completeness
2526
AWS_ROLE_ARN=some-arn

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,7 @@ The service is configured by Environment Variable:
548548
| AWS_S3_CUSTOM_DOMAIN | `None` | |
549549
| AWS_PRESIGNED_URL_EXPIRES | 3600 | AWS presigned url for asset upload expire time in seconds |
550550
| MANAGED_BUCKET_COLLECTION_PATTERNS | - | A list of prefix patterns for collections that go to the managed bucket |
551+
| MANAGED_BUCKET_COLLECTION_PATTERNS_BLACKLIST | - | A list of prefix patterns for collection that explicitly should not go to the managed bucket |
551552
| EXTERNAL_URL_REACHABLE_TIMEOUT | `5` | How long the external asset URL validator should try to connect to given asset in seconds |
552553

553554
#### **Development settings (only for local environment and DEV staging)**

app/config/settings_dev.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@
5252

5353
SHELL_PLUS_POST_IMPORTS = ['from tests.data_factory import Factory']
5454

55-
# Regex patterns of collections that should go to the managed bucket
55+
# Patterns prefixes of collections that should go to the managed bucket
5656
MANAGED_BUCKET_COLLECTION_PATTERNS = env.list(
5757
'MANAGED_BUCKET_COLLECTION_PATTERNS', default=["ch.meteoschweiz.ogd-"]
5858
)
5959

60+
# Patterns prefixes of collections that should should *not* go to the managed bucket
61+
MANAGED_BUCKET_COLLECTION_PATTERNS_BLACKLIST = env.list(
62+
'MANAGED_BUCKET_COLLECTION_PATTERNS_BLACKLIST', default=["ch.meteoschweiz.ogd-precipitation"]
63+
)
64+
6065
# Since it's impossible to recreate the service-account situation with minio
6166
# we inject some configuration in here to access the second bucket
6267
# in the same way as first bucket, via access/secrets

app/config/settings_prod.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,14 @@ def get_logging_config():
358358
) # if None, the host is taken from the request url
359359
STAC_BROWSER_BASE_PATH = env('STAC_BROWSER_BASE_PATH', default='browser/index.html')
360360

361-
# Regex patterns of collections that should go to the managed bucket
361+
# Pattern prefixes of collections that should go to the managed bucket
362362
MANAGED_BUCKET_COLLECTION_PATTERNS = env.list('MANAGED_BUCKET_COLLECTION_PATTERNS', default=[])
363363

364+
# Pattern prefixes of collections that should should *not* go to the managed bucket
365+
MANAGED_BUCKET_COLLECTION_PATTERNS_BLACKLIST = env.list(
366+
'MANAGED_BUCKET_COLLECTION_PATTERNS_BLACKLIST', default=[""]
367+
)
368+
364369
# the duration in seconds that the validator should try and reach the external URL
365370
EXTERNAL_URL_REACHABLE_TIMEOUT = env.int('EXTERNAL_URL_REACHABLE_TIMEOUT', default=5)
366371

app/stac_api/utils.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,15 @@ def select_s3_bucket(collection_name) -> AVAILABLE_S3_BUCKETS:
602602
Select the correct s3 bucket based on matching patterns with the collection
603603
name
604604
"""
605-
patterns = settings.MANAGED_BUCKET_COLLECTION_PATTERNS
606-
607-
for pattern in patterns:
608-
if collection_name.startswith(pattern):
605+
whitelist_patterns = settings.MANAGED_BUCKET_COLLECTION_PATTERNS
606+
blacklist_patterns = settings.MANAGED_BUCKET_COLLECTION_PATTERNS_BLACKLIST
607+
608+
for whitelist_pattern in whitelist_patterns:
609+
if collection_name.startswith(whitelist_pattern):
610+
# if a pattern is found, let's also check it against the blacklist
611+
for blacklist_pattern in blacklist_patterns:
612+
if collection_name.startswith(blacklist_pattern):
613+
return AVAILABLE_S3_BUCKETS.legacy
609614
return AVAILABLE_S3_BUCKETS.managed
610615

611616
return AVAILABLE_S3_BUCKETS.legacy

app/tests/base_test_admin_page.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import re
23
import time
34

45
from django.contrib.auth import get_user_model
@@ -18,6 +19,22 @@
1819
logger = logging.getLogger(__name__)
1920

2021

22+
def normalize_wkt(wkt_string):
23+
"""Normalize WKT string by rounding floating point numbers to 10 decimal places.
24+
25+
This handles floating point precision differences that occur during
26+
database storage/retrieval.
27+
"""
28+
wkt = re.sub(r'(\d+\.\d+)', lambda m: str(round(float(m.group(1)), 10)), wkt_string)
29+
# Canonicalize spacing so POLYGON ((.. becomes POLYGON((.. and commas have single spaces
30+
wkt = re.sub(r'([A-Z]+)\s+\(', r'\1(', wkt)
31+
wkt = re.sub(r'\(\s+', '(', wkt)
32+
wkt = re.sub(r'\s+\)', ')', wkt)
33+
wkt = re.sub(r',\s*', ', ', wkt)
34+
wkt = re.sub(r'\s+', ' ', wkt)
35+
return wkt.strip()
36+
37+
2138
class AdminBaseTestCase(TestCase):
2239

2340
def setUp(self):
@@ -175,7 +192,17 @@ def _create_item(self, collection, with_link=False, extra=None, data=None):
175192
elif key.startswith('links-'):
176193
continue
177194
else:
178-
self.assertEqual(getattr(item, key), value, msg=f"Item field {key} value missmatch")
195+
if key == 'geometry':
196+
geom_obj = getattr(item, key)
197+
actual_wkt = normalize_wkt(str(geom_obj))
198+
expected_wkt = normalize_wkt(value)
199+
self.assertEqual(
200+
actual_wkt, expected_wkt, msg=f"Item field {key} value missmatch"
201+
)
202+
else:
203+
self.assertEqual(
204+
getattr(item, key), value, msg=f"Item field {key} value missmatch"
205+
)
179206

180207
return item, data, link
181208

app/tests/test_multiple_bucket_setup.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def test_managed_bucket_patterns(self, collection_name):
178178
default environment explicitly here.
179179
This might appear a bit artificial, but otherwise we have no way
180180
to machine-test the functioning of getting the values from the env
181-
list, use them as regex, and match the collection name.
181+
list and match the collection name.
182182
"""
183183
env = environ.Env()
184184
env.read_env("../.local.default")
@@ -188,3 +188,22 @@ def test_managed_bucket_patterns(self, collection_name):
188188
bucket_name = select_s3_bucket(collection_name)
189189

190190
self.assertEqual(bucket_name, AVAILABLE_S3_BUCKETS.managed)
191+
192+
@parameterized.expand([
193+
'ch.meteoschweiz.ogd-precipitation',
194+
])
195+
def test_managed_bucket_patterns_blacklist(self, collection_name):
196+
"""Test if the patterns in the environment work correctly. We take the
197+
default environment explicitly here.
198+
This might appear a bit artificial, but otherwise we have no way
199+
to machine-test the functioning of getting the values from the env
200+
list and match the collection name.
201+
"""
202+
env = environ.Env()
203+
env.read_env("../.local.default")
204+
205+
patterns = env.list('MANAGED_BUCKET_COLLECTION_PATTERNS_BLACKLIST')
206+
with self.settings(MANAGED_BUCKET_COLLECTION_PATTERNS=patterns):
207+
bucket_name = select_s3_bucket(collection_name)
208+
209+
self.assertEqual(bucket_name, AVAILABLE_S3_BUCKETS.legacy)

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
services:
22
db:
3-
image: kartoza/postgis:16
3+
image: kartoza/postgis:18-3.6
44
environment:
55
- POSTGRES_DB=${DB_NAME:-service_stac_local}
66
- POSTGRES_USER=postgres
77
- POSTGRES_PASSWORD=postgres
8-
- POSTGRES_MULTIPLE_EXTENSIONS=postgis,postgis_topology
8+
- POSTGRES_MULTIPLE_EXTENSIONS=postgis
99
- EXTRA_CONF=log_min_messages = ${DB_LOG_LEVEL:-FATAL}
1010
user: ${UID}
1111
ports:

0 commit comments

Comments
 (0)