File tree Expand file tree Collapse file tree 5 files changed +48
-6
lines changed Expand file tree Collapse file tree 5 files changed +48
-6
lines changed Original file line number Diff line number Diff line change 5757 (assoc :bundle-id id)
5858 (handler ))
5959 (->
60- (res/response {:message " The bundle you are looking for does not exist" })
60+ (res/response {:message " The bundle you are looking for does not exist. " })
6161 (res/status 404 ))))))
6262
63+ (defn wrap-auth-api-key
64+ " validates the api key from the Authorization header for unauthenticated
65+ users and attaches the bundle-id to the request"
66+ [handler]
67+ (fn [request]
68+ (let [ds (db.util/conn :master )
69+ {:keys [bundle-id user-id]} (validate-request request)
70+ existing-bundle (bundles/bundle ds {:where [:and
71+ [:= :id bundle-id]
72+ [:= :user-id user-id]]})]
73+ (if (some? existing-bundle)
74+ (-> request
75+ (assoc :bundle-id bundle-id)
76+ (handler ))
77+ (-> (res/response {:message " The bundle you are looking for does not exist." })
78+ (res/status 404 ))))))
79+
6380(comment
6481 (let [authed-request {:headers {" Authorization"
6582 (str
115132 (:bundle-id ))))
116133 (println " tests passed" )
117134 (db/delete! ds
118- {:tname :bundles
119- :where [:like :name " test-bundle-%" ]
120- :ret :* }))
135+ {:tname :bundles
136+ :where [:like :name " test-bundle-%" ]
137+ :ret :* }))
121138
122139 ())
Original file line number Diff line number Diff line change 2323 (assoc :store store)
2424 (handler ))))
2525
26- (defn wrap-js
26+ (defn wrap-js
2727 " attaches the provided job service to the handler's request"
2828 [handler js]
2929 (fn [request]
3939 (-> app
4040 (wrap-store store)))
4141
42- (defn apply-js
42+ (defn apply-js
4343 " middleware for attaching the job service to the request"
4444 [app js]
4545 (-> app
9696(defn apply-bundle [app]
9797 (-> app
9898 (auth/wrap-bundle-id )))
99+
100+ (defn apply-api-key [app]
101+ (-> app
102+ (auth/wrap-auth-api-key )))
Original file line number Diff line number Diff line change 1111
1212(defn apply-bundle [app]
1313 (mw/apply-bundle app))
14+
15+ (defn apply-api-key [app]
16+ (mw/apply-api-key app))
Original file line number Diff line number Diff line change 1+ (ns source.routes.integration-key
2+ (:require [source.middleware.auth.util :as auth.util]
3+ [ring.util.response :as res]))
4+
5+ (defn post
6+ {:summary " generate an API key for the integration with the given id"
7+ :parameters {:path [:map [:id {:title " id"
8+ :description " integration id" } :int ]]}
9+ :responses {200 {:body [:map [:key :string ]]}
10+ 401 {:body [:map [:message :string ]]}
11+ 403 {:body [:map [:message :string ]]}}}
12+
13+ [{:keys [user path-params] :as _request}]
14+ (let [api-key (auth.util/sign-jwt {:user-id (:id user)
15+ :bundle-id (:id path-params)})]
16+ (res/response {:key api-key})))
Original file line number Diff line number Diff line change 4040 [source.routes.feed-categories :as feed-categories]
4141 [source.routes.integrations :as integrations]
4242 [source.routes.integration :as integration]
43+ [source.routes.integration-key :as integration-key]
4344 [source.routes.integration-categories :as integration-categories]
4445 [source.routes.bundle :as bundle]
4546 [source.routes.bundle-feeds :as bundle-feeds]
171172 [" /:id"
172173 [" " (route {:get integration/get
173174 :post integration/post})]
175+ [" /key" (route {:post integration-key/post})]
174176 [" /categories" (route {:get integration-categories/get
175177 :post integration-categories/post})]]]
176178
You can’t perform that action at this time.
0 commit comments