File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ (ns meuse.api.crate )
2+
3+ ; ; the regex for the crates names and versions in path
4+ (def crate-regex #"[a-zA-Z0-9~._+~-]+" )
5+
6+ (def crate-name-path [crate-regex :crate-name ])
7+ (def crate-version-path [crate-regex :crate-version ])
Original file line number Diff line number Diff line change 11(ns meuse.api.crate.http
2- (:require [meuse.api.default :as default ]))
2+ (:require [meuse.api.default :as default ]
3+ [meuse.api.crate :as mac]))
34
45(def skip-auth
56 " Skip token auth for these calls."
89(def crates-routes
910 {#"/new/?" {:put ::new }
1011 #"/?" {:get ::search }
11- [" /" : crate-name #"/owners/?" ] {:put ::add-owner }
12- [" /" : crate-name #"/owners/?" ] {:delete ::remove-owner }
13- [" /" : crate-name #"/owners/?" ] {:get ::list-owners }
14- [" /" : crate-name " /" : crate-version " /yank" ] {:delete ::yank }
15- [" /" : crate-name " /" : crate-version " /unyank" ] {:put ::unyank }
16- [" /" : crate-name " /" : crate-version " /download" ] {:get ::download }
12+ [" /" mac/ crate-name-path #"/owners/?" ] {:put ::add-owner }
13+ [" /" mac/ crate-name-path #"/owners/?" ] {:delete ::remove-owner }
14+ [" /" mac/ crate-name-path #"/owners/?" ] {:get ::list-owners }
15+ [" /" mac/ crate-name-path " /" mac/ crate-version-path " /yank" ] {:delete ::yank }
16+ [" /" mac/ crate-name-path " /" mac/ crate-version-path " /unyank" ] {:put ::unyank }
17+ [" /" mac/ crate-name-path " /" mac/ crate-version-path " /download" ] {:get ::download }
1718 #"/andouillette" ::andouillette })
1819
1920(defmulti crates-api!
Original file line number Diff line number Diff line change 11(ns meuse.api.meuse.http
2- (:require [meuse.api.default :as default ]))
2+ (:require [meuse.api.crate :as mac]
3+ [meuse.api.default :as default ]))
34
45(def skip-auth
56 " Skip token auth for these calls."
1718 #"/token/?" {:get ::list-tokens }
1819 [#"/token/?" ] {:delete ::delete-token }
1920 #"/crate/?" {:get ::list-crates }
20- [#"/crate/?" :name ] {:get ::get-crate }
21+ [#"/crate/?" [mac/crate-regex :name ] ] {:get ::get-crate }
2122 #"/check/?" {:get ::check-crates }
2223 #"/statistics/?" {:get ::statistics }})
2324
Original file line number Diff line number Diff line change 11(ns meuse.api.mirror.http
2- (:require [meuse.api.default :as default ]))
2+ (:require [meuse.api.crate :as mac]
3+ [meuse.api.default :as default ]))
34
45(def skip-auth
56 " Skip token auth for these calls."
67 #{:download })
78
89(def mirror-routes
9- {[" /" : crate-name " /" : crate-version " /download" ] {:get ::download }
10- [" /" : crate-name " /" : crate-version " /cache" ] {:post ::cache }})
10+ {[" /" mac/ crate-name-path " /" mac/ crate-version-path " /download" ] {:get ::download }
11+ [" /" mac/ crate-name-path " /" mac/ crate-version-path " /cache" ] {:post ::cache }})
1112
1213(defmulti mirror-api!
1314 " Handle crates.io api calls"
Original file line number Diff line number Diff line change 1+ (ns meuse.api.crate-test
2+ (:require [clojure.test :refer :all ]
3+ [meuse.api.crate :as mac]))
4+
5+ (deftest crate-regex-test
6+ (are [v] (re-matches mac/crate-regex v)
7+ " foo"
8+ " foo-bar"
9+ " foo_bar"
10+ " foo-1.1.2"
11+ " 1.1.2"
12+ " 1.1.2-alpha"
13+ " 1.1.2_alpha"
14+ " 1.1.2+3.4.5"
15+ " 1.1.2~foo"
16+ " 1.1.2~_-+134.1" )
17+ (are [v] (not (re-matches mac/crate-regex v))
18+ " foo bar"
19+ " foo%bar"
20+ " foo/bar"
21+ " foo\\ bar" ))
You can’t perform that action at this time.
0 commit comments