Last active
August 3, 2018 17:35
-
-
Save icelander/589c633f5b13e8dd585e912208e8cbdf to your computer and use it in GitHub Desktop.
Converts JSON configuration to environment variable configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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