Extract QuotaGuard Static credentials from VCAP_SERVICES

Our documentation assumes that your QuotaGuard Static credentials are available in the form of a connection string in the QUOTAGUARDSTATIC_URL environment variable.

On CloudFoundry based platforms like IBM Bluemix, Pivotal and RedHat Openshift, this is not the case. so you need slightly different code to access your QuotaGuard Static credentials by extracting them from the VCAP_SERVICES environment variable.

The VCAP_SERVICES entry looks like the following:

  "quotaguard": [
      "name": "QuotaGuardInstance",
      "label": "quotaguard",
      "tags": [],
      "plan": "starter",
      "credentials": {
        "QUOTAGUARDSTATIC_URL": "http://username:password@proxy.quotaguard.com:9293"

Extract the variable using the snippets below and then continue with our standard documented solutions.

In Java

String vcapServices = System.getenv("VCAP_SERVICES");
JsonRootNode root = new JdomParser().parse(vcapServices);
JsonNode quotaguardNode = root.getNode("quotaguard");
JsonNode credentials = quotaguardNode.getNode(0).getNode("credentials");
String proxyURL = credentials.getStringValue("QUOTAGUARDSTATIC_URL");

In Ruby

vcapServices = JSON.parse(ENV['VCAP_SERVICES'])
proxyURL = vcapServices['quotaguard'].first.dig('credentials', 'QUOTAGUARDSTATIC_URL')

In Python

service = json.loads(os.environ['VCAP_SERVICES'])['quotaguard'][0]
credentials = service['credentials']
proxy_url = credentials['QUOTAGUARDSTATIC_URL']

In Node.js/Javascript

let vcap_services = JSON.parse(process.env.VCAP_SERVICES)
let proxyUrl = vcap_services.quotaguard[0].credentials.QUOTAGUARDSTATIC_URL


$vcap = json_decode(getenv("VCAP_SERVICES"),true);
$proxy_url = $vcap["quotaguard"][0]["credentials"]["QUOTAGUARDSTATIC_URL"];