Last active
December 19, 2017 14:02
-
-
Save OriPekelman/34608cf14c5afd823af275f35753d17c to your computer and use it in GitHub Desktop.
Small ruby script to export PLATFORM_RELATIONSHIPS as pairs of key, value environment variables and runs the provided command
This file contains 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 "base64" | |
require "json" | |
if ARGV.length != 3 then #expecting precisely 3 arguments | |
puts "usage: rels_to_env [relationship name] [environment variable prefix] [start command]\n\nExample:\nexport_rels mysql DB \"java -jar myapp.jar\"\n\noutput:\nexport DB_HOST=\"database.internal\”\nexport DB_PORT=...\n" | |
else | |
rels = JSON.parse(Base64.decode64(ENV['PLATFORM_RELATIONSHIPS'])) | |
rel_name= ARGV[0] | |
prefix = ARGV[1] | |
puts "export #{prefix}_HOST=#{rels[rel_name][0]['host']}" | |
puts "export #{prefix}_PORT=#{rels[rel_name][0]['port']}" | |
puts "export #{prefix}_NAME=#{rels[rel_name][0]['path']}" | |
puts "export #{prefix}_USERNAME=#{rels[rel_name][0]['username']}" | |
puts "export #{prefix}_PASSWORD=#{rels[rel_name][0]['password']}" | |
puts "export SERVER_PORT=#{ENV['PORT']}" | |
exec ARGV[2] | |
end | |
Author
OriPekelman
commented
Dec 19, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment