harmony-service-lib


Nameharmony-service-lib JSON
Version 1.0.8 PyPI version JSON
download
home_pagehttps://github.com/nasa/harmony-service-lib-py
SummaryA library for Python-based Harmony services to parse incoming messages, fetch data, stage data, and call back to Harmony
upload_time2021-05-04 18:37:11
maintainer
docs_urlNone
authorNASA EOSDIS Harmony Team
requires_python>=3.7
licenseLicense :: OSI Approved :: Apache Software License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

1. 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.
2. Extend `harmony.BaseHarmonyAdapter` and implement the `#invoke` to
adapt the incoming Harmony message to a service call and adapt the service
result to call to one of the adapter's `#completed_with_*` methods. 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](example/example_service.py)

## 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 within
       `STAGING_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 the `OAUTH_*` 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 the `accessToken` 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 made
* `USE_LOCALSTACK`: (Development) If 'true' will perform S3 calls against localstack rather
       than AWS
* `LOCALSTACK_HOST`: (Development) If `USE_LOCALSTACK` `true` and this is set, will
       establish `boto` client connections for S3 & SQS 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.
* `HEALTH_CHECK_PATH`: Set this to the path where the health check file should be stored. This
       file's mtime is set to the current time whenever a successful attempt is made to to read the
       message queue (whether or not a message is retrieved). This file can be used by a container's
       health check command. The container is considered unhealthy if the mtime of the file is old -
       where 'old' is configurable in the service container. If this variable is not set the path
       defaults to '/tmp/health.txt'.

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.7+, ideally installed via a virtual environment such as `pyenv`
  - A local copy of the code

Install dependencies:

    $ make develop

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.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nasa/harmony-service-lib-py",
    "name": "harmony-service-lib",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "NASA EOSDIS Harmony Team",
    "author_email": "patrick@element84.com",
    "download_url": "https://files.pythonhosted.org/packages/d1/57/f48101b6819ed50717e13444c9c8ad86309cfe790177d8006cdf7a3e223e/harmony-service-lib-1.0.8.tar.gz",
    "platform": "",
    "description": "# harmony-service-lib\n\nA library for Python-based Harmony services to parse incoming messages, fetch data, stage data, and call back to Harmony\n\n## Installing\n\n### Using pip\n\nInstall the latest version of the package from PyPI using pip:\n\n    $ pip install harmony-service-lib\n\n### Other methods:\n\nThe package is installable from source via\n\n    $ pip install git+https://github.com/harmony/harmony-service-lib-py.git#egg=harmony-service-lib\n\nIf using a local source tree, run the following in the source root directory instead:\n\n    $ pip install -e .\n\n## Usage\n\nServices that want to work with Harmony can make use of this library to ease\ninterop and upgrades.  To work with Harmony, services must:\n\n1. Receive incoming messages from Harmony.  Currently the CLI is the only\nsupported way to receive messages, though HTTP is likely to follow.  `harmony.cli`\nprovides helpers for setting up CLI parsing while being unobtrusive to non-Harmony\nCLIs that may also need to exist.\n2. Extend `harmony.BaseHarmonyAdapter` and implement the `#invoke` to\nadapt the incoming Harmony message to a service call and adapt the service\nresult to call to one of the adapter's `#completed_with_*` methods. The adapter\nclass provides helper methods for retrieving data, staging results, and cleaning\nup temporary files, though these can be overridden or ignored if a service\nneeds different behavior, e.g. if it operates on data in situ and does not\nwant to download the remote file.\n\nA full example of these two requirements with use of helpers can be found in\n[example/example_service.py](example/example_service.py)\n\n## Environment\n\nThe following environment variables can be used to control the behavior of the\nlibrary and allow easier testing:\n\nREQUIRED:\n\n* `STAGING_BUCKET`: When using helpers to stage service output and pre-sign URLs, this\n       indicates the S3 bucket where data will be staged\n* `STAGING_PATH`: When using helpers to stage output, this indicates the path within\n       `STAGING_BUCKET` under which data will be staged\n* `ENV`: The name of the environment.  If 'dev' or 'test', callbacks to Harmony are\n       not made and data is not staged unless also using localstack\n* `OAUTH_UID`, `OAUTH_PASSWORD`: Used to acquire a shared EDL token\n       needed for downloading granules from EDL token-aware data\n       sources. Services using data in S3 do not need to set this.\n\n       NOTE: If `FALLBACK_AUTHN_ENABLED` is set to True (CAUTION!)\n       these credentials will be used to download data *as* the EDL\n       application user. This may cause problems with metrics and can\n       result in users getting data for which they've not approved a\n       EULA.\n* `OAUTH_CLIENT_ID`: The Earthdata application client ID.\n* `OAUTH_HOST`: Set to the correct Earthdata Login URL, depending on\n       where the service is being deployed. This should be the same\n       environment where the `OAUTH_*` credentials are valid. Defaults\n       to UAT.\n* `OAUTH_REDIRECT_URI`: A valid redirect URI for the EDL application.\n* `SHARED_SECRET_KEY`: The 32-byte encryption key shared between Harmony and backend services.\n       This is used to encrypt & decrypt the `accessToken` in the Harmony operation message.\n       In a production environment, this should be injected into the container running the service\n       Docker image. When running the service within Harmony, the Harmony infrastructure will\n       ensure that this environment variable is set with the shared secret key, and the Harmony\n       service library will read and use this key. Therefore, the service developer need not\n       be aware of this variable or its value.\n\nOPTIONAL:\n\n* `APP_NAME`: Defaults to first argument on commandline. Appears in log records.\n* `AWS_DEFAULT_REGION`: (Default: `\"us-west-2\"`) The region in which S3 calls will be made\n* `USE_LOCALSTACK`: (Development) If 'true' will perform S3 calls against localstack rather\n       than AWS\n* `LOCALSTACK_HOST`: (Development) If `USE_LOCALSTACK` `true` and this is set, will\n       establish `boto` client connections for S3 & SQS operations using this hostname.\n* `TEXT_LOGGER`: (Default: True) Setting this to true will cause all\n       log messages to use a text string format. By default log\n       messages will be formatted as JSON.\n* `HEALTH_CHECK_PATH`: Set this to the path where the health check file should be stored. This\n       file's mtime is set to the current time whenever a successful attempt is made to to read the\n       message queue (whether or not a message is retrieved). This file can be used by a container's\n       health check command. The container is considered unhealthy if the mtime of the file is old -\n       where 'old' is configurable in the service container. If this variable is not set the path\n       defaults to '/tmp/health.txt'.\n\nOPTIONAL -- Use with CAUTION:\n\n* `FALLBACK_AUTHN_ENABLED`: Default: False. Enable the fallback authentication that\n  uses the EDL application credentials. See CAUTION note above.\n* `EDL_USERNAME`: The Earthdata Login username used for fallback authn.\n* `EDL_PASSWORD`: The Earthdata Login password used for fallback authn.\n\n## Development Setup\n\nPrerequisites:\n  - Python 3.7+, ideally installed via a virtual environment such as `pyenv`\n  - A local copy of the code\n\nInstall dependencies:\n\n    $ make develop\n\nRun linter against production code:\n\n    $ make lint\n\nRun tests:\n\n    $ make test\n\nBuild & publish the package:\n\n    $ make publish\n\n## Releasing\n\nGitHub release notes will automatically be generated based on pull request subjects.\nPull request subject lines should therefore concisely emphasize library\nuser-facing behavior and updates they should appear in the changelog.  If more\ninformation is needed for release notes, note that in the PR content.\n\n\n",
    "bugtrack_url": null,
    "license": "License :: OSI Approved :: Apache Software License",
    "summary": "A library for Python-based Harmony services to parse incoming messages, fetch data, stage data, and call back to Harmony",
    "version": "1.0.8",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "8b506198d310662b0324130cd15c7eaa",
                "sha256": "00452cad304592f556f0dff0a1bbdbb6a3271e4fbe16ab5137c680d769166f74"
            },
            "downloads": -1,
            "filename": "harmony_service_lib-1.0.8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8b506198d310662b0324130cd15c7eaa",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 38788,
            "upload_time": "2021-05-04T18:37:10",
            "upload_time_iso_8601": "2021-05-04T18:37:10.646866Z",
            "url": "https://files.pythonhosted.org/packages/1f/3b/24d33fee428b8a7d3643f4c136a09bfb4895c8ba9cd33838a4341b5205ae/harmony_service_lib-1.0.8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "c327828a027a879bb297dec9f18fbeef",
                "sha256": "0ce99c51c4520ef746eba56c1bf92fca045b45cd051de49ee5ac9e5ca43f2500"
            },
            "downloads": -1,
            "filename": "harmony-service-lib-1.0.8.tar.gz",
            "has_sig": false,
            "md5_digest": "c327828a027a879bb297dec9f18fbeef",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 37376,
            "upload_time": "2021-05-04T18:37:11",
            "upload_time_iso_8601": "2021-05-04T18:37:11.973317Z",
            "url": "https://files.pythonhosted.org/packages/d1/57/f48101b6819ed50717e13444c9c8ad86309cfe790177d8006cdf7a3e223e/harmony-service-lib-1.0.8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-05-04 18:37:11",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "nasa",
    "error": "Could not fetch GitHub repository",
    "lcname": "harmony-service-lib"
}
        
Elapsed time: 0.23495s