A library for Python-based Harmony services to parse incoming message, fetch data, stage data, and call back to Harmony.
Project description
harmony-service-lib
A library for Python-based Harmony services to parse incoming messages, fetch data, stage data, and call back to Harmony
Installing
Using pip
Install the latest version of the package from PyPI using pip:
$ pip install harmony-service-lib
Other methods:
The package is installable from source via
$ pip install git+https://github.com/harmony/harmony-service-lib-py.git#egg=harmony-service-lib
If using a local source tree, run the following in the source root directory instead:
$ pip install -e .
Usage
Services that want to work with Harmony can make use of this library to ease interop and upgrades. To work with Harmony, services must:
- Receive incoming messages from Harmony. Currently the CLI is the only
supported way to receive messages, though HTTP is likely to follow.
harmony.cli
provides helpers for setting up CLI parsing while being unobtrusive to non-Harmony CLIs that may also need to exist. - Extend
harmony.BaseHarmonyAdapter
and either override#invoke
to process the message or override#process_item
to process each individual STAC item provided in the input STAC catalog. The adapter class provides helper methods for retrieving data, staging results, and cleaning up temporary files, though these can be overridden or ignored if a service needs different behavior, e.g. if it operates on data in situ and does not want to download the remote file.
A full example of these two requirements with use of helpers can be found in example/example_service.py. Also see adapting-new-services for in depth guidance on service development using this library, especially the info on proper error handling.
Environment
The following environment variables can be used to control the behavior of the library and allow easier testing:
REQUIRED:
-
STAGING_BUCKET
: When using helpers to stage service output and pre-sign URLs, this indicates the S3 bucket where data will be staged -
STAGING_PATH
: When using helpers to stage output, this indicates the path withinSTAGING_BUCKET
under which data will be staged -
ENV
: The name of the environment. If 'dev' or 'test', callbacks to Harmony are not made and data is not staged unless also using localstack -
OAUTH_UID
,OAUTH_PASSWORD
: Used to acquire a shared EDL token needed for downloading granules from EDL token-aware data sources. Services using data in S3 do not need to set this.NOTE: If `FALLBACK_AUTHN_ENABLED` is set to True (CAUTION!) these credentials will be used to download data *as* the EDL application user. This may cause problems with metrics and can result in users getting data for which they've not approved a EULA.
-
OAUTH_CLIENT_ID
: The Earthdata application client ID. -
OAUTH_HOST
: Set to the correct Earthdata Login URL, depending on where the service is being deployed. This should be the same environment where theOAUTH_*
credentials are valid. Defaults to UAT. -
OAUTH_REDIRECT_URI
: A valid redirect URI for the EDL application. -
SHARED_SECRET_KEY
: The 32-byte encryption key shared between Harmony and backend services. This is used to encrypt & decrypt theaccessToken
in the Harmony operation message. In a production environment, this should be injected into the container running the service Docker image. When running the service within Harmony, the Harmony infrastructure will ensure that this environment variable is set with the shared secret key, and the Harmony service library will read and use this key. Therefore, the service developer need not be aware of this variable or its value.
OPTIONAL:
APP_NAME
: Defaults to first argument on commandline. Appears in log records.AWS_DEFAULT_REGION
: (Default:"us-west-2"
) The region in which S3 calls will be madeUSE_LOCALSTACK
: (Development) If 'true' will perform S3 calls against localstack rather than AWSLOCALSTACK_HOST
: (Development) IfUSE_LOCALSTACK
true
and this is set, will establishboto
client connections for S3 operations using this hostname.TEXT_LOGGER
: (Default: True) Setting this to true will cause all log messages to use a text string format. By default log messages will be formatted as JSON.MAX_DOWNLOAD_RETRIES
: Number of times to retry HTTP download calls that fail due to transient errors.
OPTIONAL -- Use with CAUTION:
FALLBACK_AUTHN_ENABLED
: Default: False. Enable the fallback authentication that uses the EDL application credentials. See CAUTION note above.EDL_USERNAME
: The Earthdata Login username used for fallback authn.EDL_PASSWORD
: The Earthdata Login password used for fallback authn.
Development Setup
Prerequisites:
- Python 3.9+, ideally installed via a virtual environment
- A local copy of the code
Install dependencies:
$ make install
Run linter against production code:
$ make lint
Run tests:
$ make test
Build & publish the package:
$ make publish
Releasing
GitHub release notes will automatically be generated based on pull request subjects. Pull request subject lines should therefore concisely emphasize library user-facing behavior and updates they should appear in the changelog. If more information is needed for release notes, note that in the PR content.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file harmony_service_lib-2.3.0.tar.gz
.
File metadata
- Download URL: harmony_service_lib-2.3.0.tar.gz
- Upload date:
- Size: 53.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b83593c8f5d79c881da4d5255af72ff55f6ad9d21b44ed18e5df499c9d4245e8 |
|
MD5 | 2cea7f315bef2f5d70b919b8e1c9b6eb |
|
BLAKE2b-256 | 3c10dc38094179417f19c3c3afeae7caa6cbe23424f73694f1e8a4483f95cf16 |
Provenance
The following attestation bundles were made for harmony_service_lib-2.3.0.tar.gz
:
Publisher:
publish-release.yml
on nasa/harmony-service-lib-py
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
harmony_service_lib-2.3.0.tar.gz
- Subject digest:
b83593c8f5d79c881da4d5255af72ff55f6ad9d21b44ed18e5df499c9d4245e8
- Sigstore transparency entry: 148416666
- Sigstore integration time:
- Predicate type:
File details
Details for the file harmony_service_lib-2.3.0-py3-none-any.whl
.
File metadata
- Download URL: harmony_service_lib-2.3.0-py3-none-any.whl
- Upload date:
- Size: 41.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2aec682d4c5a7947a22861f396c15760cb98cef6b41ac152aa32a87a98955318 |
|
MD5 | fd271910c4e340d9f144fc167fd54b96 |
|
BLAKE2b-256 | 570735ef8800e7db16cd606434179e4754365a56f37d4cbda2851d99bf9cbc27 |
Provenance
The following attestation bundles were made for harmony_service_lib-2.3.0-py3-none-any.whl
:
Publisher:
publish-release.yml
on nasa/harmony-service-lib-py
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
harmony_service_lib-2.3.0-py3-none-any.whl
- Subject digest:
2aec682d4c5a7947a22861f396c15760cb98cef6b41ac152aa32a87a98955318
- Sigstore transparency entry: 148416667
- Sigstore integration time:
- Predicate type: