Skip to content

Instantly share code, notes, and snippets.

@OriPekelman OriPekelman/rels_to_env
Last active Dec 19, 2017

Embed
What would you like to do?
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
@OriPekelman

This comment has been minimized.

Copy link
Owner Author

OriPekelman commented Dec 19, 2017

usage: rels_to_env [relationship name] [environment variable prefix] [start command]

Example:
export_rels mysql DB "java -jar myapp.jar"

output:

export DB_HOST="database.internal”
export DB_PORT=...
export SERVER_PORT=8000
java -jar myapp.jar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.