Created
December 1, 2017 18:05
-
-
Save samudary/846766fac3f0846806f3b8367a98bcc4 to your computer and use it in GitHub Desktop.
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 bash | |
# | |
# drip_ssh_proxy.sh | |
# | |
# Attempts to pull private ip address from hostname pattern. | |
# assumes ruby is present on the system. | |
HOST_PORT="$1" | |
if [[ -z "$HOST_PORT" ]]; then | |
>&2 echo "host:port is required" | |
exit 1 | |
fi | |
USER="${2:-app}" | |
CMD=$( | |
/usr/bin/env ruby <<EORUBY | |
host, port = "$HOST_PORT".split(":") | |
port = "22" unless port | |
re = /\Adrip-([a-z]+)-.+-(\d+)-(\d+)-(\d+)-(\d+)\Z/ | |
m = host.match(re) | |
exit 1 unless m | |
env = m[1] | |
ip = m[2, 4].join(".") | |
proxy_ip = case env | |
when "production" | |
"52.0.68.247" | |
when "staging" | |
"34.202.212.120" | |
else | |
STDERR.puts "Invalid env: #{env}" | |
exit 1 | |
end | |
puts "ssh $USER@#{proxy_ip} -W #{ip}:#{port}" | |
EORUBY | |
) | |
if [[ "$?" -ne "0" ]]; then | |
>&2 echo "Error parsing host:port" | |
exit 1 | |
fi | |
$CMD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment