Name | value-fetcher JSON |
Version |
1.0.3
JSON |
| download |
home_page | None |
Summary | Fetch a value from various sources, e.g AWS Secrets Manager and SSM Parameter Store |
upload_time | 2024-04-30 10:44:08 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | None |
keywords |
configuration
parameters
secrets
values
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Value fetcher
## Introduction
Python module to fetch values from multiple sources with optional defaults, including:
- Environment variables
- AWS Systems Manager (SSM) Parameter Store
- AWS Secrets Manager
## Usage
Install the package with the following:
```shell
pip install value-fetcher
```
### Fetching values directly
In this use case, the value fetcher package makes it convenient to fetch values from the supported sources in a consistent and simplified manner.
```python
from value_fetcher import ValueFetcher
# Instantiate value fetcher class
fetcher = ValueFetcher()
# Retrieve values from supported AWS sources
my_secret = fetcher.get_from_aws_secrets_manager('/my/secret/key')
my_param = fetcher.get_from_aws_ssm_parameter_store('/my/parameter/key')
```
### Configuring source locations dynamically
In this use case, environment variables are used to configure the sources for multiple keys.
This is useful in more complex applications where lots of values need to be fetched and the source needs to be configured dynamically.
See this [contact form handler repository](https://github.com/voquis/aws-lambda-contact-form-handler) for example usage.
Environment variables can be appended to the configuration key name, setting the source of the value.
These are:
- `_PARAMETER_STORE_NAME` - for AWS SSM Parameter Store
- `_SECRETS_MANAGER_NAME` - for AWS Secrets Manager
One of the available configuration sources for each value must also be set by setting an environment variable ending with `_SOURCE` for the value name:
- `env` - Environment variables (default)
- `aws_ssm_parameter_store` - AWS Systems Manager (SSM) Parameter Store
- `aws_secrets_manager` - AWS Secrets Manager
For example, to fetch `MY_PARAM` from AWS SSM Parameter Store and `MY_SECRET` from AWS Secrets Manager, consider the following python script (e.g. `app.py`) called subsequently by a shell script:
```python
# This file is app.py for example
from value_fetcher import ValueFetcher
# Instantiate value fetcher class, with optional defaults if values cannot be found
fetcher = ValueFetcher({
'MY_PARAM': 'Default value if none can be found',
})
# Retrieve values from supported AWS sources
my_secret = fetcher.get('MY_SECRET')
my_param = fetcher.get('MY_PARAM')
print(my_secret)
print(my_param)
```
The above scripts would be called by the following shell script:
```shell
#!/usr/bin/bash
MY_PARAM_SOURCE="aws_ssm_parameter_store"
MY_PARAM_PARAMETER_STORE_NAME="/my/parameter/store/key/name"
MY_SECRET_SOURCE="aws_secrets_manager"
MY_SECRET_SECRETS_MANAGER_NAME="my/secrets/manager/key/name"
export MY_PARAM_SOURCE MY_PARAM_PARAMETER_STORE_NAME
export MY_SECRET_SOURCE MY_SECRET_SECRETS_MANAGER_NAME
# For AWS ensure credentials are available, e.g. with AWS SSO, aws-vault, aws-profile etc.
python app.py
```
## Development
This project uses Poetry for package management.
After cloning, run:
```
./scripts/poetry.sh
```
to install dependencies for local development and running tests, etc.
### Tests
To run static code analysers and unit tests:
```
./scripts/validate.sh
```
Raw data
{
"_id": null,
"home_page": null,
"name": "value-fetcher",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "configuration, parameters, secrets, values",
"author": null,
"author_email": "Voquis Limited <opensource@voquis.com>",
"download_url": "https://files.pythonhosted.org/packages/db/ea/7e4c6137b3f8fb6b8baba747b52ebd5d91856e3f96b6e335c6196e9f21a5/value_fetcher-1.0.3.tar.gz",
"platform": null,
"description": "# Value fetcher\n## Introduction\nPython module to fetch values from multiple sources with optional defaults, including:\n- Environment variables\n- AWS Systems Manager (SSM) Parameter Store\n- AWS Secrets Manager\n\n## Usage\nInstall the package with the following:\n\n```shell\npip install value-fetcher\n```\n\n### Fetching values directly\nIn this use case, the value fetcher package makes it convenient to fetch values from the supported sources in a consistent and simplified manner.\n```python\nfrom value_fetcher import ValueFetcher\n\n# Instantiate value fetcher class\nfetcher = ValueFetcher()\n\n# Retrieve values from supported AWS sources\nmy_secret = fetcher.get_from_aws_secrets_manager('/my/secret/key')\nmy_param = fetcher.get_from_aws_ssm_parameter_store('/my/parameter/key')\n```\n\n### Configuring source locations dynamically\nIn this use case, environment variables are used to configure the sources for multiple keys.\nThis is useful in more complex applications where lots of values need to be fetched and the source needs to be configured dynamically.\nSee this [contact form handler repository](https://github.com/voquis/aws-lambda-contact-form-handler) for example usage.\n\nEnvironment variables can be appended to the configuration key name, setting the source of the value.\nThese are:\n- `_PARAMETER_STORE_NAME` - for AWS SSM Parameter Store\n- `_SECRETS_MANAGER_NAME` - for AWS Secrets Manager\n\nOne of the available configuration sources for each value must also be set by setting an environment variable ending with `_SOURCE` for the value name:\n- `env` - Environment variables (default)\n- `aws_ssm_parameter_store` - AWS Systems Manager (SSM) Parameter Store\n- `aws_secrets_manager` - AWS Secrets Manager\n\nFor example, to fetch `MY_PARAM` from AWS SSM Parameter Store and `MY_SECRET` from AWS Secrets Manager, consider the following python script (e.g. `app.py`) called subsequently by a shell script:\n\n```python\n# This file is app.py for example\nfrom value_fetcher import ValueFetcher\n\n# Instantiate value fetcher class, with optional defaults if values cannot be found\nfetcher = ValueFetcher({\n 'MY_PARAM': 'Default value if none can be found',\n})\n\n# Retrieve values from supported AWS sources\nmy_secret = fetcher.get('MY_SECRET')\nmy_param = fetcher.get('MY_PARAM')\n\nprint(my_secret)\nprint(my_param)\n```\n\nThe above scripts would be called by the following shell script:\n```shell\n#!/usr/bin/bash\nMY_PARAM_SOURCE=\"aws_ssm_parameter_store\"\nMY_PARAM_PARAMETER_STORE_NAME=\"/my/parameter/store/key/name\"\n\nMY_SECRET_SOURCE=\"aws_secrets_manager\"\nMY_SECRET_SECRETS_MANAGER_NAME=\"my/secrets/manager/key/name\"\n\nexport MY_PARAM_SOURCE MY_PARAM_PARAMETER_STORE_NAME\nexport MY_SECRET_SOURCE MY_SECRET_SECRETS_MANAGER_NAME\n\n# For AWS ensure credentials are available, e.g. with AWS SSO, aws-vault, aws-profile etc.\npython app.py\n```\n\n## Development\nThis project uses Poetry for package management.\nAfter cloning, run:\n```\n./scripts/poetry.sh\n```\nto install dependencies for local development and running tests, etc.\n### Tests\n\nTo run static code analysers and unit tests:\n```\n./scripts/validate.sh\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Fetch a value from various sources, e.g AWS Secrets Manager and SSM Parameter Store",
"version": "1.0.3",
"project_urls": {
"Homepage": "https://github.com/voquis/value-fetcher",
"Issues": "https://github.com/voquis/value-fetcher/issues"
},
"split_keywords": [
"configuration",
" parameters",
" secrets",
" values"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "393f783362d128c3ea7bfbc0800b727debccf055f295ea580db47b9db3e7fa28",
"md5": "ecd3c87ead783041d25824743d3c2486",
"sha256": "29c86b24e7a02c472d51a93d52ef09e0b33e5e61a1a431a174f6e3700c6ecf44"
},
"downloads": -1,
"filename": "value_fetcher-1.0.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ecd3c87ead783041d25824743d3c2486",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5645,
"upload_time": "2024-04-30T10:44:07",
"upload_time_iso_8601": "2024-04-30T10:44:07.192556Z",
"url": "https://files.pythonhosted.org/packages/39/3f/783362d128c3ea7bfbc0800b727debccf055f295ea580db47b9db3e7fa28/value_fetcher-1.0.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "dbea7e4c6137b3f8fb6b8baba747b52ebd5d91856e3f96b6e335c6196e9f21a5",
"md5": "83aeda4a9071cce107aca276ce9ea425",
"sha256": "865ab7b442d2154a19aeb03c82ef62adc4adc3f11d42a8647cf1b26056743260"
},
"downloads": -1,
"filename": "value_fetcher-1.0.3.tar.gz",
"has_sig": false,
"md5_digest": "83aeda4a9071cce107aca276ce9ea425",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 7034,
"upload_time": "2024-04-30T10:44:08",
"upload_time_iso_8601": "2024-04-30T10:44:08.816504Z",
"url": "https://files.pythonhosted.org/packages/db/ea/7e4c6137b3f8fb6b8baba747b52ebd5d91856e3f96b6e335c6196e9f21a5/value_fetcher-1.0.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-30 10:44:08",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "voquis",
"github_project": "value-fetcher",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "value-fetcher"
}