allomov
6/17/2015 - 2:46 PM

Target current BOSH's current CF manifest and run nats CLI on its nats configuration

Target current BOSH's current CF manifest and run nats CLI on its nats configuration

#!/bin/bash

# Assumes using nats CLI from https://github.com/soutenniza/nats/releases

DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
cd $DIR/..

bosh_target=$(cat .bosh_config | yaml2json | jq -r ".target")
manifest=$(cat .bosh_config | yaml2json | jq -r ".deployment[\"$bosh_target\"]")
mbus=$(cat $manifest | yaml2json | jq -r '.properties.nats | "nats://\(.user):\(.password)@\(.address):\(.port)"')

command=$1; shift
if [[ "${command}X" == "X" ]]; then
  echo "USAGE: ./bin/nats.sh [pub|sub] ARGS"
  exit 1
fi
nats $command -s $mbus $@