From 4c706a712a540e6c116ab45b399e5b27b6021bc0 Mon Sep 17 00:00:00 2001 From: jspc Date: Sat, 1 Oct 2022 15:32:09 +0100 Subject: [PATCH 1/6] Allow instances to override messages Given this project no longer powers a single bot for a single purpose, and in view of wanting to make this project useful for opensource users, we now provide some default messages and a mechanism for loading specific messages from the env. --- Makefile | 5 +-- client_test.go | 8 ++-- config.gen.go | 13 ------- config.go | 25 +++++++++++++ config.toml | 28 -------------- config_test.go | 12 ++++++ gen/main.go | 76 -------------------------------------- gen/main_test.go | 79 ---------------------------------------- gen/testdata/config.toml | 4 -- gen/testdata/empty.toml | 0 10 files changed, 42 insertions(+), 208 deletions(-) delete mode 100644 config.gen.go create mode 100644 config.go delete mode 100644 config.toml create mode 100644 config_test.go delete mode 100644 gen/main.go delete mode 100644 gen/main_test.go delete mode 100644 gen/testdata/config.toml delete mode 100644 gen/testdata/empty.toml diff --git a/Makefile b/Makefile index 609c76a..ed5dec8 100644 --- a/Makefile +++ b/Makefile @@ -5,13 +5,10 @@ COSIGN_SECRET ?= cosign.key default: app -app: *.go go.mod go.sum config.gen.go +app: *.go go.mod go.sum go build -o $@ -ldflags="-s -w -linkmode=external -X main.LogLevel=$(LOGLVL)" -buildmode=pie -trimpath upx $@ -config.gen.go: config.toml gen/main.go - go run gen/main.go -f $< > $@ - .PHONY: docker-build docker-push docker-build: docker build --label "tag=$(TAG)" --label "bom=https://github.com/gender-equality-community/gec-bot/releases/download/$(TAG)/bom.json" --build-arg logLevel=$(LOGLVL) -t $(IMG):$(TAG) . diff --git a/client_test.go b/client_test.go index 9d6e11f..c735100 100644 --- a/client_test.go +++ b/client_test.go @@ -90,11 +90,11 @@ func TestClient_Handle(t *testing.T) { }{ {"Messages from me should be ignored", new(dummyClient), new(dummyRedis), &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: true, Sender: dummyJid()}, ID: "123"}}, false, ""}, {"Redis errors should bomb out, but not mark read", new(dummyClient), &dummyRedis{err: true}, &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}}, false, ""}, - {"Greetings should be recognised as such", new(dummyClient), new(dummyRedis), &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}, Message: &waProto.Message{Conversation: stringRef("Hello!")}}, true, "Hello, and welcome to the Anonymous GEC Advisor. What's on your mind?"}, + {"Greetings should be recognised as such", new(dummyClient), new(dummyRedis), &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}, Message: &waProto.Message{Conversation: stringRef("Hello!")}}, true, greetingResponse}, {"Where we've already messaged someone, don't message again", new(dummyClient), &dummyRedis{idExists: true}, &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}, Message: &waProto.Message{Conversation: stringRef("I would like to talk to somebody please")}}, true, ""}, - {"Where we've not messaged someone recently, message again", new(dummyClient), &dummyRedis{idExists: false}, &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}, Message: &waProto.Message{Conversation: stringRef("I would like to talk to somebody please")}}, true, "Thank you for your message, please provide as much information as you're comfortable sharing and we'll get back to you as soon as we can."}, - {"Brand new recipients should get a new ID", new(dummyClient), &dummyRedis{noJID: true}, &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}, Message: &waProto.Message{Conversation: stringRef("Hello!")}}, true, "Hello, and welcome to the Anonymous GEC Advisor. What's on your mind?"}, - {"Messages using new format should work fine", new(dummyClient), &dummyRedis{noJID: true}, &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}, Message: &waProto.Message{ExtendedTextMessage: &waProto.ExtendedTextMessage{Text: stringRef("Hi!")}}}, true, "Hello, and welcome to the Anonymous GEC Advisor. What's on your mind?"}, + {"Where we've not messaged someone recently, message again", new(dummyClient), &dummyRedis{idExists: false}, &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}, Message: &waProto.Message{Conversation: stringRef("I would like to talk to somebody please")}}, true, thankyouResponse}, + {"Brand new recipients should get a new ID", new(dummyClient), &dummyRedis{noJID: true}, &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}, Message: &waProto.Message{Conversation: stringRef("Hello!")}}, true, greetingResponse}, + {"Messages using new format should work fine", new(dummyClient), &dummyRedis{noJID: true}, &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}, Message: &waProto.Message{ExtendedTextMessage: &waProto.ExtendedTextMessage{Text: stringRef("Hi!")}}}, true, greetingResponse}, {"Messages where no message is found should be dropped", new(dummyClient), &dummyRedis{noJID: true}, &events.Message{Info: types.MessageInfo{MessageSource: types.MessageSource{IsFromMe: false, Sender: dummyJid()}, ID: "123"}, Message: &waProto.Message{}}, false, ""}, } { t.Run(test.name, func(t *testing.T) { diff --git a/config.gen.go b/config.gen.go deleted file mode 100644 index b469d56..0000000 --- a/config.gen.go +++ /dev/null @@ -1,13 +0,0 @@ -// Code generated from gen/main.go DO NOT EDIT - -package main - -// Greeting response is sent when a recipient sends a message sends us a greeting -const greetingResponse = "Hello, and welcome to the Anonymous GEC Advisor. What's on your mind?" - -// Thank You response is sent when a recipient sends us a message and is capped at a max of 1 per 30 mins -const thankyouResponse = "Thank you for your message, please provide as much information as you're comfortable sharing and we'll get back to you as soon as we can." - -// Disclaimer response is sent to ensure recipients don't send us stuff we can't deal with. -const disclaimerResponse = "DISCLAIMER: This is not an incident reporting service. If you believe you're being subjected to bullying, harassment, or misconduct then we cannot escalate on your behalf but we can advise you on your next steps." - diff --git a/config.go b/config.go new file mode 100644 index 0000000..e4c7c0b --- /dev/null +++ b/config.go @@ -0,0 +1,25 @@ +package main + +import "os" + +var ( + // Greeting response is sent when a recipient sends a message sends us a greeting + greetingResponse = Lookup("GREETING", "Hello, my name is Ada. What's on your mind?") + + // Thank You response is sent when a recipient sends us a message and is capped at a max of 1 per 30 mins + thankyouResponse = Lookup("THANK_YOU", "Thank you for your message, please provide as much information as you're comfortable sharing and I'll get back to you as soon as I can.") + + // Disclaimer response is sent to ensure recipients don't send us stuff we can't deal with. + disclaimerResponse = Lookup("DISCLAIMER", "DISCLAIMER: This is not an incident reporting service. If you believe you're being subjected to bullying, harassment, or misconduct then I cannot escalate on your behalf but I can advise you on your next steps.") +) + +// Lookup accepts an environment variable name and a default value. +// If the variable exists and is set, then Lookup returns that, +// otherwise Lookup returns the default value +func Lookup(v, d string) string { + s, ok := os.LookupEnv(v) + if ok { + return s + } + return d +} diff --git a/config.toml b/config.toml deleted file mode 100644 index 51bdd7c..0000000 --- a/config.toml +++ /dev/null @@ -1,28 +0,0 @@ -# This file is used to generate the file `config.gen.go`; we compile these phrases into the binary -# (rather than allowing for a separate runtime configuration options) purely because it makes -# distribution and start up a little easier for us. -# -# The only reason to have this seperate file, rather than storing this in source, is so these -# things can be edited and maintained by people who feel less confident editing source code. - -[responses] -# Greeting Response is sent when a recipient sends a message that looks vaguely like -# a greeting. -# -# To understand what this might look like, take a look in phrases.go -greeting = "Hello, and welcome to the Anonymous GEC Advisor. What's on your mind?" - -# Thank You response is sent when a recipient sends us a message. -# -# To keep this from spamming the hell out of people, we only send a maximum of 1 -# response per 30 minutes. -# -# Essentially, when a message comes in, we check whether we've responded in the last -# 30 minutes and if we haven't then we send another -thankyou = "Thank you for your message, please provide as much information as you're comfortable sharing and we'll get back to you as soon as we can." - -# Disclaimer response is sent to ensure recipients don't send us things we can't, or aren't allowed to, deal with. -# -# In much the same way as we only send a Thank You every 30 mins or less, we only send the -# disclaimer once every 24 hours. -disclaimer = "DISCLAIMER: This is not an incident reporting service. If you believe you're being subjected to bullying, harassment, or misconduct then we cannot escalate on your behalf but we can advise you on your next steps." diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..395e2d8 --- /dev/null +++ b/config_test.go @@ -0,0 +1,12 @@ +package main + +import ( + "testing" +) + +func TestLookup(t *testing.T) { + got := Lookup("__AN_UNSET_KEY_HOPEFULLY", "<3") + if got != "<3" { + t.Errorf("unexpected value %q", got) + } +} diff --git a/gen/main.go b/gen/main.go deleted file mode 100644 index 8280884..0000000 --- a/gen/main.go +++ /dev/null @@ -1,76 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "os" - "strings" - - "github.com/BurntSushi/toml" - "github.com/dave/jennifer/jen" -) - -const output = "config.gen.go" - -var config = flag.String("f", "config.toml", "configuration file to load") - -// Responses holds our default responses -type Responses struct { - Greeting string - Thankyou string - Disclaimer string -} - -// Config holds the loaded configuration from our input file -type Config struct { - Responses Responses -} - -func main() { - flag.Parse() - - c, err := readToml(*config) - if err != nil { - panic(err) - } - - f, err := generate(c) - if err != nil { - panic(err) - } - - fmt.Println(f) -} - -func readToml(f string) (c Config, err error) { - //#nosec - cf, err := os.ReadFile(f) - if err != nil { - return - } - - _, err = toml.Decode(string(cf), &c) - - return -} - -func generate(c Config) (out string, err error) { - f := jen.NewFile("main") - f.HeaderComment("Code generated from gen/main.go DO NOT EDIT ") - - f.Comment("Greeting response is sent when a recipient sends a message sends us a greeting") - f.Const().Id("greetingResponse").Op("=").Lit(c.Responses.Greeting) - - f.Comment("Thank You response is sent when a recipient sends us a message and is capped at a max of 1 per 30 mins") - f.Const().Id("thankyouResponse").Op("=").Lit(c.Responses.Thankyou) - - f.Comment("Disclaimer response is sent to ensure recipients don't send us stuff we can't deal with.") - f.Const().Id("disclaimerResponse").Op("=").Lit(c.Responses.Disclaimer) - - buf := strings.Builder{} - - err = f.Render(&buf) - out = buf.String() - - return -} diff --git a/gen/main_test.go b/gen/main_test.go deleted file mode 100644 index 3a88741..0000000 --- a/gen/main_test.go +++ /dev/null @@ -1,79 +0,0 @@ -package main - -import ( - "reflect" - "testing" - - "github.com/google/go-cmp/cmp" -) - -var ( - happyConfig = Config{ - Responses: Responses{ - Greeting: "Hi there!", - Thankyou: "Thanks!", - Disclaimer: "We can't do that!", - }, - } -) - -func TestReadToml(t *testing.T) { - for _, test := range []struct { - name string - fn string - expect Config - expectError bool - }{ - {"Config file does not exist", "testdata/nonsuch.toml", Config{}, true}, - {"Config file exists but is empty", "testdata/empty.toml", Config{}, false}, - {"Config file exists and has content", "testdata/config.toml", happyConfig, false}, - } { - t.Run(test.name, func(t *testing.T) { - got, err := readToml(test.fn) - if err != nil && !test.expectError { - t.Errorf("unexpected error: %v", err) - } else if err == nil && test.expectError { - t.Error("expected error") - } - - if !reflect.DeepEqual(test.expect, got) { - t.Errorf("expected %#v, received %#v", test.expect, got) - } - }) - } -} - -func TestGenerate(t *testing.T) { - expect := `// Code generated from gen/main.go DO NOT EDIT - -package main - -// Greeting response is sent when a recipient sends a message sends us a greeting -const greetingResponse = "Hi there!" - -// Thank You response is sent when a recipient sends us a message and is capped at a max of 1 per 30 mins -const thankyouResponse = "Thanks!" - -// Disclaimer response is sent to ensure recipients don't send us stuff we can't deal with. -const disclaimerResponse = "We can't do that!" -` - got, err := generate(happyConfig) - if err != nil { - t.Errorf("expected error") - } - - if expect != got { - t.Errorf(cmp.Diff(expect, got)) - } -} - -func TestMain(t *testing.T) { - defer func() { - err := recover() - if err == nil { - t.Error("expected error") - } - }() - - main() -} diff --git a/gen/testdata/config.toml b/gen/testdata/config.toml deleted file mode 100644 index 3a83189..0000000 --- a/gen/testdata/config.toml +++ /dev/null @@ -1,4 +0,0 @@ -[responses] -greeting = "Hi there!" -thankyou = "Thanks!" -disclaimer = "We can't do that!" diff --git a/gen/testdata/empty.toml b/gen/testdata/empty.toml deleted file mode 100644 index e69de29..0000000 From a538526a1f0531a227da2492f792ef5ae13d1b7b Mon Sep 17 00:00:00 2001 From: jspc Date: Sat, 1 Oct 2022 16:07:11 +0100 Subject: [PATCH 2/6] Ensure expected environment variables exist --- .github/workflows/ci.yml | 2 +- Makefile | 6 ++++++ config.go | 19 +++++++++++++++++++ config_test.go | 11 +++++++++++ main.go | 4 +--- 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9157bea..f97112b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -26,7 +26,7 @@ jobs: run: go build -v ./... - name: Test - run: go test -v -covermode=count -coverprofile=coverage.out ./... + run: make test - name: gosec run: | diff --git a/Makefile b/Makefile index ed5dec8..fe7cbba 100644 --- a/Makefile +++ b/Makefile @@ -18,3 +18,9 @@ docker-push: .image: echo $(IMG):$(TAG) > $@ + +.PHONY: test +test: export DATABASE = /tmp/testing.db +test: export REDIS_ADDR = redis://redis.example.com:6379 +test: + go test -v -covermode=count -coverprofile=coverage.out ./... diff --git a/config.go b/config.go index e4c7c0b..12b4b3c 100644 --- a/config.go +++ b/config.go @@ -11,6 +11,12 @@ var ( // Disclaimer response is sent to ensure recipients don't send us stuff we can't deal with. disclaimerResponse = Lookup("DISCLAIMER", "DISCLAIMER: This is not an incident reporting service. If you believe you're being subjected to bullying, harassment, or misconduct then I cannot escalate on your behalf but I can advise you on your next steps.") + + // DB is the location, on disk, of the database to use + db = MustLookup("DATABASE") + + // Redis Address is the network address of the redis instance to use + redisAddr = MustLookup("REDIS_ADDR") ) // Lookup accepts an environment variable name and a default value. @@ -23,3 +29,16 @@ func Lookup(v, d string) string { } return d } + +// MustLookup accepts and enviroment variable nae and returns +// the value of that. +// +// Should the var be unset or empty, MustLookup panics +func MustLookup(v string) (s string) { + s = os.Getenv(v) + if s == "" { + panic("Environment variable " + v + " is empty or unset") + } + + return +} diff --git a/config_test.go b/config_test.go index 395e2d8..b470ec4 100644 --- a/config_test.go +++ b/config_test.go @@ -10,3 +10,14 @@ func TestLookup(t *testing.T) { t.Errorf("unexpected value %q", got) } } + +func TestMustLookup(t *testing.T) { + defer func() { + err := recover() + if err == nil { + t.Error("expected panic, received none") + } + }() + + MustLookup("__AN_UNSET_KEY_HOPEFULLY") +} diff --git a/main.go b/main.go index 1826804..341bc93 100644 --- a/main.go +++ b/main.go @@ -13,9 +13,7 @@ import ( ) var ( - LogLevel = "DEBUG" - db = os.Getenv("DATABASE") - redisAddr = os.Getenv("REDIS_ADDR") + LogLevel = "DEBUG" boottime time.Time ) From 18694ec74dc5db2aedf79f865c60d2353e709663 Mon Sep 17 00:00:00 2001 From: jspc Date: Sat, 1 Oct 2022 16:18:11 +0100 Subject: [PATCH 3/6] Document configuration and responses --- README.md | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f7aceb5..01d81a6 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,30 @@ The GEC Bot does two things: ![Infrastructure diagram showing how GEC components talk to one another](doc/gec-bots-arch.svg) +## Configuration + +### Required environment variables + +```bash +$ export REDIS_ADDR=redis:6379 +$ export DATABASE=/tmp/database.db # Created if it doesn't exist +``` + +### Auto-responses + +This bot provides some default messages, defined in [`config.go`](config.go) + +1. Greeting response is sent when a recipient sends a message sends us a greeting +1. Thank You response is sent when a recipient sends us a message and is capped at a max of 1 per 30 mins +1. Disclaimer response is sent to ensure recipients don't send us stuff we can't deal with. + +These can be overrided with the following respective environment variables: + +```bash +$ export GREETING="Hello <3" +$ export THANK_YOU="Thanks! We'll get back to you" +$ export DISCLAIMER="Be aware that there's stuff we can't do!" +``` ## Anonymisation @@ -38,13 +62,6 @@ We then check whether this ID is already present in our database. This gives key overhand-subdivide-thaw promotion-basically-unreal clumsily-tag-gizmo -return-lyricist-sixtieth -helmet-gothic-linguist -frugality-pediatric-overstate -subzero-plastic-sadness -sliding-dairy-sleet -endurance-ferry-election -unlatch-childhood-gristle ``` These are used to group messages from a recipient later on, through slack. @@ -60,8 +77,7 @@ This application passes messages along via redis streams; these are lightweight, ## Deployment -Deployments are manual for now. - +See the [Gender Equality Community kubernetes operator](https://github.com/gender-equality-community/gec-operator) ## License -[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fgender-equality-community%2Fgec-bot.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fgender-equality-community%2Fgec-bot?ref=badge_large) \ No newline at end of file +[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fgender-equality-community%2Fgec-bot.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Fgender-equality-community%2Fgec-bot?ref=badge_large) From 2cbf62b0b81da101245238b71fdb9452c22a88f3 Mon Sep 17 00:00:00 2001 From: jspc Date: Sat, 1 Oct 2022 16:19:14 +0100 Subject: [PATCH 4/6] Remove unused dependencies --- go.mod | 3 --- go.sum | 28 +++++++++++----------------- 2 files changed, 11 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index 56b8720..e12dfb6 100644 --- a/go.mod +++ b/go.mod @@ -3,11 +3,8 @@ module github.com/gender-equality-community/gec-bot go 1.19 require ( - github.com/BurntSushi/toml v1.2.0 github.com/agnivade/levenshtein v1.1.1 - github.com/dave/jennifer v1.5.1 github.com/go-redis/redis/v9 v9.0.0-beta.2 - github.com/google/go-cmp v0.5.8 github.com/mattn/go-sqlite3 v1.14.15 github.com/mdp/qrterminal v1.0.1 github.com/rs/xid v1.4.0 diff --git a/go.sum b/go.sum index 63b86fb..00c4e51 100644 --- a/go.sum +++ b/go.sum @@ -1,54 +1,48 @@ filippo.io/edwards25519 v1.0.0 h1:0wAIcmJUqRdI8IJ/3eGi5/HwXZWPujYXXlkrQogz0Ek= filippo.io/edwards25519 v1.0.0/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns= -github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0= -github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/agnivade/levenshtein v1.1.1 h1:QY8M92nrzkmr798gCo3kmMyqXFzdQVpxLlGPRBij0P8= github.com/agnivade/levenshtein v1.1.1/go.mod h1:veldBMzWxcCG2ZvUTKD2kJNRdCk5hVbJomOvKkmgYbo= +github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0 h1:jfIu9sQUG6Ig+0+Ap1h4unLjW6YQJpKZVmUzxsD4E/Q= github.com/arbovm/levenshtein v0.0.0-20160628152529-48b4e1c0c4d0/go.mod h1:t2tdKJDJF9BV14lnkjHmOQgcvEKgtqs5a1N3LNdJhGE= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE= github.com/cespare/xxhash/v2 v2.1.2/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/dave/jennifer v1.5.1 h1:AI8gaM02nCYRw6/WTH0W+S6UNck9YqPZ05xoIxQtuoE= -github.com/dave/jennifer v1.5.1/go.mod h1:AxTG893FiZKqxy3FP1kL80VMshSMuz2G+EgvszgGRnk= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48 h1:fRzb/w+pyskVMQ+UbP35JkH8yB7MYb4q/qhBarqZE6g= github.com/dgryski/trifles v0.0.0-20200323201526-dd97f9abfb48/go.mod h1:if7Fbed8SFyPtHLHbg49SI7NAdJiC5WIA09pe59rfAA= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= github.com/go-redis/redis/v9 v9.0.0-beta.2 h1:ZSr84TsnQyKMAg8gnV+oawuQezeJR11/09THcWCQzr4= github.com/go-redis/redis/v9 v9.0.0-beta.2/go.mod h1:Bldcd/M/bm9HbnNPi/LUtYBSD8ttcZYBMupwMXhdU0o= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/gorilla/websocket v1.5.0 h1:PPwGk2jz7EePpoHN/+ClbZu8SPxiqlu12wZP/3sWmnc= github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= -github.com/mattn/go-sqlite3 v1.14.14 h1:qZgc/Rwetq+MtyE18WhzjokPD93dNqLGNT3QJuLvBGw= -github.com/mattn/go-sqlite3 v1.14.14/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI= github.com/mattn/go-sqlite3 v1.14.15/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg= github.com/mdp/qrterminal v1.0.1 h1:07+fzVDlPuBlXS8tB0ktTAyf+Lp1j2+2zK3fBOL5b7c= github.com/mdp/qrterminal v1.0.1/go.mod h1:Z33WhxQe9B6CdW37HaVqcRKzP+kByF3q/qLxOGe12xQ= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/gomega v1.20.0 h1:8W0cWlwFkflGPLltQvLRB7ZVD5HuP6ng320w2IS245Q= github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY= github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/sethvargo/go-diceware v0.3.0 h1:UVVEfmN/uF50JfWAN7nbY6CiAlp5xeSx+5U0lWKkMCQ= github.com/sethvargo/go-diceware v0.3.0/go.mod h1:lH5Q/oSPMivseNdhMERAC7Ti5oOPqsaVddU1BcN1CY0= go.mau.fi/libsignal v0.0.0-20220628090436-4d18b66b087e h1:ByHDg+D+dMIGuBA2n+1xOUf4xr3FJFYg8yxl06s1YBE= go.mau.fi/libsignal v0.0.0-20220628090436-4d18b66b087e/go.mod h1:RCdzkTWSJv0AKGqurzPXJsEGIVMuQps3E/h7CMUPous= -go.mau.fi/whatsmeow v0.0.0-20220804175245-31c5af44cb82 h1:puhLha4NZeIXdwujCBduTR5MxG4+R/Q0vrCx8bYhZn8= -go.mau.fi/whatsmeow v0.0.0-20220804175245-31c5af44cb82/go.mod h1:hsjqq2xLuoFew8vbsDCJcGf5EbXCRcR/yoQ+87w6m3k= -go.mau.fi/whatsmeow v0.0.0-20220811191500-f650c10b0068 h1:DgSTWZ1LHSBxJFa3dvTvtMJGzqfYjinUFGLR3DujEts= -go.mau.fi/whatsmeow v0.0.0-20220811191500-f650c10b0068/go.mod h1:hsjqq2xLuoFew8vbsDCJcGf5EbXCRcR/yoQ+87w6m3k= go.mau.fi/whatsmeow v0.0.0-20220912085258-5c8577b8ac6f h1:tyuzYQcAwx+cwnnJw2i+utO/xWSj8RutT9Najc+DgOk= go.mau.fi/whatsmeow v0.0.0-20220912085258-5c8577b8ac6f/go.mod h1:hsjqq2xLuoFew8vbsDCJcGf5EbXCRcR/yoQ+87w6m3k= -golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY= -golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM= -golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 h1:a5Yg6ylndHHYJqIPrdq0AhvR6KTvDTAvgBtaidhEevY= golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= +golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc= +golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= -google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w= google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY= rsc.io/qr v0.2.0/go.mod h1:IF+uZjkb9fqyeF/4tlBoynqmQxUoPfWEKh921coOuXs= From 263bbc74840a6d8254a8d8d55acead740279fdf8 Mon Sep 17 00:00:00 2001 From: jspc Date: Sat, 1 Oct 2022 16:20:29 +0100 Subject: [PATCH 5/6] Upgrade whatsmeow --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index e12dfb6..40519d6 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/mdp/qrterminal v1.0.1 github.com/rs/xid v1.4.0 github.com/sethvargo/go-diceware v0.3.0 - go.mau.fi/whatsmeow v0.0.0-20220912085258-5c8577b8ac6f + go.mau.fi/whatsmeow v0.0.0-20220928114434-ebe489ef67ef ) require ( @@ -18,7 +18,7 @@ require ( github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/gorilla/websocket v1.5.0 // indirect go.mau.fi/libsignal v0.0.0-20220628090436-4d18b66b087e // indirect - golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 // indirect + golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be // indirect google.golang.org/protobuf v1.28.1 // indirect rsc.io/qr v0.2.0 // indirect ) diff --git a/go.sum b/go.sum index 00c4e51..80c087c 100644 --- a/go.sum +++ b/go.sum @@ -31,10 +31,10 @@ github.com/sethvargo/go-diceware v0.3.0 h1:UVVEfmN/uF50JfWAN7nbY6CiAlp5xeSx+5U0l github.com/sethvargo/go-diceware v0.3.0/go.mod h1:lH5Q/oSPMivseNdhMERAC7Ti5oOPqsaVddU1BcN1CY0= go.mau.fi/libsignal v0.0.0-20220628090436-4d18b66b087e h1:ByHDg+D+dMIGuBA2n+1xOUf4xr3FJFYg8yxl06s1YBE= go.mau.fi/libsignal v0.0.0-20220628090436-4d18b66b087e/go.mod h1:RCdzkTWSJv0AKGqurzPXJsEGIVMuQps3E/h7CMUPous= -go.mau.fi/whatsmeow v0.0.0-20220912085258-5c8577b8ac6f h1:tyuzYQcAwx+cwnnJw2i+utO/xWSj8RutT9Najc+DgOk= -go.mau.fi/whatsmeow v0.0.0-20220912085258-5c8577b8ac6f/go.mod h1:hsjqq2xLuoFew8vbsDCJcGf5EbXCRcR/yoQ+87w6m3k= -golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0 h1:a5Yg6ylndHHYJqIPrdq0AhvR6KTvDTAvgBtaidhEevY= -golang.org/x/crypto v0.0.0-20220919173607-35f4265a4bc0/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +go.mau.fi/whatsmeow v0.0.0-20220928114434-ebe489ef67ef h1:32Ki56jfx+tg8B8Qla/przLXJchD4Y2NtlggA1oG+cs= +go.mau.fi/whatsmeow v0.0.0-20220928114434-ebe489ef67ef/go.mod h1:hsjqq2xLuoFew8vbsDCJcGf5EbXCRcR/yoQ+87w6m3k= +golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be h1:fmw3UbQh+nxngCAHrDCCztao/kbYFnWjoqop8dHx05A= +golang.org/x/crypto v0.0.0-20220926161630-eccd6366d1be/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA= golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 h1:xHms4gcpe1YE7A3yIllJXP16CMAGuqwO2lX1mTyyRRc= golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk= From 2f4f9697dcf548ca385a03eda952e8a11e3d6d81 Mon Sep 17 00:00:00 2001 From: jspc Date: Sat, 1 Oct 2022 16:24:45 +0100 Subject: [PATCH 6/6] Cover lookup where a value is set --- config_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/config_test.go b/config_test.go index b470ec4..72062f1 100644 --- a/config_test.go +++ b/config_test.go @@ -1,6 +1,7 @@ package main import ( + "os" "testing" ) @@ -11,6 +12,15 @@ func TestLookup(t *testing.T) { } } +func TestLookup_Exists(t *testing.T) { + os.Setenv("__THIS_KEY_HAS_A_VALUE", "<3") + + got := Lookup("__THIS_KEY_HAS_A_VALUE", "blahblahblah") + if got != "<3" { + t.Errorf("unexpected value %q", got) + } +} + func TestMustLookup(t *testing.T) { defer func() { err := recover()