adobe / himl

A hierarchical yaml config in Python

Home Page:https://pypi.org/project/himl/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support for multiline line string dump without `\n`

ecojan opened this issue · comments

Python: 3.7.5
Himl: 0.5.0

Current yaml Library configuration used by HIML is treating multiline string dumps with a \n.
This can be improved by adding a scalar_representer to the BaseRepresenter.

eg.
For the following field:

testkey: |-
        # Set to true to log user information returned from LDAP
          verbose_logging = true

          [[servers]]
          # Ldap server host
          host = "someaddress"

          # Default port is 389 or 636 if use_ssl = true
          port = 389

          start_tls = true

will be dumped as:

testkey: "# Set to true to log user information returned from LDAP\n  verbose_logging\
        \ = true\n\n  [[servers]]\n  # Ldap server host\n  host = \"someaddress\"\n\
        \n  # Default port is 389 or 636 if use_ssl = true\n  port = 389\n\n  start_tls\
        \ = true"

Expected result:

testkey: |-
        # Set to true to log user information returned from LDAP
          verbose_logging = true

          [[servers]]
          # Ldap server host
          host = "someaddress"

          # Default port is 389 or 636 if use_ssl = true
          port = 389

          start_tls = true

I tested locally a version that fixes this, let me know if a PR is ok that would support this fix.

I would recomand against what you are trying to do here, storing text blobs or static configs.

Feel free to submit a PR.

I'm storing it at a higher level and using it on lower ones. This can cause issues for certain applications (eg. when loading their configuration).

I would recomand against what you are trying to do here, storing text blobs or static configs.

Can you be more explicit on what you are recommending against?

I would recomand against what you are trying to do here, storing text blobs or static configs.

Can you be more explicit on what you are recommending against?

Storing config blobs, multi line text or unstructured data in a key value.
In the example the config looks like it should be part of the application or other packaging systems like helm.

@ecojan I don't understand why you don't store that static config in helm or somewhere else. And from hiera get the values that change, example maybe the port. From hiera you should only get the values and keys that change and inject them in your templating engine. You instead are using hiera to reinvent that templating engine. cc @amuraru

I'm challenging that this is a use case we want to support. Even if you can do it doesn't mean it's something you should be doing. I'm wary about it.

There are 2 things I want to point out:

  1. Someone using a public helm chart for example, might want to pass a multiline string as a config (some helm charts have this, ex. grafana helm chart for the ldap.toml file)
  2. When using multiline string itself, it's expected to get the same output after using HIML on your structure IF no template is done on said multiline string

The issue described does look like a bug to me and we should fix it, but @danielcoman your recommendation seems legit. Where possible, we should rely on the other tools (ie. helm) to store the config files, and only store simple values in himl. Given @ecojan and team are doing their own thing with himl (in their own repo), they shouldn't be blocked by this bug.