Module: CPRuntime

Included in:
MemcacheClient, MongoClient, MySql2Client, RabbitMQClient, RedisClient
Defined in:
lib/CPRuntime.rb,
lib/cpruntime/MongoClient.rb,
lib/cpruntime/RedisClient.rb,
lib/cpruntime/MySql2Client.rb,
lib/cpruntime/MemcacheClient.rb,
lib/cpruntime/RabbitMQClient.rb

Overview

require ‘cpruntime/rabbitmqclient’ require ‘cpruntime/mongoclient’ require ‘cpruntime/redisclient’ require ‘cpruntime/memcacheclient’

Defined Under Namespace

Classes: MemcacheClient, MongoClient, MySql2Client, RabbitMQClient, RedisClient

Instance Method Summary collapse

Instance Method Details

#credential_map(service_name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/CPRuntime.rb', line 13

def credential_map(service_name)
  credential_map = {}
  svc_env =  ENV['VCAP_SERVICES']
  #svc_env =  '{"mongodb-2.0.20":[{"name":"sz-dedicated-v2_73_mongodb64-ubuntu1004_suzhen","label":"mongodb-2.0.20","plan":"free","credentials":[{"username":"scalr","host":"ec2-23-20-254-0.compute-1.amazonaws.com","password":"uUfigF6Dlq","name":"sz-dedicated-v2_73_mongodb64-ubuntu1004_suzhen","db":"cloudpidb","hostname":"ec2-23-20-254-0.compute-1.amazonaws.com","type":"slave","port":27017},{"username":"scalr","host":"ec2-107-22-7-246.compute-1.amazonaws.com","password":"uUfigF6Dlq","name":"sz-dedicated-v2_73_mongodb64-ubuntu1004_suzhen","db":"cloudpidb","hostname":"ec2-107-22-7-246.compute-1.amazonaws.com","type":"slave","port":27017}]}]}'
  services = JSON.parse(svc_env, :symbolize_names => true)
  services.values.map { |srvs|
    srvs.map{ |svc|
      if svc[:label] =~ /^#{service_name}/
        for i in 0..svc[:credentials].length-1 do
          c_map =  svc[:credentials][i]
          c = Credential.new
          c.username = c_map[:username]
          c.password = c_map[:password]
          c.host = c_map[:host]!=nil ? c_map[:host] : c_map[:host_ip]
          c.port = c_map[:port]
          c.vhost = c_map[:vhost]
          c.db = c_map[:db]!=nil ? c_map[:db] : c_map[:name]
          credential_map[c.host] = c
          #            p c.host
        end
      end
    }
  }
  return credential_map
end