使用yaml的分层配置

himl的Python项目详细描述


HIML

在python中使用yaml的分层配置。

最新版本为:0.2.1

说明

一个python模块,允许您使用yaml语法合并分层配置文件。它提供深度合并、变量插值和秘密管理器的秘密检索。

如果您希望以避免重复的方式构建层次结构,则这是理想的选择。您可以使用层次结构(如environment/project/cluster/app)定义配置的结构。你想在这个层次结构中使用什么层取决于你。该工具将从根(默认值为)开始读取所有yaml文件,一直到叶(最具体的值为,优先)。

这个想法来自木偶的神像。

目录

  1. Installation
  2. Examples
  3. Features

Installation

Using ^{}

^{pr 1}$

From Source

^{pr 2}$

Examples

Using the python module

This will merge simple/default.yaml with simple/production/env.yaml

^{pr 3}$

The above example will merge ^{} with ^{}:

^{pr 4}$

The example also showcases deep merging of lists and maps.

^{}

^{pr 5}$

^{}

^{pr 6}$

Result:

^{pr 7}$

Using the cli

A cli tool called ^{} is automatically installed via ^{}. You can use it to parse a tree of yamls and it will either output the combined configuration at standard output or write it to a file.

^{pr 8}$ ^{pr 9}$

Based on the configuration tree from the examples/complex文件夹,上述命令的输出如下:

cluster:
  description: 'This is cluster: cluster2. It is using c3.2xlarge instance type.'
  name: cluster2
  node_type: c3.2xlarge
region:
  location: us-east-1
env: dev

“示例”文件夹的外观如下:

$ tree examples/complex
examples/complex
├── default.yaml
├── env=dev
│   ├── env.yaml
│   ├── region=us-east-1
│   │   ├── cluster=cluster1
│   │   │   └── cluster.yaml
│   │   ├── cluster=cluster2
│   │   │   └── cluster.yaml
│   │   └── region.yaml
│   └── region=us-west-2
│       ├── cluster=cluster1
│       │   └── cluster.yaml
│       └── region.yaml
└── env=prod
    ├── env.yaml
    └── region=eu-west-2
        ├── cluster=ireland1
        │   └── cluster.yaml
        └── region.yaml

Features

Interpolation

In order to avoid repetition, we wanted to make it possible to define a value once and reuse it in other parts of the yaml config. Unlike yaml anchors, these interpolations work across multiple files.

Interpolating simple values

^{}:

^{pr 12}$

^{}:

^{pr 13}$

Interpolating whole ^{}

^{pr 14}$

Deep merge

It's possible to have the same key (eg. a dict/list) in multiple files and combine them using a deep merge. See an example here

Secrets retrieval

AWS SSM

passphrase:"{{ssm.path(/key/coming/from/aws/secrets/store/manager).aws_profile(myprofile)}}"

Vault

尚未实施。

Merge with Terraform remote state

### Terraform remote states ###remote_states:-name:cluster_compositiontype:terraformaws_profile:"my_aws_profile"s3_bucket:"my_terraform_bucket"s3_key:"mycluster.tfstate"endpoint:"{{outputs.cluster_composition.output.value.redis_endpoint}}"

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何创建比较器   java将所有接口读入列表   java Android Studio在Webview中隐藏特定URL的操作栏   java如何在春季从云存储中生成URL文件而无需持续时间   icalendar如何使用Java以日历格式发送ics电子邮件附件?   如果textfield包含数字,则在运行时进行java检查   java util日志属性中何时需要“.level”?   java在一个字符串中显示json   跨平台日志系统的java Log4j替代方案   coldfusion在Lucee上安装Cassandra Java驱动程序   SpringWebMVC4Java配置不工作   windows使用java程序添加环境变量,并且能够在我从计算机打开“环境”选项卡时看到   java未设置变量和方法   mysql在java中通过查询更改数据库的现有行   java如何使用递归方法查找所有可能的数字   java如何使非原语类成员不可变   java将信息从输入按钮传递到标签