Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use config map in db.clj and scp.clj.

  • Loading branch information...
commit 488cb19caaff44d5c1b678ba9076a265f0ad8e40 1 parent 590254b
@technomancy authored
Showing with 15 additions and 19 deletions.
  1. +1 −0  .gitignore
  2. +11 −17 src/clojars/db.clj
  3. +3 −2 src/clojars/scp.clj
View
1  .gitignore
@@ -2,3 +2,4 @@
*.jar
*.swp
#*
+home
View
28 src/clojars/db.clj
@@ -1,18 +1,12 @@
(ns clojars.db
- (:use clojure.contrib.sql
+ (:use [clojars :only [config]]
+ clojure.contrib.sql
clojure.contrib.duck-streams
[clojure.contrib.str-utils2 :only [join]])
(:import java.security.MessageDigest
java.util.Date
java.io.File))
-;;
-;; TODO: should move this to a config file
-;;
-(def db {:classname "org.sqlite.JDBC"
- :subprotocol "sqlite"
- :subname "/home/clojars/data/db"})
-
-(def key-file "/home/clojars/data/auth_keys")
+
(def ssh-options "no-agent-forwarding,no-port-forwarding,no-pty,no-X11-forwarding")
(def *reserved-names*
@@ -37,7 +31,7 @@
(repeatedly #(rand (count chars))))))))
(defn write-key-file [path]
- (locking key-file
+ (locking (:key-file config)
(let [new-file (File. (str path ".new"))]
(with-query-results rs ["select user, ssh_key from users"]
(with-open [f (writer new-file)]
@@ -51,11 +45,11 @@
(defn db-middleware
[handler]
(fn [request]
- (with-connection db (handler request))))
+ (with-connection (:db config) (handler request))))
(defmacro with-db
[& body]
- `(with-connection db
+ `(with-connection (:db config)
~@body))
(defn sha1 [& s]
@@ -122,7 +116,7 @@
:groups
[:name :user]
[(str "org.clojars." user) user])
- (write-key-file key-file)))
+ (write-key-file (:key-file config))))
(defn update-user [account email user password ssh-key]
(let [salt (rand-string 16)]
@@ -133,7 +127,7 @@
:salt salt
:password (sha1 salt password)
:ssh_key ssh-key})
- (write-key-file key-file)))
+ (write-key-file (:key-file config))))
(defn add-member [group user]
(insert-records :groups
@@ -159,7 +153,7 @@
(throw (Exception. (str "Jar names must consist solely of lowercase "
"letters, numbers, hyphens and underscores."))))
- (with-connection db
+ (with-connection (:db config)
(transaction
(when check-only (set-rollback-only))
(check-and-add-group account (:group jarmap) (:name jarmap))
@@ -190,10 +184,10 @@
(comment
- (with-connection db (add-jar "atotx" {:name "test3" :group "test3" :version "1.0"
+ (with-connection (:db config) (add-jar "atotx" {:name "test3" :group "test3" :version "1.0"
:description "An dog awesome and non-existent test jar."
:homepage "http://clojars.org/"
:authors ["Alex Osborne"
"a little fish"]}))
- (with-connection db (find-user "atotx"))
+ (with-connection (:db config) (find-user "atotx"))
)
View
5 src/clojars/scp.clj
@@ -3,7 +3,8 @@
FileOutputStream)
com.martiansoftware.nailgun.NGContext)
(:use clojure.contrib.duck-streams)
- (:require [clojars.maven :as maven]
+ (:require [clojars]
+ [clojars.maven :as maven]
[clojars.db :as db])
(:gen-class
:methods [#^{:static true}
@@ -121,7 +122,7 @@
(:name jarmap) " " (:version jarmap)))
(db/add-jar (first (.getArgs ctx)) jarmap true)
(maven/deploy-model jarfile model
- "file:///home/clojars/repo")
+ (str "file://" clojars.home "/repo"))
(db/add-jar (first (.getArgs ctx)) jarmap))
(throw (Exception. (str "You need to give me one of: " names)))))
(.println *err* (str "\nSuccess! Your jars are now available from "
Please sign in to comment.
Something went wrong with that request. Please try again.