Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

improve vmc module

  • Loading branch information...
commit 4470cd080094c9da8f5c0bd638a0bbc1d37865ac 1 parent 01cb86a
@sunng87 authored
Showing with 46 additions and 6 deletions.
  1. +46 −6 src/karmalet/vmc.clj
View
52 src/karmalet/vmc.clj
@@ -4,14 +4,54 @@
(defn get-env [key]
(System/getenv key))
-(defn mongo-config [key]
+(defn- vmc-service-config [service key]
(if-let [services (get-env "VCAP_SERVICES")]
- (let [services-dict (parse-string services false)]
+ (let [services-dict (parse-string services)]
(-> services-dict
- (get "mongodb-1.8")
+ (get service)
first
- (get "credentials")
- (get key)))))
+ (get :credentials)
+ (get key))))))
+
+(def mongo-config
+ (partial vmc-service-config :mongodb-1.8))
+
+(defn mongo-db []
+ (mongo-config :db))
+(defn mongo-host []
+ (mongo-config :hostname))
+(defn mongo-port []
+ (mongo-config :port))
+(defn mongo-user []
+ (mongo-config :username))
+(defn mongo-passwd []
+ (mongo-config :password))
+
+(def redis-config
+ (partial vmc-service-config :redis-2.2))
+
+(defn redis-password []
+ (redis-config :password))
+(defn redis-host []
+ (redis-config :hostname))
+(defn redis-port []
+ (redis-config :port))
+
+(def mysql-config
+ (partial vmc-service-config :mysql-5.1))
+(defn mysql-host []
+ (mysql-config :hostname))
+(defn mysql-port []
+ (mysql-config :port))
+(defn mysql-user []
+ (mysql-config :user))
+(defn mysql-password []
+ (mysql-config :password))
+
+(def rabbitmq-config
+ (partial vmc-service-config :rabbitmq-2.4))
+(def rabbitmq-url []
+ (rabbitmq-config :url))
(defn vmc? []
- (not (nil? (get-env "VCAP_SERVICES"))))
+ (not (nil? (get-env "VMC_APP_NAME"))))
Please sign in to comment.
Something went wrong with that request. Please try again.