├── doc └── intro.md ├── .gitignore ├── test └── claude │ └── core_test.clj ├── project.clj ├── src └── claude │ └── core.clj ├── LICENSE └── README.md /doc/intro.md: -------------------------------------------------------------------------------- 1 | # Introduction to claude 2 | 3 | TODO: write [great documentation](http://jacobian.org/writing/great-documentation/what-to-write/) 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | /lib 3 | /classes 4 | /checkouts 5 | pom.xml 6 | *.jar 7 | *.class 8 | .lein-deps-sum 9 | .lein-failures 10 | .lein-plugins 11 | -------------------------------------------------------------------------------- /test/claude/core_test.clj: -------------------------------------------------------------------------------- 1 | (ns claude.core-test 2 | (:use clojure.test 3 | claude.core)) 4 | 5 | (deftest a-test 6 | (testing "FIXME, I fail." 7 | (is (= 0 1)))) -------------------------------------------------------------------------------- /project.clj: -------------------------------------------------------------------------------- 1 | (defproject claude "0.1.0-SNAPSHOT" 2 | :description "Utilities to connect Clojure apps to Cloud Foundry" 3 | :url "http://example.com/FIXME" 4 | :license {:name "The MIT License" 5 | :url "http://opensource.org/licenses/mit-license.php"} 6 | :dependencies [[org.clojure/clojure "1.4.0"] 7 | [org.clojure/data.json "0.1.3"]] 8 | :plugins [[lein-swank "1.4.4"]]) 9 | -------------------------------------------------------------------------------- /src/claude/core.clj: -------------------------------------------------------------------------------- 1 | (ns claude.core 2 | (:use [clojure.data.json :only [read-json]])) 3 | 4 | (defn cloudfoundry? [] 5 | (not (nil? (System/getenv "VCAP_SERVICES")))) 6 | 7 | (defn service-config [label key] 8 | (if-let [services (System/getenv "VCAP_SERVICES")] 9 | (let [services-dict (read-json services false)] 10 | (-> services-dict 11 | (get label) 12 | first ;; maybe in the future allow to use multiple services 13 | (get "credentials") 14 | (get key))))) 15 | 16 | (defn mongo-config [key] 17 | (service-config "mongodb-2.0" key)) 18 | 19 | (defn rabbit-config [key] 20 | (service-config "rabbitmq-2.4" key)) 21 | 22 | (defn redis-config [key] 23 | (service-config "redis-2.2" key)) 24 | 25 | (defn mongo-url [] 26 | (mongo-config "url")) 27 | 28 | (defn rabbit-url [] 29 | (rabbit-config "url")) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2012 Alvaro Videla 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # claude 2 | 3 | A Clojure library designed to ease integration with Cloud Foundry 4 | 5 | NOTE: Work In Progress 6 | 7 | ## Usage 8 | 9 | With leiningen add it to your project dependencies like this: 10 | 11 | [claude "0.1.0-SNAPSHOT"] 12 | 13 | And with Maven you can do: 14 | 15 | 16 | claude 17 | claude 18 | 0.1.0-SNAPSHOT 19 | 20 | 21 | Then on your code you can use it this way: 22 | 23 | (ns my.namespace 24 | (use: [claude.core :as cf] 25 | [langohr.core :as lhc] 26 | [monger.core :as mg])) 27 | 28 | (defonce default-url "mongodb://127.0.0.1/mydb) 29 | 30 | (defn mongo-connect [] 31 | (if (cf/cloudfoundry?) 32 | (mg/connect-via-uri! (cf/mongo-url)) 33 | (mg/connect-via-uri! default-url))) 34 | 35 | (defn rabbitmq-connect [] 36 | (if (cf/cloudfoundry?) 37 | (lhc/connect (lhc/settings-from (cf/rabbit-url))) 38 | (lhc/connect))) 39 | 40 | (defonce ^Connection conn (rabbitmq-connect)) 41 | 42 | ## TODO 43 | 44 | - Add a proper `groupId` for the Maven repositories 45 | - Improve Integration with Cloud Foundry services 46 | - Improve API for obatining services credentials/info 47 | 48 | ## Credits 49 | 50 | The code is based on this [blog post](http://sunng.info/blog/2012/01/clojure-on-cloudfoundry/). 51 | 52 | ## License 53 | 54 | Copyright © 2012 Alvaro Videla 55 | 56 | See the LICENSE file. 57 | --------------------------------------------------------------------------------