客户端aws机密管理器缓存库
aws-secretsmanager-caching的Python项目详细描述
aws secrets manager python缓存客户端
aws secrets manager python缓存客户端为python应用程序启用了机密的进程内缓存。
开始
必需先决条件
要使用此客户端,您必须具有:
- Python3.6或更新版本。不支持使用3.5或更高版本的Python
- 用于访问存储在aws secrets manager中的机密的amazon web服务(aws)帐户。
若要创建AWS帐户,请转到Sign In or Create an AWS Account,然后选择我是新用户。按照说明创建AWS帐户。
要在aws机密管理器中创建机密,请转到Creating Secrets并按照该页上的说明进行操作。
这个库利用了boto3 SDK的底层核心功能botocore有关boto3和botocore的更多信息,请查看AWS SDK for Python和Botocore文档。
依赖性
此库需要以下标准依赖项:
- Botocore
- 设置工具配置管理
为了进行开发和测试,此库需要以下附加依赖项:
- pytest
- pytest cov
- pytest糖
- codecov
- Pylint
- isort
- 斯芬克斯
请查看requirements.txt
和dev-requirements.txt
文件以了解特定的版本要求。
安装
通过pip安装最新版本
安装最新的开发版本: 假设您安装了python和virtualenv,那么设置您的环境并安装这样的所需依赖项,而不是上面定义的 您可以使用tox在所有受支持的python版本中运行测试。默认情况下,它将运行所有单元测试和集成测试,但您也可以将自己的参数指定为past to 您可以通过: 随后可在 使用客户端包括以下步骤: 可以使用以下参数配置缓存配置对象: 该库还包含几个装饰函数,用基于秘字符串的秘密包装现有函数调用: 我们使用github问题来跟踪bug和缓存库功能请求,并且带宽有限。请使用这些社区资源获取帮助: 此库是根据Apache2.0许可证授权的。$ pip install aws-secretsmanager-caching
$ git clone https://github.com/aws/aws-secretsmanager-caching-python.git
$ cd aws-secretsmanager-caching-python
$ python setup.py install
发展
入门
pip install aws_secretsmanager_caching
:$ git clone https://github.com/aws/aws-secretsmanager-caching-python.git
$ cd aws-secretsmanager-caching-python
$ virtualenv venv
...
$ . venv/bin/activate
$ pip install -r requirements.txt -r dev-requirements.txt
$ pip install -e .
运行测试
pytest
。$ tox # runs integ/unit tests, flake8 tests and pylint tests
$ tox -- test/unit/test_decorators.py # runs specific test file
$ tox -e py37 -- test/integ/ # runs specific test directory
文档
$ tox -e docs
file://${CLONE_DIR}/.tox/docs_out/index.html
查看使用量
SecretCacheConfig()
对象传递给config
参数时实例化客户端。还可以将现有的{{CD8}}客户端传递给客户端参数。importbotocoreimportbotocore.sessionfromaws_secretsmanager_cachingimportSecretCache,SecretCacheConfigclient=botocore.session.get_session().create_client('secretsmanager')cache_config=SecretCacheConfig()# See below for defaultscache=SecretCache(config=cache_config,client=client)secret=cache.get_secret_string('mysecret')
缓存配置
1024
。exception_retry_delay_base
-遇到异常之后和重试请求之前等待的秒数。默认值是1
。exception_retry_growth_factor
-用于计算失败请求重试之间等待时间的增长因子默认值是2
。3600
。default_version_stage
-要请求的默认版本阶段默认值是'AWSCURRENT'
secret_refresh_interval
-刷新缓存的机密信息之间等待的秒数。默认值是3600.0
。secret_cache_hook
-secretcachehook抽象类的实现。默认值是None
。装饰工
@InjectedKeywordedSecretString
-这个装饰器期望secret id和cache作为第一个和第二个参数,随后的参数映射正在包装到secret中的键的函数的参数键。从缓存中检索的机密必须包含机密字符串和该字符串必须基于JSON@InjectSecretString
-这个装饰器还需要secret id和cache作为第一个和第二个参数但是,这个decorator只是将缓存查找的结果直接返回到包装函数的第一个参数机密不需要基于json,但必须包含secretstring。fromaws_secretsmanager_cachingimportSecretCachefromaws_secretsmanager_cachingimportInjectKeywordedSecretString,InjectSecretStringcache=SecretCache()@InjectKeywordedSecretString(secret_id='mysecret',cache=cache,func_username='username',func_password='password')deffunction_to_be_decorated(func_username,func_password):print('Something cool is being done with the func_username and func_password arguments here')...@InjectSecretString('mysimplesecret',cache)deffunction_to_be_decorated(arg1,arg2,arg3):# arg1 contains the cache lookup result of the 'mysimplesecret' secret.# arg2 and arg3, in this example, must still be passed when calling function_to_be_decorated().
得到帮助
许可证
推荐PyPI第三方库