This repository has been archived by the owner on Jan 23, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit; basic apps:info and apps:create working.
- Loading branch information
0 parents
commit 9ba711d
Showing
5 changed files
with
121 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/pom.xml | ||
*jar | ||
/lib | ||
/classes | ||
/native | ||
/.lein-failures | ||
/checkouts | ||
/.lein-deps-sum |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# lein-heroku | ||
|
||
A Leiningen plugin for managing your Heroku apps. | ||
|
||
## Usage | ||
|
||
FIXME: write | ||
|
||
## License | ||
|
||
Copyright © 2011 Heroku Inc. | ||
|
||
Distributed under the Eclipse Public License, the same as Clojure. |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(defproject lein-heroku "1.0.0-SNAPSHOT" | ||
:description "Heroku plugin for Leiningen" | ||
:dependencies [[lein-newnew "0.1.0"] | ||
[com.heroku.api/heroku-api "0.1-SNAPSHOT"] | ||
[com.heroku.api/heroku-httpclient "0.1-SNAPSHOT"] | ||
[com.heroku.api/heroku-json-gson "0.1-SNAPSHOT"] | ||
[clj-http "0.2.4"]] | ||
:eval-in-leiningen true) |
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
(ns leiningen.heroku | ||
(:require [clojure.java.io :as io] | ||
[clj-http.core :as http] | ||
[leiningen.help :as help]) | ||
(:import (com.heroku.api.command CommandConfig) | ||
(com.heroku.api.command.login BasicAuthLogin) | ||
(com.heroku.api.connection Connection HttpClientConnection) | ||
(com.heroku.api HerokuAPI HerokuStack))) | ||
|
||
(try ; Leiningen 2.0 compatibility | ||
(use '[leiningen.core :only [abort]]) | ||
(catch Exception _ | ||
(use '[leiningen.main :only [abort]]))) | ||
|
||
(defn- read-password [] | ||
(.readPassword (System/console) "%s" (into-array ["Password: "]))) | ||
|
||
(defn- credentials-file [] | ||
(io/file (System/getProperty "user.home") ".heroku" "credentials")) | ||
|
||
(defn- get-credentials [] | ||
(-> (credentials-file) | ||
(slurp) | ||
(.split "\n"))) | ||
|
||
(defn login [_ & args] | ||
(println "Enter your Heroku credentials.") | ||
(print "Email: ") (flush) | ||
(let [email (read-line) | ||
password (read-password) | ||
command (BasicAuthLogin. email password)] | ||
;; TODO: save to credentials-file | ||
)) | ||
|
||
(defn api [] | ||
(when-not (.exists (credentials-file)) | ||
(login)) | ||
(let [[email key] (get-credentials)] | ||
(-> (BasicAuthLogin. email key) | ||
(HttpClientConnection.) | ||
(HerokuAPI/with)))) | ||
|
||
(defn app-api [] | ||
;; TODO: depends on current directory; should we pass project args around? | ||
(let [git-config (slurp (io/file ".git/config")) | ||
[_ app-name] (re-find #"git@heroku.com:(.+).git" git-config)] | ||
(.app (api) app-name))) | ||
|
||
(defn ^{:no-project-needed true} heroku | ||
"Manage Heroku apps." | ||
[command & args] | ||
(let [command-ns (str "leiningen.heroku." (first (.split command ":"))) | ||
_ (require (symbol command-ns)) | ||
subtask (ns-resolve (symbol command-ns) (symbol command))] | ||
(try | ||
;; TODO: help | ||
(apply subtask args) | ||
(catch Exception e | ||
(abort (.getMessage e)))))) |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(ns leiningen.heroku.apps | ||
(:require [leiningen.heroku :as heroku]) | ||
(:import (com.heroku.api.command.app AppList) | ||
(com.heroku.api Heroku$Stack))) | ||
|
||
(defn create [name] | ||
(-> (heroku/api) (.newapp Heroku$Stack/Cedar name))) | ||
|
||
(defn apps:create [name] | ||
(let [response (create name)] | ||
(println "Created app" (.getAppName response)))) | ||
|
||
(defn apps:destroy []) | ||
|
||
(defn- space-key [k longest-key] | ||
(apply str k ": " (repeat (- longest-key (count k)) " "))) | ||
|
||
(defn apps:info [] | ||
(let [api (heroku/app-api) | ||
info (.info api) | ||
longest-key (apply max (map count (keys info)))] | ||
(println "==" (.getAppName api)) | ||
(doseq [[k v] info] | ||
(println (space-key k longest-key) v)))) | ||
|
||
(defn apps:open []) | ||
|
||
(defn apps:rename [new-name]) | ||
|
||
(defn apps [] | ||
(println "= Heroku Applications") | ||
(doseq [app (-> (heroku/api) .apps .getData)] | ||
(println "*" (.get app "name")))) |