Working with VCAP_SERVICES

Our documentation assumes that your Statica credentials are available in the form of a connection string in the STATICA_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 Statica credentials by extracting them from the VCAP_SERVICES environment variable.


The VCAP_SERVICES entry looks like the following:


 

{"statica":[{"name":"StaticaInstance","label":"statica","tags":[],"plan":"starter","credentials":{"STATICA_URL":STATICA_URL}}]}

 

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 mysqlNode = root.getNode("statica");
JsonNode credentials = mysqlNode.getNode(0).getNode("credentials");
String staticaURL = credentials.getStringValue("STATICA_URL");

 


In Ruby

 

credentials = proxyURL = ''
if !ENV['VCAP_SERVICES'].blank?
  JSON.parse(ENV['VCAP_SERVICES']).each do |k,v|
    if !k.scan("statica").blank?
      credentials = v.first.select {|k1,v1| k1 == "credentials"}["credentials"]
      proxyURL = credentials["STATICA_URL"]
    end
  end
end

 


In Python


 

statica_service = json.loads(os.environ['VCAP_SERVICES'])['statica'][0]
credentials = statica_service['credentials']
statica_url = credentials['STATICA_URL']

 

In Node.js/Javascript

 

var vcap_services = JSON.parse(process.env.VCAP_SERVICES)
var staticaUrl = vcap_services['statica'][0].credentials.STATICA_URL

 

In PHP

 

 $vcap = json_decode(getenv("VCAP_SERVICES"),true);
 $statica_env = $vcap["statica"][0]["credentials"]["STATICA_URL"];