Skip to content

Commit 0db4d61

Browse files
Authentication documentation (#274)
**Related Issue(s):** - #273 **Description:** Authentication related docker-compose files moved to `examples/auth` and `README` with explanation of different auth patterns being used added. **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [ ] Documentation has been updated to reflect changes, if applicable - [ ] Changes are added to the changelog --------- Co-authored-by: Jonathan Healy <[email protected]>
1 parent de78fbc commit 0db4d61

8 files changed

+270
-157
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2525

2626
- Updated stac-fastapi libraries to v3.0.0a1 [#265](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/265)
2727
- Updated stac-fastapi libraries to v3.0.0a3 [#269](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/269)
28+
- Converted Basic auth to a route dependency and merged with new route depndencies method. [#251](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/251)
29+
- Updated docker-compose.basic_auth_protected.yml to use STAC_FASTAPI_ROUTE_DEPENDENCIES environment variable. [#251](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/251)
2830

2931
### Fixed
3032

README.md

Lines changed: 19 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
</p>
1010

1111

12-
[![PyPI version](https://badge.fury.io/py/stac-fastapi.elasticsearch.svg)](https://badge.fury.io/py/stac-fastapi.elasticsearch)
12+
[![PyPI version](https://badge.fury.io/py/stac-fastapi.elasticsearch.svg)](https://badge.fury.io/py/stac-fastapi.elasticsearch)
1313
[![Join the chat at https://gitter.im/stac-fastapi-elasticsearch/community](https://badges.gitter.im/stac-fastapi-elasticsearch/community.svg)](https://gitter.im/stac-fastapi-elasticsearch/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
14-
14+
1515

1616
---
1717

@@ -22,41 +22,41 @@
2222

2323
---
2424

25-
### Notes:
25+
### Notes:
2626

27-
- Our Api core library can be used to create custom backends. See [stac-fastapi-mongo](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo) for a working example.
27+
- Our Api core library can be used to create custom backends. See [stac-fastapi-mongo](https://github.com/Healy-Hyperspatial/stac-fastapi-mongo) for a working example.
2828
- Reach out on our [Gitter](https://app.gitter.im/#/room/#stac-fastapi-elasticsearch_community:gitter.im) channel or feel free to add to our [Discussions](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/discussions) page here on github.
2929
- There is [Postman](https://documenter.getpostman.com/view/12888943/2s8ZDSdRHA) documentation here for examples on how to run some of the API routes locally - after starting the elasticsearch backend via the docker-compose.yml file.
30-
- The `/examples` folder shows an example of running stac-fastapi-elasticsearch from PyPI in docker without needing any code from the repository. There is also a Postman collection here that you can load into Postman for testing the API routes.
31-
32-
- For changes, see the [Changelog](CHANGELOG.md)
33-
- We are always welcoming contributions. For the development notes: [Contributing](CONTRIBUTING.md)
30+
- The `/examples` folder shows an example of running stac-fastapi-elasticsearch from PyPI in docker without needing any code from the repository. There is also a Postman collection here that you can load into Postman for testing the API routes.
31+
32+
- For changes, see the [Changelog](CHANGELOG.md)
33+
- We are always welcoming contributions. For the development notes: [Contributing](CONTRIBUTING.md)
3434

3535

3636
### To install from PyPI:
3737

3838
```shell
3939
pip install stac_fastapi.elasticsearch
4040
```
41-
or
41+
or
4242
```
4343
pip install stac_fastapi.opensearch
4444
```
45-
45+
4646
## Build Elasticsearch API backend
4747

4848
```shell
4949
docker-compose up elasticsearch
5050
docker-compose build app-elasticsearch
5151
```
52-
52+
5353
## Running Elasticsearch API on localhost:8080
5454

5555
```shell
5656
docker-compose up app-elasticsearch
5757
```
5858

59-
By default, docker-compose uses Elasticsearch 8.x and OpenSearch 2.11.1.
59+
By default, docker-compose uses Elasticsearch 8.x and OpenSearch 2.11.1.
6060
If you wish to use a different version, put the following in a
6161
file named `.env` in the same directory you run docker-compose from:
6262

@@ -76,7 +76,7 @@ curl -X "POST" "http://localhost:8080/collections" \
7676
}'
7777
```
7878

79-
Note: this "Collections Transaction" behavior is not part of the STAC API, but may be soon.
79+
Note: this "Collections Transaction" behavior is not part of the STAC API, but may be soon.
8080

8181
## Configure the API
8282

@@ -91,12 +91,12 @@ The application root path is left as the base url by default. If deploying to AW
9191
The collections route handles optional `limit` and `token` parameters. The `links` field that is
9292
returned from the `/collections` route contains a `next` link with the token that can be used to
9393
get the next page of results.
94-
94+
9595
```shell
9696
curl -X "GET" "http://localhost:8080/collections?limit=1&token=example_token"
9797
```
9898

99-
## Ingesting Sample Data CLI Tool
99+
## Ingesting Sample Data CLI Tool
100100

101101
```shell
102102
Usage: data_loader.py [OPTIONS]
@@ -114,12 +114,12 @@ Options:
114114

115115
```shell
116116
python3 data_loader.py --base-url http://localhost:8080
117-
```
117+
```
118118

119119

120120
## Elasticsearch Mappings
121121

122-
Mappings apply to search index, not source. The mappings are stored in index templates on application startup.
122+
Mappings apply to search index, not source. The mappings are stored in index templates on application startup.
123123
These templates will be used implicitly when creating new Collection and Item indices.
124124

125125

@@ -275,112 +275,6 @@ curl -X "POST" "http://localhost:9200/_aliases" \
275275
The modified Items with lowercase identifiers will now be visible to users accessing `my-collection` in the STAC API.
276276

277277

278-
## Basic Auth
279-
280-
#### Environment Variable Configuration
281-
282-
Basic authentication is an optional feature that can be enabled through [Route Dependencies](#route-dependencies).
283-
284-
285-
### Example Configuration
286-
287-
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.
288-
```json
289-
[
290-
{
291-
"routes": [
292-
{
293-
"method": "*",
294-
"path": "*"
295-
}
296-
],
297-
"dependencies": [
298-
{
299-
"method": "stac_fastapi.core.basic_auth.BasicAuth",
300-
"kwargs": {
301-
"credentials":[
302-
{
303-
"username": "admin",
304-
"password": "admin"
305-
}
306-
]
307-
}
308-
}
309-
]
310-
},
311-
{
312-
"routes": [
313-
{"path": "/", "method": ["GET"]},
314-
{"path": "/conformance", "method": ["GET"]},
315-
{"path": "/collections/{collection_id}/items/{item_id}", "method": ["GET"]},
316-
{"path": "/search", "method": ["GET", "POST"]},
317-
{"path": "/collections", "method": ["GET"]},
318-
{"path": "/collections/{collection_id}", "method": ["GET"]},
319-
{"path": "/collections/{collection_id}/items", "method": ["GET"]},
320-
{"path": "/queryables", "method": ["GET"]},
321-
{"path": "/queryables/collections/{collection_id}/queryables", "method": ["GET"]},
322-
{"path": "/_mgmt/ping", "method": ["GET"]}
323-
],
324-
"dependencies": [
325-
{
326-
"method": "stac_fastapi.core.basic_auth.BasicAuth",
327-
"kwargs": {
328-
"credentials":[
329-
{
330-
"username": "reader",
331-
"password": "reader"
332-
}
333-
]
334-
}
335-
}
336-
]
337-
}
338-
]
339-
```
340-
341-
## Route Dependencies
342-
343-
### Configuration
344-
345-
Route dependencies for endpoints can enable through the `STAC_FASTAPI_ROUTE_DEPENDENCIES`
346-
environment variable as a path to a JSON file or a JSON string.
347-
348-
#### Route Dependency
349-
350-
A Route Dependency must include `routes`, a list of at least one [Route](#routes), and `dependencies` a
351-
list of at least one [Dependency](#dependencies).
352-
353-
#### Routes
354-
355-
A Route must include a `path`, the relative path to the endpoint, and a `method`, the request method of the path.
356-
357-
#### Dependencies
358-
359-
A Dependency must include the `method`, a dot seperated path to the Class or Function, and
360-
can include any `args` or `kwargs` for the method.
361-
362-
#### Example
363-
```
364-
STAC_FASTAPI_ROUTE_DEPENDENCIES=[
365-
{
366-
"routes": [
367-
{
368-
"method": "GET",
369-
"path": "/collections"
370-
}
371-
],
372-
"dependencies": [
373-
{
374-
"method": "fastapi.security.OAuth2PasswordBearer",
375-
"kwargs": {
376-
"tokenUrl": "token"
377-
}
378-
}
379-
]
380-
}
381-
]
382-
```
383-
384-
### Docker Compose Configurations
278+
## Auth
385279

386-
See `docker-compose.basic_auth_protected.yml` and `docker-compose.basic_auth_public.yml` for basic authentication configurations.
280+
Authentication is an optional feature that can be enabled through `Route Dependencies` examples can be found and a more detailed explanation in [examples/auth](examples/auth).

0 commit comments

Comments
 (0)