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

add support for modifying content after reading #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

colstrom
Copy link

Describe the change

This is a pretty straightforward one, it just adds the ability to modify the contents of a config file after reading it, but before it gets parsed and merged.

Why are we doing this?

The boring way to use this it to append content to the config or something like that. But there are more fun things you can do with it, like scanning the content to check for any secrets that shouldn't be stored in plaintext, or... this thing that I'm doing:

TTY::Config.new do |config|
  if config.exist?
    config.read do |content|
      if %w[<% %>].all? { |tag| content.include? tag }
        content.replace ERB.new(content).result
      end
    end
  end
end

With a config file like this:

---
github:
  access_token: %x{vault kv get -mount secret -field access-token github}

This allows the config file itself to be an integration point for things like secrets management.

Benefits

The main use case I'm using this for is templating config files, and this small change is enough to allow that.

Drawbacks

This does make use of the implicit block, which would prevent it from being used for something else. An alternate (more complicated) approach would be to add some sort of hooks that could be configured, perhaps passing a proc to those that would be called at the appropriate time. That's... probably more complexity than is needed.

Requirements

  • Tests written & passing locally?
  • Code style checked?
  • Rebased with master branch?
  • Documentation updated?
  • Changelog updated?

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

Successfully merging this pull request may close these issues.

1 participant