Small ruby script to export PLATFORM_RELATIONSHIPS as pairs of key, value environment variables and runs the provided command
#!/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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
OriPekelman commentedDec 19, 2017
•
edited