From 829b53ee8c7f295e145ad425fbd300d4bff68553 Mon Sep 17 00:00:00 2001 From: kev Date: Sat, 21 Jan 2017 18:51:37 +0800 Subject: [PATCH] update hubot --- hubot/Dockerfile | 13 ++++----- hubot/README.md | 68 +++++++++++++++++++++++++++++++++++++++++--- hubot/arm/Dockerfile | 2 +- 3 files changed, 71 insertions(+), 12 deletions(-) diff --git a/hubot/Dockerfile b/hubot/Dockerfile index 014c7a7..a02fd10 100644 --- a/hubot/Dockerfile +++ b/hubot/Dockerfile @@ -2,7 +2,7 @@ # Dockerfile for hubot # -FROM node:slim +FROM alpine MAINTAINER kev ENV HUBOT_NAME=Hubot @@ -11,11 +11,9 @@ ENV HUBOT_DESCRIPTION=$HUBOT_NAME-$HUBOT_ADAPTER ENV HUBOT_SLACK_TOKEN= RUN set -xe \ - && npm install -g coffee-script \ - generator-hubot \ - hubot \ - yo \ - && useradd -m -s /bin/bash hubot + && apk add --update ca-certificates nodejs \ + && npm install -g yo generator-hubot \ + && adduser -s /bin/sh -D hubot USER hubot WORKDIR /home/hubot @@ -28,6 +26,7 @@ RUN set -xe \ && npm install hubot-$HUBOT_ADAPTER --save \ && sed -i -r 's/^\s+#//' scripts/example.coffee -VOLUME /home/hobot/scripts +VOLUME /home/hobot +EXPOSE 8080 CMD ["./bin/hubot", "--adapter", "slack"] diff --git a/hubot/README.md b/hubot/README.md index e33a746..06dd146 100644 --- a/hubot/README.md +++ b/hubot/README.md @@ -4,7 +4,7 @@ hubot ![](https://badge.imagelayers.io/vimagick/hubot:latest.svg) [Hubot][1] is a customizable, life embetterment robot commissioned by github. -Hubot's power comes through [scripts][3]. +Hubot's power comes through [scripts][2]. ## docker-compse.yml @@ -15,11 +15,71 @@ hubot: - ./data:/home/hubot/scripts environment: - HUBOT_SLACK_TOKEN=xoxb-xxxxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx + - HUBOT_AUTH_ADMIN=UXXXXXXXX restart: always ``` -> Goto [here][2] to generate `HUBOT_SLACK_TOKEN`. +- Click [this][3] to generate `HUBOT_SLACK_TOKEN`. +- Click [this][4] to get `HUBOT_AUTH_ADMIN`. + +## up and running + +```bash +$ docker-compose up -d +$ docker-compose exec hubot sh +>>> npm install --save hubot-auth +>>> vi external-scripts.json +>>> exit +$ vi data/example.coffee +$ docker-compose restart +``` + +```coffee +module.exports = (robot) -> + + robot.respond /who is @?([\w .\-]+)\?*$/i, (res) -> + name = res.match[1].trim() + users = robot.brain.usersForFuzzyName(name) + for user in users + delete user['slack'] + user = JSON.stringify user, null, 2 + res.send "```#{user}```" + + robot.respond /shell:?\s+(.+)/i, (res) -> + cmd = res.match[1] + user = robot.brain.userForName(res.message.user.name) + if robot.auth.hasRole(user, ["ops"]) + cp = require "child_process" + cp.exec cmd, (error, stdout, stderr) -> + res.send "```#{stdout}```" if stdout + res.send "```#{stderr}```" if stderr + else + res.reply "Access Denied!" +``` + +## chat-ops + +``` +kevin [5:25 PM] what roles do I have +hubot [5:25 PM] kevin has the following roles: admin. + +kevin [5:24 PM] who is kevin +hubot [5:24 PM] { "id": "UXXXXXXXX", "name": "kevin" } + +kevin [5:26 PM] kevin has ops role +hubot [5:26 PM] OK, kevin has the 'ops' role. + +kevin [5:27 PM] shell date +hubot [5:27 PM] Sat Jan 21 10:08:28 UTC 2017 + +kevin [5:28 PM] kevin doesn't have ops role +hubot [5:28 PM] OK, kevin doesn't have the 'ops' role. + +kevin [5:29 PM] shell date +hubot [5:29 PM] Access Denied! +``` [1]: https://hubot.github.com/ -[2]: https://my.slack.com/services/new/hubot -[3]: https://hubot.github.com/docs/scripting/ +[2]: https://hubot.github.com/docs/scripting/ +[3]: https://my.slack.com/services/new/hubot +[4]: https://api.slack.com/methods/users.list/test diff --git a/hubot/arm/Dockerfile b/hubot/arm/Dockerfile index 3e0d92a..37e03ea 100644 --- a/hubot/arm/Dockerfile +++ b/hubot/arm/Dockerfile @@ -26,7 +26,7 @@ RUN set -xe \ && npm install hubot-$HUBOT_ADAPTER --save \ && sed -i -r 's/^\s+#//' scripts/example.coffee -VOLUME /home/hobot/scripts +VOLUME /home/hobot EXPOSE 8080 CMD ["./bin/hubot", "--adapter", "slack"]