3个版本 (破坏性更新)
0.3.0 | 2023年4月28日 |
---|---|
0.2.0 | 2023年4月28日 |
0.1.0 | 2023年4月28日 |
#514 在 配置
每月下载量 31次
16KB
183 代码行
consul-patch-json
一个用于修补consul中JSON值的工具。
用法
$ consul-patch-json apps/foo/config version='"1.0.0"'
安装
$ cargo install consul-patch-json
Consul配置
以下环境变量用于配置consul交互
CONSUL_HTTP_ADDR
CONSUL_CACERT
CONSUL_CAPATH
CONSUL_CLIENT_CERT
CONSUL_CLIENT_KEY
CONSUL_HTTP_TOKEN
CONSUL_HTTP_SSL_VERIFY
示例
添加属性
$ consul kv put apps/foo/config '{"version": "1.0.0"}'
$ consul-patch-json apps/foo/config description='"My app"'
$ consul kv get apps/foo/config
{"description":"My app","version":"1.0.0"}
替换属性
$ consul kv put apps/foo/config '{"version": "1.0.0"}'
$ consul-patch-json apps/foo/config version='"1.0.1"'
$ consul kv get apps/foo/config
{"version":"1.0.1"}
复杂属性
$ consul kv put apps/foo/config '{"version": "1.0.0"}'
$ consul-patch-json apps/foo/config features='["metrics"]'
$ consul kv get apps/foo/config
{"features":["metrics"],"version":"1.0.0"}
从标准输入读取单个属性
$ consul kv put apps/foo/config '{"version": "1.0.0"}'
$ echo '["coffee"]' | consul-patch-json apps/foo/config features=--
$ consul kv get apps/foo/config
{"features":["coffee"],"version":"1.0.0"}
JSON合并补丁(RFC 7396)
$ consul kv put apps/foo/config '{"version": "1.0.0"}'
$ jo features=$(jo -a coffee metrics) | consul-patch-json apps/foo/config --
$ consul kv get apps/foo/config
{"features":["coffee","metrics"],"version":"1.0.0"}
另请参阅:https://datatracker.ietf.org/doc/html/rfc7396
JSON补丁(RFC 6902)
$ consul kv put apps/foo/config '{"version": "1.0.0","features":["coffee"]}'
$ cat > patch.json <<EOF
[
{"op": "test", "path": "/version", "value": "1.0.0"},
{"op": "add","path": "/features/0", "value": "metrics"}
]
EOF
$ cat patch.json | consul-patch-json apps/foo/config --json-patch --
$ consul kv get apps/foo/config
{"features":["coffee","metrics"],"version":"1.0.0"}
另请参阅:https://datatracker.ietf.org/doc/html/rfc6902
待办事项
- 支持事务
依赖项
~11–26MB
~419K SLoC