Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YAML support #175

Open
mihai-stancu opened this issue Oct 30, 2024 · 4 comments
Open

YAML support #175

mihai-stancu opened this issue Oct 30, 2024 · 4 comments

Comments

@mihai-stancu
Copy link

Hello,

I saw a tentative successor app that was eventually abandoned back in 2021 ecfg. Are there any (further) plans or alternatives for YAML support?

Currently a few design choices are making working with a wrapper script much harder:

  • not taking input via stdin
  • encrypt not writing output to stdout
  • overall not easy to write a series of pipes as yq -ojson . my.eyaml | ejson encrypt | yq -oyaml . | sponge my.eyaml

So "on the fly conversion" from an eyaml file to ejson to be used with this tool requires a temporary file + writing back into the original file (when encrypting).

Thank you,
Mihai

@mihai-stancu
Copy link
Author

Example wrapper script for YAML:

#!/bin/bash -e

declare -A map;
args=("$@")
for i in "${!args[@]}"; do
  arg="${args[i]}";

  # Guard clause: Skip if not an eYAML file
  [[ ! -f "$arg" ]] && [[ ! $arg =~ *.eyml ]] && [[ ! $arg =~ *.eyml ]] && continue;

  # Temporarily convert eYAML to eJSON
  tmp=$(mktemp eyaml_XXXXXX.ejson);
  trap 'rm -f "$tmp"' EXIT;
  yq -ojson . "$arg" > "$tmp";

  # Replace eYAML file with eJSON file
  args[i]="$tmp";
  map["$arg"]="$tmp";
done

case "$*" in
  # Convert eJSON files back to eYAML
  *"encrypt "*|*" encrypt"*|*" encrypt "*)
    ejson "${args[@]}";
    STATUS="$?";

    for original in "${!map[@]}"; do
        yq -P "${map[$original]}" > "$original";
    done

    exit $STATUS;
  ;;

  # Convert JSON output to YAML
  *"decrypt "*|*" decrypt"*|*" decrypt "*)
    ejson "${args[@]}" | yq -P .;
 ;;

  *)
    ejson "${args[@]}";
  ;;
esac

@thepwagner
Copy link
Contributor

👋 there's nothing planned, but if these features are guarded by new flags/arguments PRs are welcome!

https://github.com/getsops/sops/ supports YAML+JSON among other formats, might be worth checking out.

@mihai-stancu
Copy link
Author

Thank you for the prompt reply & the sops suggestion.

sops doesn't appear to allow team members to add new values, it has a checksum over the entire file and assumes the file will be decrypted when editing (with their handy sops edit somefile.yml).

I'll take a look at the ejson main package to see how hard adding yaml support would be.

Thank you!

@mihai-stancu
Copy link
Author

From the architecture of the package I notice that there's a JSON walker implementation meant to take entries in the order they are found (to avoid randomizing the order of the output).

With that in mind an eyaml implementation would either

  • require a YAML walker implementation that fits the same interface, or
  • load the YAML file into memory, parse it & convert it to JSON, hand it over to the JSON walker implementation

The walker approach seems to dig fairly "deep" into the implementation.
But the in-memory YAML & conversion seems wasteful.

Do you have a go/no-go for either of these?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants