Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moves service specific code to their own namespace
- Loading branch information
1 parent
70b46a8
commit fcfe64d
Showing
1 changed file
with
17 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
(ns claude.core | ||
(:use [clojure.data.json :only [read-json]])) | ||
|
||
(defn get-vcap-env [] | ||
(System/getenv "VCAP_SERVICES")) | ||
|
||
(defn get-vcap-services [] | ||
(if-let [services (get-vcap-env)] | ||
(read-json services false))) | ||
|
||
(defn cloudfoundry? [] | ||
(not (nil? (System/getenv "VCAP_SERVICES")))) | ||
(not (nil? (get-vcap-env)))) | ||
|
||
(defn service-config [label key] | ||
(if-let [services (System/getenv "VCAP_SERVICES")] | ||
(let [services-dict (read-json services false)] | ||
(let [services-dict (get-vcap-services)] | ||
(-> services-dict | ||
(get label) | ||
first ;; maybe in the future allow to use multiple services | ||
(get "credentials") | ||
(get key))))) | ||
|
||
(defn mongo-config [key] | ||
(service-config "mongodb-2.0" key)) | ||
|
||
(defn rabbit-config [key] | ||
(service-config "rabbitmq-2.4" key)) | ||
(get key)))) | ||
|
||
(defn redis-config [key] | ||
(service-config "redis-2.2" key)) | ||
(defn services-labels [] | ||
(keys (get-vcap-services))) | ||
|
||
(defn mongo-url [] | ||
(mongo-config "url")) | ||
(defmacro service-value [service key] | ||
`(defn ~(symbol key) [] (service-config ~service ~key))) | ||
|
||
(defn rabbit-url [] | ||
(rabbit-config "url")) | ||
(defmacro expose-service [service keys] | ||
`(do | ||
~@(map #(list 'service-value service %) keys))) |