This tool is for manipulating the YAML and JSON files. The operations are merging, replacing the key values and adding new values. This can't delete the keys. This uses Helm (https://helm.sh/) to do the manipulation.
This example expects, that helm-yaml-tool.sh
and helm-json-tool.sh
are in PATH
.
helm.sh should be available.
Installation of helm.sh: https://helm.sh/docs/intro/install/
helm-data-yaml.sh [-f <yaml 1> [-f <yaml 2> [-f <json 3> ... ]]] \
[--set key1=val1[,key2=val2...] [--set key3=val3,key4=val4,...]...]
helm-data-json.sh [-f <yaml 1> [-f <yaml 2> [-f <json 3> ... ]]] \
[--set key1=val1[,key2=val2...] [--set key3=val3,key4=val4,...]...]
Parameters:
- -f - This merges all files which are
mentioned with the
-f
flag together. Values could be ein YAML or JSON format. If there is same keys, the later file is overriding all previous ones. (See example.) - --set - This sets the values for the key(s). Values could be in YAML format.
The last --set or -f sets the final value for the key.
RAW usage directly with helm
Additional power of tools comes out when charts are pushed to chartmuseum/similar helm chart versioning system. Then charts are available everywhere where charts repo is defined and usage happened over network without cloning of this git repo. Just helm tool is required.
This is the usage example without the wrapper.
helm repo add helm-data-repo https://theprojectaurora.github.io/helm-data-tool/
helm repo update
helm template -f ./eg_files/set1.yaml -f ./eg_files/set2.yaml \
--set Passwords={},Passwords[0].User=tvesala,Passwords[0].Password=abc \
--set Passwords[1].User=shoisko,Passwords[1].Password=123dsa \
--set Last_set="Dynamically created" helm-data-repo/helm-data-yaml
Output:
---
# Source: helm-data-yaml/templates/values_to_yaml.yaml
Apps:
Set1: Application1
Set2: Application2
Last_set: Dynamically created
Passwords:
- Password: abc
User: tvesala
- Password: 123dsa
User: shoisko
This is the usage example without the wrapper.
helm template -f ./eg_files/set1.yaml -f ./eg_files/set2.yaml \
--set Passwords={},Passwords[0].User=tvesala,Passwords[0].Password=abc \
--set Passwords[1].User=shoisko,Passwords[1].Password=123dsa \
--set Last_set="Dynamically created" helmchart_json/charts
Output:
---
# Source: helm-data-json/templates/values_to_json.yaml
{"Apps":{"Set1":"Application1","Set2":"Application2"},"Last_set":"Dynamically created","Passwords":[{"Password":"abc","User":"tvesala"},{"Password":"123dsa","User":"shoisko"}]}