From f383ab9a0d8edf52c47253c759914676cf2cce74 Mon Sep 17 00:00:00 2001 From: Teemu Patja Date: Tue, 21 Feb 2017 11:37:55 +0200 Subject: [PATCH] Fix build errors + problem with webhook routes * remove unnecessary servlet context middleware * do not apply unnecessary ring middleware to webhook routes --- src/clj/commiteth/handler.clj | 22 ++++++++++++---------- src/clj/commiteth/middleware.clj | 22 +++------------------- src/clj/commiteth/routes/qrcodes.clj | 3 +-- src/clj/commiteth/routes/webhooks.clj | 13 +++++++------ 4 files changed, 23 insertions(+), 37 deletions(-) diff --git a/src/clj/commiteth/handler.clj b/src/clj/commiteth/handler.clj index 732fb42..ca218f1 100644 --- a/src/clj/commiteth/handler.clj +++ b/src/clj/commiteth/handler.clj @@ -19,18 +19,20 @@ (def app-routes (routes - (-> #'home-routes - (wrap-routes middleware/wrap-csrf) - (wrap-routes middleware/wrap-formats)) - #'redirect-routes #'webhook-routes - #'service-routes - #'qr-routes - (route/not-found + (middleware/wrap-base + (routes + (-> #'home-routes + (wrap-routes middleware/wrap-csrf) + (wrap-routes middleware/wrap-formats)) + #'redirect-routes + #'service-routes + #'qr-routes + (route/not-found (:body - (error-page {:status 404 - :title "page not found"}))))) + (error-page {:status 404 + :title "page not found"}))))))) (defn app [] - (middleware/wrap-base #'app-routes)) + #'app-routes) diff --git a/src/clj/commiteth/middleware.clj b/src/clj/commiteth/middleware.clj index d60f70c..ffbfce9 100644 --- a/src/clj/commiteth/middleware.clj +++ b/src/clj/commiteth/middleware.clj @@ -1,7 +1,7 @@ (ns commiteth.middleware (:require [commiteth.env :refer [defaults]] [clojure.tools.logging :as log] - [commiteth.layout :refer [*app-context* error-page]] + [commiteth.layout :refer [error-page]] [ring.middleware.anti-forgery :refer [wrap-anti-forgery]] [ring.middleware.format :refer [wrap-restful-format]] [commiteth.config :refer [env]] @@ -12,24 +12,9 @@ [buddy.auth.middleware :refer [wrap-authentication wrap-authorization]] [buddy.auth.backends.session :refer [session-backend]] [buddy.auth.accessrules :refer [restrict]] - [buddy.auth :refer [authenticated?]] - [commiteth.layout :refer [*identity*]]) - (:import [javax.servlet ServletContext])) + [buddy.auth :refer [authenticated?]])) -(defn wrap-context [handler] - (fn [request] - (binding [*app-context* - (if-let [context (:servlet-context request)] - ;; If we're not inside a servlet environment - ;; (for example when using mock requests), then - ;; .getContextPath might not exist - (try (.getContextPath ^ServletContext context) - (catch IllegalArgumentException _ context)) - ;; if the context is not specified in the request - ;; we check if one has been specified in the environment - ;; instead - (:app-context env))] - (handler request)))) +(declare ^:dynamic *identity*) (defn wrap-internal-error [handler] (fn [req] @@ -89,6 +74,5 @@ (-> site-defaults (assoc-in [:security :anti-forgery] false) (dissoc :session))) - wrap-context wrap-gzip wrap-internal-error)) diff --git a/src/clj/commiteth/routes/qrcodes.clj b/src/clj/commiteth/routes/qrcodes.clj index 863990e..6e2ab3d 100644 --- a/src/clj/commiteth/routes/qrcodes.clj +++ b/src/clj/commiteth/routes/qrcodes.clj @@ -4,8 +4,7 @@ [commiteth.db.bounties :as bounties] [commiteth.db.comment-images :as comment-images] [commiteth.github.core :as github] - [clojure.tools.logging :as log] - [clojure.java.io :as io]) + [clojure.tools.logging :as log]) (:import [java.io ByteArrayInputStream])) diff --git a/src/clj/commiteth/routes/webhooks.clj b/src/clj/commiteth/routes/webhooks.clj index e29b1a8..cfd7c71 100644 --- a/src/clj/commiteth/routes/webhooks.clj +++ b/src/clj/commiteth/routes/webhooks.clj @@ -152,9 +152,10 @@ (let [raw-payload (slurp body) payload (json/parse-string raw-payload true)] (if (validate-secret payload raw-payload (get headers "x-hub-signature")) - (do (log/debug "Github secret validation OK") - (log/debug "x-github-event" (get headers "x-github-event")) - (case (get headers "x-github-event") - "issues" (handle-issue payload) - "pull_request" (handle-pull-request payload) - (ok))))))) + (do + (log/debug "Github secret validation OK") + (log/debug "x-github-event" (get headers "x-github-event")) + (case (get headers "x-github-event") + "issues" (handle-issue payload) + "pull_request" (handle-pull-request payload) + (ok)))))))