Skip to content

Instantly share code, notes, and snippets.

@icelander
Last active August 3, 2018 17:35
Show Gist options
  • Save icelander/589c633f5b13e8dd585e912208e8cbdf to your computer and use it in GitHub Desktop.
Save icelander/589c633f5b13e8dd585e912208e8cbdf to your computer and use it in GitHub Desktop.
Converts JSON configuration to environment variable configuration
#!/usr/bin/env ruby
require 'json'
=begin
This converts a Mattermost JSON configuration file to environment variables
More information available here: https://docs.mattermost.com/administration/config-settings.html
To use, download this script and then pipe the config.json file into it, like this:
$ cat /opt/mattermost/config/config.json | json_to_env.rb
=end
def convert_to_env(json, prefix_string)
return_string = ''
json.each do |k, v|
if v.is_a?(Hash)
prefix_string += '_' + k.upcase
return_string += convert_to_env(v, prefix_string)
else
return_string += "#{prefix_string}_#{k.upcase}=\"#{v}\"\n"
end
end
return_string
end
json_string = ARGF.read
json = JSON::parse(json_string)
puts convert_to_env(json, 'MM')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment