Commit 3d385867 authored by phil's avatar phil

initial commit

This diff is collapsed.
# webhooks
FIXME: description
## Installation
Download from
## Usage
FIXME: explanation
$ java -jar webhooks-0.1.0-standalone.jar [args]
## Options
FIXME: listing of options this app accepts.
## Examples
### Bugs
### Any Other Sections
### That You Think
### Might be Useful
## License
Copyright © 2017 FIXME
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.
# Introduction to webhooks
TODO: write [great documentation](
(defproject webhooks "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url ""
:license {:name "Eclipse Public License"
:url ""}
:dependencies [[org.clojure/clojure "1.8.0"]
[org.clojure/tools.cli "0.3.5"]
[http-kit "2.2.0"]]
:main ^:skip-aot webhooks.core
:target-path "target/%s"
:profiles {:uberjar {:aot :all}})
(ns webhooks.core
"webhooks --port 9000 --config webhooks.edn"
(:require [org.httpkit.server :refer [run-server]]
[ :refer [sh]]
[clojure.string :refer [split]]
[clojure.pprint :refer [pprint]]
[ :refer [parse-opts]]))
(defonce options (atom {:options {:port 9000
:config "webhook.edn"
:help false}}))
(defn load-config []
(read-string (slurp (:config (:options @options)))))
(defn handler [req]
(let [config (load-config)
endpoints (filter #(= (:path %) (:uri req)) (:endpoints config))]
(if-not (empty? endpoints)
;; TODO dump payload in file pass file to sh
(doall (map #(apply sh (split (:exec %) #" ")) endpoints))
{:status 200
:headers {"Content-Type" "text/plain"}
:body "200 OK"})
{:status 404
:body (with-out-str
(println "404 Not found (unknown endpoint)")
(pprint req)
(pprint @options))})))
(defonce server (atom nil))
(defn stop-server []
(when-not (nil? @server)
(@server :timeout 100)
(reset! server nil)))
(defn start-server []
(let [port (:port (:options @options))]
(reset! server (run-server #'handler {:port port}))
(println (str "Accepting connections on port " port "."))))
(def cli-options
[["-p" "--port PORT" "Port number"
:default 9000
:parse-fn #(Integer/parseInt %)
:validate [#(< 0 % 0x10000) "Must be a number between 0 and 65536"]]
["-c" "--config" "Config file"
:default "webhooks.edn"]
["-h" "--help"]])
(defn -main [& args]
(reset! options (parse-opts args cli-options))
(if (:help (:options @options))
(println (:summary @options))
(ns webhooks.core-test
(:require [clojure.test :refer :all]
[webhooks.core :refer :all]))
(deftest a-test
(testing "FIXME, I fail."
(is (= 0 1))))
[{:path "/gh/page-build"
:exec "/usr/bin/aplay /usr/share/games/wesnoth/1.10/sounds/slider.wav"}]}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment