diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fa27d6..9628b5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [v0.5.0] - 2021-08-20 + +### Removed +- `stac` module and global PySTAC dependency + ## [v0.4.6] - 2021-07-15 ### Changed @@ -135,7 +140,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. Initial Release -[Unreleased]: https://github.com/cirrus-geo/cirrus-lib/compare/v0.4.6...main +[Unreleased]: https://github.com/cirrus-geo/cirrus-lib/compare/v0.5.0...main +[v0.5.0]: https://github.com/cirrus-geo/cirrus-lib/compare/v0.4.6...v0.5.0 [v0.4.6]: https://github.com/cirrus-geo/cirrus-lib/compare/v0.4.5...v0.4.6 [v0.4.5]: https://github.com/cirrus-geo/cirrus-lib/compare/v0.4.4...v0.4.5 [v0.4.4]: https://github.com/cirrus-geo/cirrus-lib/compare/v0.4.3...v0.4.4 diff --git a/cirruslib/stac.py b/cirruslib/stac.py deleted file mode 100644 index d00802b..0000000 --- a/cirruslib/stac.py +++ /dev/null @@ -1,84 +0,0 @@ -import boto3 -import json -import logging -import os - -from boto3utils import s3 -from typing import Dict, Optional, List - -from pystac import STAC_IO, Catalog, CatalogType, Collection, Link - -logger = logging.getLogger(__name__) - -# envvars -DATA_BUCKET = os.getenv('CIRRUS_DATA_BUCKET', None) -STAC_VERSION = os.getenv('CIRRUS_STAC_VERSION', '1.0.0-beta.2') -DESCRIPTION = os.getenv('CIRRUS_STAC_DESCRIPTION', 'Cirrus STAC') -AWS_REGION = os.getenv('AWS_REGION') -PUBLISH_TOPIC = os.getenv('CIRRUS_PUBLISH_TOPIC_ARN', None) -PUBLIC_CATALOG = os.getenv('CIRRUS_PUBLIC_CATALOG', False) -if isinstance(PUBLIC_CATALOG, str): - PUBLIC_CATALOG = True if PUBLIC_CATALOG.lower() == 'true' else False - -# root catalog -ROOT_URL = f"s3://{DATA_BUCKET}" -if PUBLIC_CATALOG: - ROOT_URL = s3.s3_to_https(ROOT_URL, region=AWS_REGION) - -# boto3 clients -snsclient = boto3.client('sns') - - -def s3stac_read(uri): - if uri.startswith('http'): - uri = s3.https_to_s3(uri) - return json.dumps(s3().read_json(uri)) - -def s3stac_write(uri, txt): - extra = { - 'ContentType': 'application/json' - } - if uri.startswith('http'): - uri = s3.https_to_s3(uri) - s3().upload_json(json.loads(txt), uri, extra=extra, public=PUBLIC_CATALOG) - -STAC_IO.read_text_method = s3stac_read -STAC_IO.write_text_method = s3stac_write - - -def get_root_catalog(): - """Get Cirrus root catalog from s3 - - Returns: - Dict: STAC root catalog - """ - caturl = f"{ROOT_URL}/catalog.json" - if s3().exists(caturl): - cat = Catalog.from_file(caturl) - else: - catid = DATA_BUCKET.split('-data-')[0] - cat = Catalog(id=catid, description=DESCRIPTION) - cat.normalize_and_save(ROOT_URL, CatalogType.ABSOLUTE_PUBLISHED) - logger.debug(f"Fetched {cat.describe()}") - return cat - - -# add this collection to Cirrus catalog -def add_collections(collections, publish=True): - - for collection in collections: - collection.remove_links('child') - link = Link('copied_from', collection) - collection.add_link(link, collection.get_self_href()) - ROOT_CATALOG.add_child(collection) - if publish: - child_json = json.dumps(collection.to_dict()) - logger.debug(f"Publishing {collection.id}: {child_json}") - response = snsclient.publish(TopicArn=PUBLISH_TOPIC, Message=child_json) - logger.debug(f"SNS Publish response: {json.dumps(response)}") - - ROOT_CATALOG.normalize_and_save(ROOT_URL, CatalogType.ABSOLUTE_PUBLISHED) - return ROOT_CATALOG - - -ROOT_CATALOG = get_root_catalog() \ No newline at end of file diff --git a/cirruslib/version.py b/cirruslib/version.py index ab45471..2b8877c 100644 --- a/cirruslib/version.py +++ b/cirruslib/version.py @@ -1 +1 @@ -__version__ = '0.4.6' +__version__ = '0.5.0' diff --git a/requirements.txt b/requirements.txt index 2a4d84e..45ed9e6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,3 @@ boto3-utils~=0.3.2 -pystac~=0.5.0 requests>=2.24.0 python-json-logger~=2.0