-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from xeqi/uploads
act as maven repo supporting http uploads
- Loading branch information
Showing
17 changed files
with
407 additions
and
113 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
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,19 @@ | ||
(ns clojars.auth | ||
(:require [cemerick.friend :as friend] | ||
[clojars.db :refer [group-membernames]])) | ||
|
||
(defmacro with-account [body] | ||
`(friend/authenticated (try-account ~body))) | ||
|
||
(defmacro try-account [body] | ||
`(let [~'account (:username (friend/current-authentication))] | ||
~body)) | ||
|
||
(defn authorized? [account group] | ||
(let [names# (group-membernames group)] | ||
(or (some #{account} names#) (empty? names#)))) | ||
|
||
(defmacro require-authorization [group & body] | ||
`(if (authorized? ~'account ~group) | ||
(do ~@body) | ||
(friend/throw-unauthorized friend/*identity*))) |
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
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,17 @@ | ||
(ns clojars.friend.registration | ||
(:require [cemerick.friend :as friend] | ||
[cemerick.friend.workflows :as workflow] | ||
[ring.util.response :refer [response]] | ||
[clojars.web.user :refer [register-form validate-profile]] | ||
[clojars.db :refer [add-user]])) | ||
|
||
(defn register [{:keys [email username password confirm ssh-key]}] | ||
(if-let [errors (validate-profile nil email username password confirm ssh-key)] | ||
(response (register-form errors email username ssh-key)) | ||
(do (add-user email username password ssh-key) | ||
(workflow/make-auth {:identity username :username username})))) | ||
|
||
(defn workflow [{:keys [uri request-method params]}] | ||
(when (and (= uri "/register") | ||
(= request-method :post)) | ||
(register params))) |
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
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,70 @@ | ||
(ns clojars.repo | ||
(:require [clojars.auth :refer [with-account require-authorization]] | ||
[clojars.db :refer [find-jar add-jar update-jar]] | ||
[clojars.config :refer [config]] | ||
[clojars.maven :as maven] | ||
[compojure.core :refer [defroutes PUT ANY]] | ||
[compojure.route :refer [not-found]] | ||
[clojure.java.io :as io] | ||
[clojure.string :as string] | ||
[ring.util.codec :as codec] | ||
[ring.util.response :as response]) | ||
(:import java.io.StringReader)) | ||
|
||
(defn save-to-file [sent-file input] | ||
(-> sent-file | ||
.getParentFile | ||
.mkdirs) | ||
(io/copy input sent-file)) | ||
|
||
(defroutes routes | ||
(PUT ["/:group/:artifact/:file" | ||
:group #".+" :artifact #"[^/]+" :file #"maven-metadata\.xml[^/]*"] | ||
{body :body {:keys [group artifact file]} :params} | ||
(with-account | ||
(require-authorization | ||
(string/replace group "/" ".") | ||
(save-to-file (io/file (config :repo) group artifact file) | ||
body) | ||
{:status 201 :headers {} :body nil}))) | ||
(PUT ["/:group/:artifact/:version/:file" | ||
:group #"[^\.]+" :artifact #"[^/]+" :version #"[^/]+" | ||
:file #"[^/]+(\.pom|\.jar|\.sha1|\.md5)$"] | ||
{body :body {:keys [group artifact version file]} :params} | ||
(let [groupname (string/replace group "/" ".")] | ||
(with-account | ||
(require-authorization | ||
groupname | ||
(try | ||
(let [info {:group groupname | ||
:name artifact | ||
:version version}] | ||
(if (.endsWith file ".pom") | ||
(let [contents (slurp body) | ||
pom-info (merge (maven/pom-to-map | ||
(StringReader. contents)) info)] | ||
(if (find-jar groupname artifact version) | ||
(update-jar account pom-info) | ||
(add-jar account pom-info)) | ||
(save-to-file (io/file (config :repo) group | ||
artifact version file) | ||
contents)) | ||
(do | ||
(when-not (find-jar groupname artifact version) | ||
(add-jar account info)) | ||
(save-to-file (io/file (config :repo) group | ||
artifact version file) | ||
body)))) | ||
{:status 201 :headers {} :body nil} | ||
(catch Exception e | ||
{:status 403 :headers {} :body (.getMessage e)})))))) | ||
(PUT "*" _ {:status 400 :headers {}}) | ||
(not-found "Page not found")) | ||
|
||
(defn wrap-file [app dir] | ||
(fn [req] | ||
(if-not (= :get (:request-method req)) | ||
(app req) | ||
(let [path (codec/url-decode (:path-info req))] | ||
(or (response/file-response path {:root dir}) | ||
(app req)))))) |
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
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
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
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
Oops, something went wrong.