Skip to content

Commit 6fc39f9

Browse files
committed
Allow credentials to be set from a config file
1 parent 53057fa commit 6fc39f9

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

lambda-deploy

+18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
#!/bin/bash
2+
echo "Creating properties file..."
3+
echo
4+
if [ "$GITHUB_TOKEN" = "" ]; then
5+
echo "You must specify a Github token using the env variable \$GITHUB_TOKEN.
6+
If you don't have a token, generate one at https://github.com/settings/tokens"
7+
exit -1
8+
fi
9+
if [ "$SLACK_WEBHOOK_URL" = "" ]; then
10+
echo "You must specify a Slack webhook URL using the env variable \$SLACK_WEBHOOK_URL.
11+
If you don't have one yet, generate it at https://slack.com/apps/new/A0F7XDUAZ-incoming-webhooks"
12+
exit -1
13+
fi
14+
15+
# create a config file with the token and url
16+
echo "github.token=$GITHUB_TOKEN" > resources/config.properties
17+
echo "slack.webhook.url=$SLACK_WEBHOOK_URL" >> resources/config.properties
18+
219
echo "Creating uberjar:"
20+
echo
321

422
lein uberjar
523
cp $PWD/target/uberjar/tako-*-standalone.jar $PWD/target/tako.jar

project.clj

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[cheshire "5.5.0"]
88
[org.julienxx/clj-slack "0.5.2.1"]
99
[org.clojure/tools.logging "0.3.1"]
10+
[clojurewerkz/propertied "1.2.0"]
1011
[com.amazonaws/aws-lambda-java-core "1.1.0"]]
1112
:main ^:skip-aot tako.core
1213
:target-path "target/%s"

resources/config.properties

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
github.token=set when running ./lambda-deploy
2+
slack.webhook.url=set when running ./lambda-deploy

src/tako/core.clj

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
(ns tako.core
22
(:require [tako.github :as github]
33
[tako.slack :as slack]
4+
[clojure.java.io :as io]
5+
[clojurewerkz.propertied.properties :as props]
46
[clojure.tools.logging :refer [info]])
57
(:gen-class
68
:methods [^:static [handler [Object] String]]))
79

8-
(def github-token "PLACE YOUR GITHUB TOKEN HERE")
9-
(def slack-webhook-url "PLACE THE SLACK WEBHOOK URL HERE")
10+
;; read credentials from config file
11+
(def config (-> "config.properties" io/resource props/load-from props/properties->map))
12+
(def github-token (config "github.token"))
13+
(def slack-webhook-url (config "slack.webhook.url"))
1014

1115
(defn -handler
1216
"This is the function called by AWS Lambda"

0 commit comments

Comments
 (0)