Mercurial > lbo > hg > goe_bot
changeset 72:8528c88cecad default tip
Read secret token from file, and some other improvements
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Thu, 23 Jan 2020 19:11:05 +0000 |
parents | 8f0bc3d2675d |
children | |
files | handler_remind.go handler_todo.go main.go remind.go scripts/run.sh sql/storage.go |
diffstat | 6 files changed, 27 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/handler_remind.go Thu Jun 29 17:31:16 2017 +0000 +++ b/handler_remind.go Thu Jan 23 19:11:05 2020 +0000 @@ -9,7 +9,7 @@ "strings" "time" - "bitbucket.org/dermesser/goe_bot/sql" + "goe_bot/sql" ) var (
--- a/handler_todo.go Thu Jun 29 17:31:16 2017 +0000 +++ b/handler_todo.go Thu Jan 23 19:11:05 2020 +0000 @@ -7,7 +7,7 @@ "log" "strconv" - _ "bitbucket.org/dermesser/goe_bot/sql" + _ "goe_bot/sql" ) func todoHandler(ctx context.Context, msg message) (replyContent, error) {
--- a/main.go Thu Jun 29 17:31:16 2017 +0000 +++ b/main.go Thu Jan 23 19:11:05 2020 +0000 @@ -2,16 +2,20 @@ import ( "flag" + "fmt" + "io/ioutil" "log" "net/http" + "strings" "time" - "bitbucket.org/dermesser/goe_bot/sql" + "goe_bot/sql" ) var ( // FLAGS - flagToken = flag.String("token", "", "The telegram API token") + flagToken = flag.String("token", "", "The telegram API token (insecure)") + flagTokenFile = flag.String("token_file", "", "file with the token") flagWebhookToken = flag.String("hook_token", "supersecrettoken", "A shared secret authenticating the Telegram API to the bot") flagPullDuration = flag.Uint("pull_ival", 100, "Max duration of hanging pull request") @@ -26,7 +30,7 @@ flagDatabase = flag.String("dbname", "goe_bot", "Database name") flagDBUser = flag.String("dbuser", "goe_bot", "Database user") - flagDBPass = flag.String("dbpass", "", "Database password (please prefer peer authentication!)") + flagDBPass = flag.String("dbpass", "not-that-important-anyway", "Database password (please prefer peer authentication!)") flagDBPort = flag.Uint("dbport", 5432, "Database port") flagDBHost = flag.String("dbhost", "/var/run/postgresql/", "Socket path or address for database") @@ -66,6 +70,16 @@ log.SetFlags(log.Lmicroseconds) flag.Parse() + if *flagTokenFile != "" { + l, err := ioutil.ReadFile(*flagTokenFile) + if err != nil { + fmt.Errorf("%v", err) + return + } + l2 := strings.TrimSpace(string(l)) + *flagToken = l2 + } + if *flagOnlyRegister { if err := registerWebhook(); err != nil { log.Fatal(err)
--- a/remind.go Thu Jun 29 17:31:16 2017 +0000 +++ b/remind.go Thu Jan 23 19:11:05 2020 +0000 @@ -8,7 +8,7 @@ "sync" "time" - "bitbucket.org/dermesser/goe_bot/sql" + "goe_bot/sql" ) var (
--- a/scripts/run.sh Thu Jun 29 17:31:16 2017 +0000 +++ b/scripts/run.sh Thu Jan 23 19:11:05 2020 +0000 @@ -2,10 +2,13 @@ # Contains deployment-specific variables, like secret token ($TOKEN), # webhook token ($HOOKTOKEN) and name ($NAME) -source token.txt +source /home/lbo/go/src/goe_bot/token.txt -./goe_bot --token=$TOKEN \ +PATH=/home/lbo/go/bin:${PATH} + +goe_bot --token_file=/home/lbo/go/src/goe_bot/token2.txt \ --hook_token=$HOOKTOKEN \ --myurl=$HOOKURL \ --tz "Europe/Berlin" \ - $@ >> bot.log 2>&1 + --pull \ + $@ >> /dev/null 2>&1