Skip to content

Commit 502a870

Browse files
authored
Merge pull request #36 from Healy-Hyperspatial/update-core-3.0.0
### Added - Logging to database logic. [#36](#36) ### Changed - Add support for python 3.12. [#22](#22) - Updated sfeos core to v3.0.0a0, fixed datetime functionality. [#23](#23) - Updated stac-fastapi.core to v4.1.0. [#36](#36) - Create indexes in MongoDB at startup only if environment variable MONGO_CREATE_INDEXES is set to "true" (default when the env variable is not set: "true"). [#31](#31) - Improved README with table of contents, better formatting, and added Contributing section. [#34](#34) - Updated authentication to use STAC_FASTAPI_ROUTE_DEPENDENCIES environment variable instead of BASIC_AUTH. [#36](#36) ### Fixed - Added a new index based on collection id and item id to ensure item IDs aren't required to be unique across all collections. [#26](#26) - Updated test fixtures to use ASGITransport with AsyncClient for compatibility with newer httpx versions. [#35](#35)
2 parents d78fc0e + a509807 commit 502a870

File tree

15 files changed

+514
-283
lines changed

15 files changed

+514
-283
lines changed

.github/workflows/cicd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
strategy:
2727
matrix:
28-
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12"]
28+
python-version: ["3.9", "3.10", "3.11", "3.12"]
2929

3030
name: Python ${{ matrix.python-version }} testing
3131

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0/
77

88
## [Unreleased]
99

10+
## [v4.0.0]
11+
12+
### Added
13+
14+
- Logging to database logic. [#36](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/pull/36)
15+
1016
### Changed
1117

1218
- Add support for python 3.12. [#22](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/pull/22)
1319
- Updated sfeos core to v3.0.0a0, fixed datetime functionality. [#23](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/pull/23)
20+
- Updated stac-fastapi.core to v4.1.0. [#36](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/pull/36)
1421
- Create indexes in MongoDB at startup only if environment variable MONGO_CREATE_INDEXES is set to "true" (default when the env variable is not set: "true"). [#31](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/pull/31)
1522
- Improved README with table of contents, better formatting, and added Contributing section. [#34](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/pull/34)
23+
- Updated authentication to use STAC_FASTAPI_ROUTE_DEPENDENCIES environment variable instead of BASIC_AUTH. [#36](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/pull/36)
1624

1725
### Fixed
1826

@@ -76,7 +84,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0/
7684

7785
----
7886

79-
[Unreleased]: <https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/compare/v3.2.1...main>
87+
[Unreleased]: <https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/compare/v4.0.0...main>
88+
[v4.0.0]: <https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/compare/v3.2.1...v4.0.0>
8089
[v3.2.1]: <https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/compare/v3.2.0...v3.2.1>
8190
[v3.2.0]: <https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/compare/v3.1.0...v3.2.0>
8291
[v3.1.0]: <https://github.com/Healy-Hyperspatial/stac-fastapi-mongo/compare/v3.0.1...v3.1.0>

README.md

Lines changed: 149 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ MongoDB backend for the [stac-fastapi](https://github.com/stac-utils/stac-fastap
1818

1919
<!-- [![Join the chat at https://gitter.im/stac-fastapi-mongo/community](https://badges.gitter.im/stac-fastapi-mongo/community.svg)](https://gitter.im/stac-fastapi-mongo/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) -->
2020

21+
## Technologies
22+
23+
This project is built on the following technologies: STAC, stac-fastapi, SFEOS core, FastAPI, MongoDB, Python
24+
25+
<p align="left">
26+
<a href="https://stacspec.org/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/STAC-01.png" alt="STAC" height="100" hspace="10"></a>
27+
<a href="https://www.python.org/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/python.png" alt="Python" height="80" hspace="10"></a>
28+
<a href="https://fastapi.tiangolo.com/"><img src="https://raw.githubusercontent.com/stac-utils/stac-fastapi-elasticsearch-opensearch/refs/heads/main/assets/fastapi.svg" alt="FastAPI" height="80" hspace="10"></a>
29+
<a href="https://www.mongodb.com/"><img src="assets/mongodb.svg" alt="MongoDB" height="80" hspace="10"></a>
30+
<a href="https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch"><img src="assets/sfeos-bw.png" alt="stac-fastapi-core" height="83" hspace="10"></a>
31+
</p>
32+
33+
2134
## Table of Contents
2235

2336
- [Installation](#installation)
@@ -32,9 +45,11 @@ MongoDB backend for the [stac-fastapi](https://github.com/stac-utils/stac-fastap
3245
- [Sample Data](#sample-data)
3346
- [Authentication](#authentication)
3447
- [Environment Variable Configuration](#environment-variable-configuration)
35-
- [User Permissions Configuration](#user-permissions-configuration)
36-
- [Public Endpoints Configuration](#public-endpoints-configuration)
37-
- [Authentication Configurations](#authentication-configurations)
48+
- [Authentication Configuration](#authentication-configuration)
49+
- [Examples](#examples)
50+
- [Admin-only Authentication](#admin-only-authentication)
51+
- [Public Endpoints with Admin Authentication](#public-endpoints-with-admin-authentication)
52+
- [Multi-user Authentication](#multi-user-authentication)
3853
- [Read-Only Databases](#note-for-read-only-databases)
3954
- [Contributing](#contributing)
4055
- [Changelog](#changelog)
@@ -128,79 +143,153 @@ make ingest
128143

129144
### Environment Variable Configuration
130145

131-
Basic authentication is an optional feature. You can enable it by setting the environment variable `BASIC_AUTH` as a JSON string.
146+
Basic authentication is an optional feature. You can enable it by setting the environment variable `STAC_FASTAPI_ROUTE_DEPENDENCIES` as a JSON string.
132147

133148
Example:
134149
```
135-
BASIC_AUTH={"users":[{"username":"user","password":"pass","permissions":"*"}]}
150+
STAC_FASTAPI_ROUTE_DEPENDENCIES=[{"routes":[{"method":"*","path":"*"}],"dependencies":[{"method":"stac_fastapi.core.models.basic_auth.BasicAuth","kwargs":{"credentials":[{"username":"admin","password":"admin"}]}}]}]
136151
```
137152

138-
### User Permissions Configuration
153+
### Authentication Configuration
154+
155+
The `STAC_FASTAPI_ROUTE_DEPENDENCIES` environment variable allows you to configure different levels of authentication for different routes. The configuration is a JSON array of objects, each with two properties:
139156

140-
In order to set endpoints with specific access permissions, you can configure the `users` key with a list of user objects. Each user object should contain the username, password, and their respective permissions.
157+
1. `routes`: An array of route objects, each with `method` and `path` properties
158+
2. `dependencies`: An array of dependency objects, each with `method` and `kwargs` properties
159+
160+
#### Examples
161+
162+
##### Admin-only Authentication
163+
164+
This example configures all routes to require admin authentication:
141165

142-
Example: This example illustrates the configuration for two users: an **admin** user with full permissions (*) and a **reader** user with limited permissions to specific read-only endpoints.
143166
```json
144-
{
145-
"users": [
146-
{
147-
"username": "admin",
148-
"password": "admin",
149-
"permissions": "*"
150-
},
151-
{
152-
"username": "reader",
153-
"password": "reader",
154-
"permissions": [
155-
{"path": "/", "method": ["GET"]},
156-
{"path": "/conformance", "method": ["GET"]},
157-
{"path": "/collections/{collection_id}/items/{item_id}", "method": ["GET"]},
158-
{"path": "/search", "method": ["GET", "POST"]},
159-
{"path": "/collections", "method": ["GET"]},
160-
{"path": "/collections/{collection_id}", "method": ["GET"]},
161-
{"path": "/collections/{collection_id}/items", "method": ["GET"]},
162-
{"path": "/queryables", "method": ["GET"]},
163-
{"path": "/queryables/collections/{collection_id}/queryables", "method": ["GET"]},
164-
{"path": "/_mgmt/ping", "method": ["GET"]}
165-
]
166-
}
167-
]
168-
}
167+
[
168+
{
169+
"routes": [
170+
{
171+
"method": "*",
172+
"path": "*"
173+
}
174+
],
175+
"dependencies": [
176+
{
177+
"method": "stac_fastapi.core.models.basic_auth.BasicAuth",
178+
"kwargs": {
179+
"credentials": [
180+
{
181+
"username": "admin",
182+
"password": "admin"
183+
}
184+
]
185+
}
186+
}
187+
]
188+
}
189+
]
169190
```
170191

171-
### Public Endpoints Configuration
192+
##### Public Endpoints with Admin Authentication
172193

173-
In order to set endpoints with public access, you can configure the public_endpoints key with a list of endpoint objects. Each endpoint object should specify the path and method of the endpoint.
194+
This example makes specific endpoints public while requiring admin authentication for all others:
174195

175-
Example: This example demonstrates the configuration for public endpoints, allowing access without authentication to read-only endpoints.
176196
```json
177-
{
178-
"public_endpoints": [
179-
{"path": "/", "method": "GET"},
180-
{"path": "/conformance", "method": "GET"},
181-
{"path": "/collections/{collection_id}/items/{item_id}", "method": "GET"},
182-
{"path": "/search", "method": "GET"},
183-
{"path": "/search", "method": "POST"},
184-
{"path": "/collections", "method": "GET"},
185-
{"path": "/collections/{collection_id}", "method": "GET"},
186-
{"path": "/collections/{collection_id}/items", "method": "GET"},
187-
{"path": "/queryables", "method": "GET"},
188-
{"path": "/queryables/collections/{collection_id}/queryables", "method": "GET"},
189-
{"path": "/_mgmt/ping", "method": "GET"}
190-
],
191-
"users": [
192-
{
193-
"username": "admin",
194-
"password": "admin",
195-
"permissions": "*"
196-
}
197-
]
198-
}
197+
[
198+
{
199+
"routes": [
200+
{
201+
"method": "*",
202+
"path": "*"
203+
}
204+
],
205+
"dependencies": [
206+
{
207+
"method": "stac_fastapi.core.models.basic_auth.BasicAuth",
208+
"kwargs": {
209+
"credentials": [
210+
{
211+
"username": "admin",
212+
"password": "admin"
213+
}
214+
]
215+
}
216+
}
217+
]
218+
},
219+
{
220+
"routes": [
221+
{"path": "/", "method": ["GET"]},
222+
{"path": "/conformance", "method": ["GET"]},
223+
{"path": "/collections/{collection_id}/items/{item_id}", "method": ["GET"]},
224+
{"path": "/search", "method": ["GET", "POST"]},
225+
{"path": "/collections", "method": ["GET"]},
226+
{"path": "/collections/{collection_id}", "method": ["GET"]},
227+
{"path": "/collections/{collection_id}/items", "method": ["GET"]},
228+
{"path": "/queryables", "method": ["GET"]},
229+
{"path": "/queryables/collections/{collection_id}/queryables", "method": ["GET"]},
230+
{"path": "/_mgmt/ping", "method": ["GET"]}
231+
],
232+
"dependencies": []
233+
}
234+
]
199235
```
200236

201-
### Authentication Configurations
237+
##### Multi-user Authentication
202238

203-
See `docker-compose.basic_auth_protected.yml` and `docker-compose.basic_auth_public.yml` for basic authentication configurations.
239+
This example configures admin authentication for all routes, with a separate reader user that can access specific read-only endpoints:
240+
241+
```json
242+
[
243+
{
244+
"routes": [
245+
{
246+
"method": "*",
247+
"path": "*"
248+
}
249+
],
250+
"dependencies": [
251+
{
252+
"method": "stac_fastapi.core.models.basic_auth.BasicAuth",
253+
"kwargs": {
254+
"credentials": [
255+
{
256+
"username": "admin",
257+
"password": "admin"
258+
}
259+
]
260+
}
261+
}
262+
]
263+
},
264+
{
265+
"routes": [
266+
{"path": "/", "method": ["GET"]},
267+
{"path": "/conformance", "method": ["GET"]},
268+
{"path": "/collections/{collection_id}/items/{item_id}", "method": ["GET"]},
269+
{"path": "/search", "method": ["GET", "POST"]},
270+
{"path": "/collections", "method": ["GET"]},
271+
{"path": "/collections/{collection_id}", "method": ["GET"]},
272+
{"path": "/collections/{collection_id}/items", "method": ["GET"]},
273+
{"path": "/queryables", "method": ["GET"]},
274+
{"path": "/queryables/collections/{collection_id}/queryables", "method": ["GET"]},
275+
{"path": "/_mgmt/ping", "method": ["GET"]}
276+
],
277+
"dependencies": [
278+
{
279+
"method": "stac_fastapi.core.models.basic_auth.BasicAuth",
280+
"kwargs": {
281+
"credentials": [
282+
{
283+
"username": "reader",
284+
"password": "reader"
285+
}
286+
]
287+
}
288+
}
289+
]
290+
}
291+
]
292+
```
204293

205294
## Note for Read-Only Databases
206295

assets/mongodb.svg

Lines changed: 5 additions & 0 deletions
Loading

assets/sfeos-bw.png

1.87 MB
Loading

docker-compose.basic_auth_protected.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- MONGO_USER=root
1818
- MONGO_PASS=example
1919
- MONGO_PORT=27017
20-
- BASIC_AUTH={"users":[{"username":"admin","password":"admin","permissions":"*"},{"username":"reader","password":"reader","permissions":[{"path":"/","method":["GET"]},{"path":"/conformance","method":["GET"]},{"path":"/collections/{collection_id}/items/{item_id}","method":["GET"]},{"path":"/search","method":["GET","POST"]},{"path":"/collections","method":["GET"]},{"path":"/collections/{collection_id}","method":["GET"]},{"path":"/collections/{collection_id}/items","method":["GET"]},{"path":"/queryables","method":["GET"]},{"path":"/queryables/collections/{collection_id}/queryables","method":["GET"]},{"path":"/_mgmt/ping","method":["GET"]}]}]}
20+
- STAC_FASTAPI_ROUTE_DEPENDENCIES=[{"routes":[{"method":"*","path":"*"}],"dependencies":[{"method":"stac_fastapi.core.basic_auth.BasicAuth","kwargs":{"credentials":[{"username":"admin","password":"admin"}]}}]},{"routes":[{"path":"/","method":["GET"]},{"path":"/conformance","method":["GET"]},{"path":"/collections/{collection_id}/items/{item_id}","method":["GET"]},{"path":"/search","method":["GET","POST"]},{"path":"/collections","method":["GET"]},{"path":"/collections/{collection_id}","method":["GET"]},{"path":"/collections/{collection_id}/items","method":["GET"]},{"path":"/queryables","method":["GET"]},{"path":"/queryables/collections/{collection_id}/queryables","method":["GET"]},{"path":"/_mgmt/ping","method":["GET"]}],"dependencies":[{"method":"stac_fastapi.core.basic_auth.BasicAuth","kwargs":{"credentials":[{"username":"reader","password":"reader"}]}}]}]
2121
ports:
2222
- "8084:8084"
2323
volumes:

docker-compose.basic_auth_public.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ services:
1717
- MONGO_USER=root
1818
- MONGO_PASS=example
1919
- MONGO_PORT=27017
20-
- BASIC_AUTH={"public_endpoints":[{"path":"/","method":"GET"},{"path":"/conformance","method":"GET"},{"path":"/collections/{collection_id}/items/{item_id}","method":"GET"},{"path":"/search","method":"GET"},{"path":"/search","method":"POST"},{"path":"/collections","method":"GET"},{"path":"/collections/{collection_id}","method":"GET"},{"path":"/collections/{collection_id}/items","method":"GET"},{"path":"/queryables","method":"GET"},{"path":"/queryables/collections/{collection_id}/queryables","method":"GET"},{"path":"/_mgmt/ping","method":"GET"}],"users":[{"username":"admin","password":"admin","permissions":[{"path":"/","method":["GET"]},{"path":"/conformance","method":["GET"]},{"path":"/collections/{collection_id}/items/{item_id}","method":["GET","POST","PUT","DELETE"]},{"path":"/search","method":["GET","POST"]},{"path":"/collections","method":["GET","PUT","POST"]},{"path":"/collections/{collection_id}","method":["GET","DELETE"]},{"path":"/collections/{collection_id}/items","method":["GET","POST"]},{"path":"/queryables","method":["GET"]},{"path":"/queryables/collections/{collection_id}/queryables","method":["GET"]},{"path":"/_mgmt/ping","method":["GET"]}]}]}
20+
- STAC_FASTAPI_ROUTE_DEPENDENCIES=[{"routes":[{"method":"*","path":"*"}],"dependencies":[{"method":"stac_fastapi.core.basic_auth.BasicAuth","kwargs":{"credentials":[{"username":"admin","password":"admin"}]}}]},{"routes":[{"path":"/","method":["GET"]},{"path":"/conformance","method":["GET"]},{"path":"/collections/{collection_id}/items/{item_id}","method":["GET"]},{"path":"/search","method":["GET","POST"]},{"path":"/collections","method":["GET"]},{"path":"/collections/{collection_id}","method":["GET"]},{"path":"/collections/{collection_id}/items","method":["GET"]},{"path":"/queryables","method":["GET"]},{"path":"/queryables/collections/{collection_id}/queryables","method":["GET"]},{"path":"/_mgmt/ping","method":["GET"]}],"dependencies":[]}]
2121
ports:
2222
- "8084:8084"
2323
volumes:

setup.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
desc = f.read()
77

88
install_requires = [
9-
"stac-fastapi.core==3.0.0a0",
10-
"motor==3.3.2",
11-
"pymongo==4.6.2",
9+
"stac-fastapi-core==4.1.0",
10+
"motor~=3.3.2",
11+
"pymongo~=4.6.2",
1212
"uvicorn",
1313
"starlette",
14-
"typing_extensions==4.8.0",
15-
"stac_pydantic==3.0.0",
14+
"typing_extensions~=4.8.0",
15+
"stac_pydantic>=3.0.0",
1616
]
1717

1818
extra_reqs = {
@@ -30,8 +30,8 @@
3030
}
3131

3232
setup(
33-
name="stac-fastapi.mongo",
34-
version="3.2.1",
33+
name="stac-fastapi-mongo",
34+
version="4.0.0",
3535
description="Mongodb stac-fastapi backend.",
3636
long_description=desc,
3737
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)