Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to parse downloading stac from file #134

Merged
merged 2 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.3.0] - 2023-01-23
### Added
- [#134](https://github.com/unity-sds/unity-data-services/pull/134) feat: add option to parse downloading stac from file

## [3.2.0] - 2023-01-23
### Added
- [#131](https://github.com/unity-sds/unity-data-services/pull/131) granules query pagination
Expand Down
16 changes: 15 additions & 1 deletion cumulus_lambda_functions/stage_in_out/download_granules_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,25 @@ def __init__(self) -> None:
self.__s3 = AwsS3()
self.__granules_json = []

def __retrieve_stac_json(self):
raw_stac_json = os.environ.get(self.STAC_JSON)
try:
self.__granules_json = json.loads(raw_stac_json)
return self
except:
LOGGER.debug(f'raw_stac_json is not STAC_JSON: {raw_stac_json}. trying to see if file exists')
if not FileUtils.file_exist(raw_stac_json):
raise ValueError(f'missing file or not JSON: {raw_stac_json}')
self.__granules_json = FileUtils.read_json(raw_stac_json)
if self.__granules_json is None:
raise ValueError(f'{raw_stac_json} is not JSON')
return self

def __set_props_from_env(self):
missing_keys = [k for k in [self.STAC_JSON, self.DOWNLOAD_DIR_KEY] if k not in os.environ]
if len(missing_keys) > 0:
raise ValueError(f'missing environment keys: {missing_keys}')
self.__granules_json = json.loads(os.environ.get(self.STAC_JSON))
self.__retrieve_stac_json()
self.__download_dir = os.environ.get(self.DOWNLOAD_DIR_KEY)
self.__download_dir = self.__download_dir[:-1] if self.__download_dir.endswith('/') else self.__download_dir
return self
Expand Down
Loading