Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rp/6.1.5 rocketchat ticketer unofficial #39

Merged
merged 146 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
660f935
Add http client to RocketChat ticketer
Jul 13, 2020
f32f725
Add ticket service to RocketChat
Jul 14, 2020
fee12aa
Handle event callbacks to the RocketChat ticketer
Jul 15, 2020
9ae0a08
Handle extra fields from ticket body on RocketChat ticketer
Jul 15, 2020
eb80d01
Update RocketChat ticketer client
Jul 20, 2020
3369e7d
Add client and service tests for RocketChat ticketer
Aug 6, 2020
adc3879
Change variable name
Aug 7, 2020
2e72235
Add web tests for RocketChat ticketer
Aug 13, 2020
8419bdb
Get custom fields from ticket body on RocketChat ticketer
Aug 14, 2020
2a1c8ff
Fix RocketChat ticketer tests
Aug 14, 2020
498bfbe
Merge from nyaruka/master and fix conflicts
Aug 17, 2020
c1c0054
Pass org from the base task to task structs to remove need for duplic…
rowanseymour Sep 22, 2020
0d9497e
Merge pull request #357 from nyaruka/task_org
rowanseymour Sep 22, 2020
ea6d738
Update CHANGELOG.md for v5.7.25
Sep 22, 2020
7659543
WIP
rowanseymour Sep 23, 2020
2f1e7fe
WIP
rowanseymour Sep 24, 2020
c159526
Allow get or create by multiple URNs (WIP)
rowanseymour Sep 24, 2020
eb4a0e1
Add new testdata package for easier creation of new test data objects
rowanseymour Sep 25, 2020
0862be3
Merge pull request #359 from nyaruka/testdata
rowanseymour Sep 25, 2020
fe8b299
Merge branch 'master' into imports2
rowanseymour Sep 25, 2020
fc94a2b
Update to latest goflow
rowanseymour Sep 25, 2020
68c85f7
Merge branch 'master' into imports2
rowanseymour Sep 25, 2020
5d19c90
Add tests
rowanseymour Sep 28, 2020
b37f98b
Fix updating priority for orphaned URNs which are being attached
rowanseymour Sep 28, 2020
daed23a
CreateContact also should do lookup before trying to create new conta…
rowanseymour Sep 29, 2020
bf2cf51
Add test for dynamic group re-evaluation of imported contacts
rowanseymour Sep 29, 2020
7b904d9
Add tests for URN normalization during imports
rowanseymour Sep 29, 2020
5d8b8f6
Add mockable DB to enable testing database errors
rowanseymour Sep 29, 2020
1ad2a3c
Merge pull request #360 from nyaruka/mock_db
rowanseymour Sep 30, 2020
d439565
Merge branch 'master' into imports2
rowanseymour Sep 30, 2020
81e279b
Updates from code review
rowanseymour Sep 30, 2020
14ec817
Merge pull request #358 from nyaruka/imports2
rowanseymour Sep 30, 2020
7e4c1ed
Update CHANGELOG.md for v5.7.26
Sep 30, 2020
c19d933
Reorganize contacts.go
rowanseymour Sep 30, 2020
a5787d4
More use of Queryer interface instead of sqlx.DB
rowanseymour Sep 30, 2020
d671b40
If a flow start task creates new contacts, save those back to the start
rowanseymour Oct 1, 2020
e32d6a6
Merge pull request #362 from nyaruka/start_contacts
rowanseymour Oct 1, 2020
0fa60d4
Update CHANGELOG.md for v5.7.27
Oct 1, 2020
dc4c859
Add contact/resolve endpoint to assist with channel events still hand…
rowanseymour Oct 1, 2020
653d8f2
Resolve endpoint should also return URN
rowanseymour Oct 2, 2020
cbccc73
Merge pull request #364 from nyaruka/resolve_endpoint
rowanseymour Oct 2, 2020
896ba60
Update CHANGELOG.md for v5.7.28
Oct 2, 2020
5c9ef85
Merge from nyaruka/master and fix conflicts
koallann Oct 5, 2020
00fa663
Fix package import and ticketer contract implementation
koallann Oct 5, 2020
e67bf3f
Fix race condition when bulk getting/creating contacts
rowanseymour Oct 5, 2020
87fd852
Add utility method for race tests
rowanseymour Oct 5, 2020
0e627ff
Send/receive attachments in RocketChat ticketer
koallann Oct 5, 2020
a59c8db
Coverage
rowanseymour Oct 5, 2020
81cfacf
Merge pull request #366 from nyaruka/bulk_contact_get_or_create_fix
rowanseymour Oct 5, 2020
feb7858
Update CHANGELOG.md for v5.7.29
Oct 5, 2020
9d2d68c
Cleanup hook unit tests
rowanseymour Oct 6, 2020
3829e7a
Rework hooks so the hook instance is the exported thing
rowanseymour Oct 6, 2020
4d31785
Create new top-level core package for better organization of top leve…
rowanseymour Oct 6, 2020
6e296a5
Enable fail_ci_if_error for codecov
rowanseymour Oct 6, 2020
fdc3611
Move event handlers out of the hooks package and into their own package
rowanseymour Oct 7, 2020
7f29a7a
Update CHANGELOG.md for v5.7.30
Oct 7, 2020
e85dd46
Enable retrying on the elastic client
rowanseymour Oct 8, 2020
88b8c87
Fix attachment payload format in RocketChat ticketer
koallann Oct 9, 2020
9f8a21c
Merge remote-tracking branch 'nyaruka/master' into feature/rocketchat…
koallann Oct 9, 2020
e302006
Update to latest goflow
rowanseymour Oct 12, 2020
df9910d
Merge pull request #368 from nyaruka/elastic_retries
rowanseymour Oct 12, 2020
ab01d62
Update CHANGELOG.md for v5.7.31
Oct 12, 2020
528f856
Fix imports in RocketChat ticketer
koallann Oct 13, 2020
c7d1a0e
Update to latest goflow v0.105.2 and add tests for runs without expir…
rowanseymour Oct 13, 2020
797dc10
Merge pull request #370 from nyaruka/expires_on_tests
rowanseymour Oct 14, 2020
6491157
Update to goflow v0.105.3 to get support for arabic numerals in has_n…
rowanseymour Oct 14, 2020
c80d240
Update CHANGELOG.md for v5.7.32
Oct 14, 2020
c11d919
Fix closing of flows during simulation so that ignore keyword trigger…
rowanseymour Oct 15, 2020
390e92b
Simplify overriding flow definitions and creation of test channels fo…
rowanseymour Oct 15, 2020
bd33e62
Add Flow.cloneWithNewDefinition
rowanseymour Oct 16, 2020
3030522
Merge pull request #372 from nyaruka/sim_fix
rowanseymour Oct 16, 2020
b5e30fd
Update to goflow v0.105.4
rowanseymour Oct 16, 2020
0fe3817
Update CHANGELOG.md for v5.7.33
Oct 16, 2020
f37c923
Merge remote-tracking branch 'nyaruka/master' into feature/rocketchat…
koallann Oct 20, 2020
8705272
Use the new testdata.InsertOpenTicket in RocketChat ticketer
koallann Oct 20, 2020
4e88a14
Support incoming attachments on mailgun ticketers
rowanseymour Oct 20, 2020
1410dc7
Get rid of no longer used files property on web tests
rowanseymour Oct 20, 2020
7b348d2
Mailgun requests can be either url-encoded or multipart
rowanseymour Oct 20, 2020
59d6208
Merge pull request #374 from nyaruka/mailgun_attachments_pt1
rowanseymour Oct 21, 2020
739542e
Update CHANGELOG.md for v5.7.36
Oct 21, 2020
7708c6f
Merge remote-tracking branch 'nyaruka/master' into feature/rocketchat…
koallann Oct 21, 2020
8a839fd
Add support for outgoing mailgun ticket attachments
rowanseymour Oct 21, 2020
df94e50
Merge pull request #375 from nyaruka/mailgun_attachments_pt2
rowanseymour Oct 21, 2020
b938d6a
Update CHANGELOG.md for v5.7.37
Oct 21, 2020
7befdac
Support incoming attachments on RocketChat ticketers
koallann Oct 22, 2020
6720efd
Make sure we save attachment file extension
norkans7 Oct 23, 2020
9249315
Revert "Make sure we save attachment file extension"
norkans7 Oct 23, 2020
61a0657
Always request Mp3 files from Twilio IVR recordings
norkans7 Oct 23, 2020
9599f49
Merge pull request #376 from nyaruka/fix-attachment-extension
rowanseymour Oct 23, 2020
b522aa9
Update CHANGELOG.md for v5.7.38
Oct 23, 2020
8c046d1
Remove hack for get department and custom fields on RocketChat tickets
koallann Oct 23, 2020
29e20f4
Fix input_labels_added event handling when session input ID isn't set
rowanseymour Oct 23, 2020
e9771f5
Remove no longer needed codecov token from CI workflow
rowanseymour Oct 23, 2020
e0ff4bc
Merge pull request #377 from nyaruka/input_label_fix
rowanseymour Oct 26, 2020
41871b3
Update CHANGELOG.md for v5.7.39
Oct 26, 2020
713c250
Update to goflow v0.105.5
norkans7 Oct 27, 2020
7084c42
Merge pull request #378 from nyaruka/update-goflow
rowanseymour Oct 27, 2020
5b63fd6
Update CHANGELOG.md for v5.7.40
Oct 27, 2020
232dd81
Add better testing of number normalization during imports
rowanseymour Oct 28, 2020
ed5af54
Don't write to flows_flowrun.timeout_on so it can be dropped
rowanseymour Oct 29, 2020
110fdbb
Update to latest goflow v0.106.0
rowanseymour Oct 29, 2020
0fa5b0f
Merge pull request #379 from nyaruka/drop_run_timeout
rowanseymour Oct 29, 2020
73852e6
Update CHANGELOG.md for v5.7.41
Oct 29, 2020
7ae69ce
Prevent importing invalid URNs during import
rowanseymour Oct 30, 2020
d052cfc
Merge pull request #380 from nyaruka/import_fix_invalid_urns
rowanseymour Oct 30, 2020
506f132
Update CHANGELOG.md for v5.7.42
Oct 30, 2020
85b7614
Update to latest goflow v0.106.1
rowanseymour Oct 30, 2020
5315a00
Update CHANGELOG.md for v5.7.43
Oct 30, 2020
0f53a5c
Merge pull request #333 from Ilhasoft/feature/rocketchat-ticketer
rowanseymour Nov 5, 2020
d85b51e
Update CHANGELOG.md for v5.7.44
Nov 5, 2020
428c121
Update test database
rowanseymour Nov 5, 2020
13ea732
Update CHANGELOG.md for v6.0.0
Nov 5, 2020
3ee97fe
Update README
rowanseymour Nov 5, 2020
00eb393
add log when queuing to courier
nicpottier Nov 18, 2020
796aa50
add timing to redis insert
nicpottier Nov 18, 2020
d282e1c
typo
nicpottier Nov 18, 2020
23c74d9
Merge pull request #382 from nyaruka/log-queue
nicpottier Nov 18, 2020
d97ed7c
Update CHANGELOG.md for v6.0.1
Nov 18, 2020
749cb41
pin goreleaser, explicit inclusion of /docs/*, completions and functions
nicpottier Nov 18, 2020
a22c933
Update CHANGELOG.md for v6.0.2
Nov 18, 2020
98a8f75
correct name for completion
nicpottier Nov 18, 2020
eb86e90
Update CHANGELOG.md for v6.0.3
Nov 18, 2020
ffe4239
pin to v0.147.2
nicpottier Nov 18, 2020
c1e4909
Configure engine to disallow HTTP requests to private networks
rowanseymour Nov 20, 2020
533001e
Rename DisallowedIPs to DisallowedNetworks
rowanseymour Nov 23, 2020
07227fb
Merge pull request #384 from nyaruka/private_networks
rowanseymour Nov 23, 2020
89f4a31
Update CHANGELOG.md for v6.1.0
Nov 23, 2020
a470a53
Update to latest goflow v0.106.3
rowanseymour Dec 2, 2020
43beb1f
Update CHANGELOG.md for v6.1.1
Dec 3, 2020
8d0e44b
Add support for internal type ticketers
rowanseymour Dec 9, 2020
e60b52d
Ensure field and group assets used for imports are fresh
rowanseymour Dec 10, 2020
76adbf7
Merge pull request #387 from nyaruka/internal_ticketers
rowanseymour Dec 10, 2020
3ea8c63
Merge pull request #388 from nyaruka/import_fix
rowanseymour Dec 10, 2020
e380075
Update CHANGELOG.md for v6.1.2
Dec 10, 2020
959b54d
Fix misreporting created contacts as updated during imports
rowanseymour Dec 11, 2020
8664a24
Merge pull request #389 from nyaruka/import_create_vs_update
rowanseymour Dec 14, 2020
c5c7d9b
Update CHANGELOG.md for v6.1.3
Dec 14, 2020
e42fb88
variable timeout for fire campaign task
nicpottier Dec 15, 2020
cf42c79
Merge pull request #390 from nyaruka/variable-event-fire-timeout
nicpottier Dec 15, 2020
d13a71e
Update CHANGELOG.md for v6.1.4
Dec 15, 2020
c812464
Update to goflow v0.107.0
rowanseymour Dec 16, 2020
1b5ed34
Update to goflow v0.107.1
rowanseymour Dec 17, 2020
aa822c6
Update CHANGELOG.md for v6.1.5
Dec 17, 2020
e8b68cd
Merge branch 'master' of https://github.com/nyaruka/mailroom into upd…
Dec 30, 2020
c10d260
Re-add get department and custom fields on RocketChat tickets
Jan 21, 2021
2ff2ea3
Merge branch 'feature/rocketchat-ticketer-unofficial' of https://gith…
Jan 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ jobs:
if: success()
uses: codecov/codecov-action@v1
with:
token: ${{ secrets.CODECOV_TOKEN }}
# fail_ci_if_error: true # ideally this should be enabled but codecov uploads fail a lot
fail_ci_if_error: true

release:
name: Release
Expand All @@ -72,7 +71,7 @@ jobs:
uses: goreleaser/goreleaser-action@v1
if: ${{ !contains(github.ref, '-') }}
with:
version: latest
version: v0.147.2
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -81,7 +80,7 @@ jobs:
uses: goreleaser/goreleaser-action@v1
if: contains(github.ref, '-')
with:
version: latest
version: v0.147.2
args: release --rm-dist --skip-validate
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
118 changes: 118 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,121 @@
v6.1.5
----------
* Update to goflow v0.107.1

v6.1.4
----------
* Variable timeout for fire campaign task

v6.1.3
----------
* Fix misreporting created contacts as updated during imports

v6.1.2
----------
* Ensure field and group assets used for imports are fresh
* Add support for internal type ticketers

v6.1.1
----------
* Update to latest goflow v0.106.3

v6.1.0
----------
* Configure engine to disallow HTTP requests to private networks

v6.0.3
----------
* correct name for completion.json in release

v6.0.2
----------
* pin goreleaser, explicit inclusion of /docs/*, completions and functions

v6.0.1
----------
* add log when queuing to courier

v6.0.0
----------
* Update test database

v5.7.44
----------
* Add ticket service for Rocket.Chat

v5.7.43
----------
* Update to latest goflow v0.106.1

v5.7.42
----------
* Prevent importing invalid URNs during import

v5.7.41
----------
* Update to latest goflow v0.106.0
* Don't write to flows_flowrun.timeout_on so it can be dropped

v5.7.40
----------
* Update to goflow v0.105.5

v5.7.39
----------
* Fix input_labels_added event handling when session input ID isn't set

v5.7.38
----------
* Always request Mp3 files from Twilio IVR recordings

v5.7.37
----------
* Add support for outgoing mailgun ticket attachments

v5.7.36
----------
* Incoming attachments for mailgun ticketers

v5.7.33
----------
* Update to goflow v0.105.4
* Fix cloning of flows during simulation so that ignore keyword triggers is cloned too

v5.7.32
----------
* Update to goflow v0.105.3 to get support for arabic numerals in has_number tests

v5.7.31
----------
* Update to latest goflow to get for normalizing numbers from The Gambia
* Enable retrying on the elastic client

v5.7.30
----------
* Reorganization of core packages

v5.7.29
----------
* Fix race condition when bulk getting/creating contacts

v5.7.28
----------
* Add contact/resolve endpoint to assist with channel events still handled in RP

v5.7.27
----------
* If a flow start task creates new contacts, save those back to the start

v5.7.26
----------
* Add mockable DB to enable testing database errors
* CreateContact also should do lookup before trying to create new contact with URNs
* Imports 2.0

v5.7.25
----------
* Pass org from the base task to task structs to remove need for duplicating it in the task body

v5.7.24
----------
* Add SessionStatus to messages queued to courier
Expand Down
10 changes: 2 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,13 @@ Recommended settings for error and performance monitoring:

# Development

Install Mailroom source in your workspace with:

```
go get github.com/nyaruka/mailroom
```

Build Mailroom with:
Once you've checked out the code, you can build Mailroom with:

```
go build github.com/nyaruka/mailroom/cmd/mailroom
```

This will create a new executable in your current directory `mailroom`
This will create a new executable in $GOPATH/bin called `mailroom`.

To run the tests you need to create the test database:

Expand Down
34 changes: 21 additions & 13 deletions cmd/mailroom/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ import (
"github.com/nyaruka/mailroom"
"github.com/nyaruka/mailroom/config"

_ "github.com/nyaruka/mailroom/hooks"
_ "github.com/nyaruka/mailroom/ivr/nexmo"
_ "github.com/nyaruka/mailroom/ivr/twiml"
_ "github.com/nyaruka/mailroom/core/handlers"
_ "github.com/nyaruka/mailroom/core/hooks"
_ "github.com/nyaruka/mailroom/core/ivr/nexmo"
_ "github.com/nyaruka/mailroom/core/ivr/twiml"
_ "github.com/nyaruka/mailroom/core/tasks/broadcasts"
_ "github.com/nyaruka/mailroom/core/tasks/campaigns"
_ "github.com/nyaruka/mailroom/core/tasks/contacts"
_ "github.com/nyaruka/mailroom/core/tasks/expirations"
_ "github.com/nyaruka/mailroom/core/tasks/groups"
_ "github.com/nyaruka/mailroom/core/tasks/interrupts"
_ "github.com/nyaruka/mailroom/core/tasks/ivr"
_ "github.com/nyaruka/mailroom/core/tasks/schedules"
_ "github.com/nyaruka/mailroom/core/tasks/starts"
_ "github.com/nyaruka/mailroom/core/tasks/stats"
_ "github.com/nyaruka/mailroom/core/tasks/timeouts"
_ "github.com/nyaruka/mailroom/services/tickets/mailgun"
_ "github.com/nyaruka/mailroom/services/tickets/rocketchat"
_ "github.com/nyaruka/mailroom/services/tickets/zendesk"
_ "github.com/nyaruka/mailroom/tasks/broadcasts"
_ "github.com/nyaruka/mailroom/tasks/campaigns"
_ "github.com/nyaruka/mailroom/tasks/expirations"
_ "github.com/nyaruka/mailroom/tasks/groups"
_ "github.com/nyaruka/mailroom/tasks/interrupts"
_ "github.com/nyaruka/mailroom/tasks/ivr"
_ "github.com/nyaruka/mailroom/tasks/schedules"
_ "github.com/nyaruka/mailroom/tasks/starts"
_ "github.com/nyaruka/mailroom/tasks/stats"
_ "github.com/nyaruka/mailroom/tasks/timeouts"
_ "github.com/nyaruka/mailroom/web/contact"
_ "github.com/nyaruka/mailroom/web/docs"
_ "github.com/nyaruka/mailroom/web/expression"
Expand All @@ -53,6 +56,11 @@ func main() {
)
loader.MustLoad()

// ensure config is valid
if err := config.Validate(); err != nil {
logrus.Fatalf("invalid config: %s", err)
}

// if we have a custom version, use it
if version != "Dev" {
config.Version = version
Expand Down
41 changes: 31 additions & 10 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Config struct {
WebhooksInitialBackoff int `help:"the initial backoff in milliseconds when retrying a failed webhook call"`
WebhooksBackoffJitter float64 `help:"the amount of jitter to apply to backoff times"`
SMTPServer string `help:"the smtp configuration for sending emails ex: smtp://user%40password@server:port/?from=foo%40gmail.com"`
DisallowedIPs string `help:"comma separated list of IP addresses which engine can't make HTTP calls to"`
DisallowedNetworks string `help:"comma separated list of IP addresses and networks which engine can't make HTTP calls to"`
MaxStepsPerSprint int `help:"the maximum number of steps allowed per engine sprint"`
MaxValueLength int `help:"the maximum size in characters for contact field values and run result values"`

Expand Down Expand Up @@ -84,7 +84,7 @@ func NewMailroomConfig() *Config {
WebhooksInitialBackoff: 5000,
WebhooksBackoffJitter: 0.5,
SMTPServer: "",
DisallowedIPs: `127.0.0.1,::1`,
DisallowedNetworks: `127.0.0.1,::1,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16`,
MaxStepsPerSprint: 100,
MaxValueLength: 640,

Expand All @@ -106,19 +106,40 @@ func NewMailroomConfig() *Config {
}
}

func (c *Config) ParseDisallowedIPs() ([]net.IP, error) {
addrs, err := csv.NewReader(strings.NewReader(c.DisallowedIPs)).Read()
// Validate validates the config
func (c *Config) Validate() error {
_, _, err := c.ParseDisallowedNetworks()
if err != nil {
return errors.Wrap(err, "unable to parse DisallowedNetworks")
}
return nil
}

// ParseDisallowedNetworks parses the list of IPs and IP networks (written in CIDR notation)
func (c *Config) ParseDisallowedNetworks() ([]net.IP, []*net.IPNet, error) {
addrs, err := csv.NewReader(strings.NewReader(c.DisallowedNetworks)).Read()
if err != nil && err != io.EOF {
return nil, err
return nil, nil, err
}

ips := make([]net.IP, 0, len(addrs))
ipNets := make([]*net.IPNet, 0, len(addrs))

for _, addr := range addrs {
ip := net.ParseIP(addr)
if ip == nil {
return nil, errors.Errorf("couldn't parse '%s' as an IP address", addr)
if strings.Contains(addr, "/") {
_, ipNet, err := net.ParseCIDR(addr)
if err != nil {
return nil, nil, errors.Errorf("couldn't parse '%s' as an IP network", addr)
}
ipNets = append(ipNets, ipNet)
} else {
ip := net.ParseIP(addr)
if ip == nil {
return nil, nil, errors.Errorf("couldn't parse '%s' as an IP address", addr)
}
ips = append(ips, ip)
}
ips = append(ips, ip)
}

return ips, nil
return ips, ipNets, nil
}
27 changes: 19 additions & 8 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,38 @@ import (
"github.com/stretchr/testify/assert"
)

func TestParseDisallowedIPs(t *testing.T) {
func TestParseDisallowedNetworks(t *testing.T) {
cfg := config.NewMailroomConfig()

privateNetwork1 := &net.IPNet{IP: net.IPv4(10, 0, 0, 0).To4(), Mask: net.CIDRMask(8, 32)}
privateNetwork2 := &net.IPNet{IP: net.IPv4(172, 16, 0, 0).To4(), Mask: net.CIDRMask(12, 32)}
privateNetwork3 := &net.IPNet{IP: net.IPv4(192, 168, 0, 0).To4(), Mask: net.CIDRMask(16, 32)}

// test with config defaults
ips, err := cfg.ParseDisallowedIPs()
ips, ipNets, err := cfg.ParseDisallowedNetworks()
assert.NoError(t, err)
assert.Equal(t, []net.IP{net.IPv4(127, 0, 0, 1), net.ParseIP(`::1`)}, ips)
assert.Equal(t, []*net.IPNet{privateNetwork1, privateNetwork2, privateNetwork3}, ipNets)

// test with empty
cfg.DisallowedIPs = ``
ips, err = cfg.ParseDisallowedIPs()
cfg.DisallowedNetworks = ``
ips, ipNets, err = cfg.ParseDisallowedNetworks()
assert.NoError(t, err)
assert.Equal(t, []net.IP{}, ips)
assert.Equal(t, []*net.IPNet{}, ipNets)

// test with invalid CSV
cfg.DisallowedIPs = `"127.0.0.1`
_, err = cfg.ParseDisallowedIPs()
cfg.DisallowedNetworks = `"127.0.0.1`
_, _, err = cfg.ParseDisallowedNetworks()
assert.EqualError(t, err, `record on line 1; parse error on line 2, column 0: extraneous or missing " in quoted-field`)

// test with invalid IP
cfg.DisallowedIPs = `127.0.1`
_, err = cfg.ParseDisallowedIPs()
cfg.DisallowedNetworks = `127.0.1`
_, _, err = cfg.ParseDisallowedNetworks()
assert.EqualError(t, err, `couldn't parse '127.0.1' as an IP address`)

// test with invalid network
cfg.DisallowedNetworks = `127.0.0.1/x`
_, _, err = cfg.ParseDisallowedNetworks()
assert.EqualError(t, err, `couldn't parse '127.0.0.1/x' as an IP network`)
}
9 changes: 8 additions & 1 deletion courier/courier.go → core/courier/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (

"github.com/gomodule/redigo/redis"
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/mailroom/models"
"github.com/nyaruka/mailroom/core/models"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -43,10 +44,16 @@ func QueueMessages(rc redis.Conn, msgs []*models.Msg) error {
if err != nil {
return err
}
start := time.Now()
_, err = queueMsg.Do(rc, epochMS, "msgs", currentChannel.UUID(), currentChannel.TPS(), priority, batchJSON)
if err != nil {
return err
}
logrus.WithFields(logrus.Fields{
"msgs": len(batch),
"channel_uuid": currentChannel.UUID(),
"elapsed": time.Since(start),
}).Info("msgs queued to courier")
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions courier/courier_test.go → core/courier/courier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/goflow/assets"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/mailroom/courier"
"github.com/nyaruka/mailroom/models"
"github.com/nyaruka/mailroom/core/courier"
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/testsuite"

"github.com/stretchr/testify/assert"
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions goflow/engine_test.go → core/goflow/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/nyaruka/gocommon/httpx"
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/mailroom/goflow"
"github.com/nyaruka/mailroom/models"
"github.com/nyaruka/mailroom/core/goflow"
"github.com/nyaruka/mailroom/core/models"
"github.com/nyaruka/mailroom/testsuite"

"github.com/shopspring/decimal"
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion goflow/flows_test.go → core/goflow/flows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/goflow/flows"
"github.com/nyaruka/goflow/test"
"github.com/nyaruka/mailroom/goflow"
"github.com/nyaruka/mailroom/core/goflow"

"github.com/Masterminds/semver"
"github.com/stretchr/testify/assert"
Expand Down
Loading