-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'simplify_plugins' of https://github.com/cedadev/stac-ge…
…nerator into simplify_plugins Conflicts: requirements.txt stac_generator/plugins/extraction_methods/asset_aggregator.py stac_generator/plugins/extraction_methods/ceda_vocabulary.py stac_generator/plugins/extraction_methods/datetime_bound_to_centroid.py stac_generator/plugins/extraction_methods/dot_seperated_str.py stac_generator/plugins/extraction_methods/elasticsearch_aggregation.py stac_generator/plugins/extraction_methods/elasticsearch_assets.py stac_generator/plugins/extraction_methods/general_function.py stac_generator/plugins/extraction_methods/geometry_to_bbox.py stac_generator/plugins/extraction_methods/header/header.py stac_generator/plugins/extraction_methods/iso_date.py stac_generator/plugins/extraction_methods/json_file.py stac_generator/plugins/extraction_methods/lambda.py stac_generator/plugins/extraction_methods/netcdf.py stac_generator/plugins/extraction_methods/open_zip.py stac_generator/plugins/extraction_methods/regex_assets.py stac_generator/plugins/extraction_methods/remove.py stac_generator/plugins/extraction_methods/stac_bbox.py stac_generator/plugins/extraction_methods/xml.py stac_generator/plugins/mappings/stac.py stac_generator/plugins/outputs/stac_fastapi.py
- Loading branch information
Showing
16 changed files
with
78 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
__contact__ = "[email protected]" | ||
|
||
import logging | ||
from datetime import datetime | ||
|
||
from jinja2 import Environment, FileSystemLoader | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,9 +40,6 @@ | |
__license__ = "BSD - see LICENSE file in top-level package directory" | ||
__contact__ = "[email protected]" | ||
|
||
from datetime import datetime | ||
from typing import Dict | ||
|
||
from elasticsearch import Elasticsearch | ||
|
||
from stac_generator.core.output import BaseOutput | ||
|
@@ -74,7 +71,7 @@ def __init__(self, **kwargs): | |
self.es.indices.create(self.index_name, body=mapping) | ||
|
||
@staticmethod | ||
def _format_bbox(data: Dict) -> Dict: | ||
def _format_bbox(data: dict) -> dict: | ||
""" | ||
Convert WGS84 coordinates into GeoJSON and | ||
format for Elasticsearch. Replaces the bbox key. | ||
|
@@ -96,7 +93,7 @@ def _format_bbox(data: Dict) -> Dict: | |
return data | ||
|
||
@staticmethod | ||
def _format_temporal_extent(data: Dict) -> Dict: | ||
def _format_temporal_extent(data: dict) -> dict: | ||
""" | ||
Convert `extent object<https://github.com/radiantearth/stac-spec/blob/master/collection-spec/collection-spec.md#extent-object>_` for Elasticsearch. | ||
|
@@ -116,7 +113,7 @@ def _format_temporal_extent(data: Dict) -> Dict: | |
|
||
return data | ||
|
||
def clean(self, data: Dict) -> Dict: | ||
def clean(self, data: dict) -> dict: | ||
""" | ||
Condition the input dictionary for elasticsearch | ||
:param data: Input dictionary | ||
|
@@ -129,7 +126,7 @@ def clean(self, data: Dict) -> Dict: | |
|
||
return data | ||
|
||
def _remove_old(self, data: str, previous_ids: dict) -> Dict: | ||
def _remove_old(self, data: str, previous_ids: dict) -> dict: | ||
""" | ||
Condition the input dictionary for elasticsearch | ||
:param data: Input dictionary | ||
|
@@ -142,7 +139,6 @@ def _remove_old(self, data: str, previous_ids: dict) -> Dict: | |
self.es.delete(index=self.index_name, id=previous_id) | ||
|
||
def export(self, data: dict, **kwargs) -> None: | ||
|
||
data = self.clean(data) | ||
|
||
if self.remove_old: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,14 +40,17 @@ | |
__license__ = "BSD - see LICENSE file in top-level package directory" | ||
__contact__ = "[email protected]" | ||
|
||
import requests | ||
import logging | ||
from urllib.parse import urljoin | ||
import logging | ||
|
||
import requests | ||
|
||
from stac_generator.core.output import BaseOutput | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
class STACFastAPIOutput(BaseOutput): | ||
""" | ||
Connects to an elasticsearch instance and exports the | ||
|
@@ -58,7 +61,7 @@ class STACFastAPIOutput(BaseOutput): | |
def __init__(self, **kwargs): | ||
super().__init__(**kwargs) | ||
if not hasattr(self, "verify"): | ||
self.verify = True | ||
self.verify = True | ||
|
||
def item(self, data: dict) -> None: | ||
collections = data["collection"] | ||
|
@@ -67,28 +70,36 @@ def item(self, data: dict) -> None: | |
collections = [collections] | ||
|
||
for collection in collections: | ||
|
||
collection = data["collection"] = collection.lower() | ||
|
||
response = requests.post( | ||
urljoin(self.api_url, f"collections/{collection}/items"), json=data, verify=self.verify | ||
urljoin(self.api_url, f"collections/{collection}/items"), | ||
json=data, | ||
verify=self.verify, | ||
) | ||
|
||
if response.status_code == 404: | ||
response_json = response.json() | ||
|
||
if response_json["description"] == f"Collection {collection} does not exist": | ||
if ( | ||
response_json["description"] | ||
== f"Collection {collection} does not exist" | ||
): | ||
collection = { | ||
"type": "Collection", | ||
"id": collection, | ||
} | ||
|
||
response = requests.post( | ||
urljoin(self.api_url, "collections"), json=collection, verify=self.verify | ||
urljoin(self.api_url, "collections"), | ||
json=collection, | ||
verify=self.verify, | ||
) | ||
|
||
response = requests.post( | ||
urljoin(self.api_url, f"collections/{collection}/items"), json=data, verify=self.verify | ||
urljoin(self.api_url, f"collections/{collection}/items"), | ||
json=data, | ||
verify=self.verify, | ||
) | ||
|
||
if response.status_code == 409: | ||
|
@@ -103,18 +114,32 @@ def item(self, data: dict) -> None: | |
LOGGER.warning(f"FastAPI Output Update failed with status code: {response.status_code} and response text: {response.text}") | ||
|
||
elif response.status_code != 200: | ||
LOGGER.warning(f"FastAPI Output failed with status code: {response.status_code} and response text: {response.text}") | ||
LOGGER.warning( | ||
"FastAPI Output failed to post to STAC Fastapi items endpoint returned status code: %s and response text: %s request data: %s", | ||
response.status_code, | ||
response.text, | ||
data, | ||
) | ||
|
||
def collection(self, data: dict) -> None: | ||
|
||
response = requests.post( | ||
urljoin(self.api_url, "collections"), json=data, verify=self.verify | ||
urljoin(self.api_url, "collections"), | ||
json=data, | ||
verify=self.verify, | ||
timeout=180, | ||
) | ||
|
||
def export(self, data: dict, **kwargs) -> None: | ||
if response.status_code != 200: | ||
LOGGER.warning( | ||
"FastAPI Output failed to post to STAC Fastapi collections endpoint returned status code: %s and response text: %s request data: %s", | ||
response.status_code, | ||
response.text, | ||
data, | ||
) | ||
|
||
if kwargs['TYPE'].value == "item": | ||
def export(self, data: dict, **kwargs) -> None: | ||
if kwargs["TYPE"].value == "item": | ||
self.item(data) | ||
|
||
elif kwargs['TYPE'].value == "collection": | ||
elif kwargs["TYPE"].value == "collection": | ||
self.collection(data) |
Oops, something went wrong.