Skip to content

Commit 8171793

Browse files
authored
Merge pull request #57 from hazcod/feat/deps
feat: support multiple security users
2 parents 63d170a + 8979ccc commit 8171793

File tree

6 files changed

+33
-255
lines changed

6 files changed

+33
-255
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ slack:
2828
# slack bot token
2929
token: "XXX"
3030
# Slack user that receives messages if the user is not found
31-
security_user: "[email protected]"
31+
security_user: ["[email protected]"]
3232
# skip sending a security overview if there is nothing to mention
3333
skip_no_report: true
3434
# don't send a message to the user if 'Vacationing' status is set

cmd/main.go

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,22 @@ func main() {
7373
logrus.WithError(err).Fatal("could not fetch slack users")
7474
}
7575

76-
securityUserID := ""
76+
securityUserIDs := map[string]string{}
7777
for _, slackUser := range slackUsers {
78-
if strings.EqualFold(slackUser.Profile.Email, config.Slack.SecurityUser) {
79-
securityUserID = slackUser.ID
78+
for _, secUser := range config.Slack.SecurityUser {
79+
if strings.EqualFold(slackUser.Profile.Email, secUser) {
80+
securityUserIDs[secUser] = slackUser.ID
81+
break
82+
}
83+
}
84+
85+
if len(securityUserIDs) == len(config.Slack.SecurityUser) {
8086
break
8187
}
8288
}
8389

84-
if securityUserID == "" && !*noReport {
85-
logrus.WithField("fallback_user", config.Slack.SecurityUser).
90+
if len(securityUserIDs) == 0 && !*noReport {
91+
logrus.WithField("fallback_users", config.Slack.SecurityUser).
8692
Fatal("could not find fallback user on Slack")
8793
}
8894

@@ -239,15 +245,17 @@ func main() {
239245
logrus.WithError(err).Fatal("could not generate security overview")
240246
}
241247

242-
logrus.WithField("email", config.Slack.SecurityUser).
243-
Debug("sending security report to security user")
248+
logrus.WithField("emails", config.Slack.SecurityUser).
249+
Debug("sending security report to security users")
244250

245-
if _, _, _, err := slackClient.SendMessage(
246-
securityUserID, slack.MsgOptionText(overviewText, false), slack.MsgOptionAsUser(true),
247-
); err != nil {
248-
logrus.WithField("email", config.Slack.SecurityUser).WithError(err).
249-
Fatal("could not send security overview to security user")
250-
}
251+
for _, secUser := range config.Slack.SecurityUser {
252+
if _, _, _, err := slackClient.SendMessage(
253+
securityUserIDs[secUser], slack.MsgOptionText(overviewText, false), slack.MsgOptionAsUser(true),
254+
); err != nil {
255+
logrus.WithField("email", secUser).WithError(err).
256+
Fatal("could not send security overview to security user")
257+
}
251258

252-
logrus.WithField("email", config.Slack.SecurityUser).Info("sent security overview to security user")
259+
logrus.WithField("email", secUser).Info("sent security overview to security user")
260+
}
253261
}

config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const (
1414

1515
type Config struct {
1616
Slack struct {
17-
Token string `yaml:"token" env:"SLACK_TOKEN"`
18-
SecurityUser string `yaml:"security_user" emv:"SLACK_SECURITY_USER"`
17+
Token string `yaml:"token" env:"SLACK_TOKEN"`
18+
SecurityUser []string `yaml:"security_user" emv:"SLACK_SECURITY_USER"`
1919

2020
SkipNoReport bool `yaml:"skip_no_report" env:"SLACK_SKIP_NO_REPORT"`
2121
SkipOnHoliday bool `yaml:"skip_on_holiday" env:"SLACK_SKIP_ON_HOLIDAY"`

go.mod

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,21 @@ module github.com/hazcod/crowdstrike-spotlight-slacker
33
go 1.16
44

55
require (
6-
github.com/PuerkitoBio/purell v1.1.1 // indirect
7-
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
8-
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
9-
github.com/aws/aws-sdk-go v1.34.28 // indirect
10-
github.com/blang/semver/v4 v4.0.0 // indirect
11-
github.com/crowdstrike/gofalcon v0.2.21
12-
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8 // indirect
6+
github.com/crowdstrike/gofalcon v0.2.22
137
github.com/go-openapi/analysis v0.21.3 // indirect
14-
github.com/go-openapi/errors v0.20.2 // indirect
15-
github.com/go-openapi/jsonpointer v0.19.5 // indirect
16-
github.com/go-openapi/jsonreference v0.20.0 // indirect
17-
github.com/go-openapi/loads v0.21.1 // indirect
18-
github.com/go-openapi/runtime v0.24.1 // indirect
198
github.com/go-openapi/spec v0.20.6 // indirect
20-
github.com/go-openapi/strfmt v0.21.2 // indirect
21-
github.com/go-openapi/swag v0.21.1 // indirect
22-
github.com/go-openapi/validate v0.21.0 // indirect
23-
github.com/go-stack/stack v1.8.1 // indirect
249
github.com/golang/protobuf v1.5.2 // indirect
2510
github.com/gorilla/websocket v1.5.0 // indirect
26-
github.com/josharian/intern v1.0.0 // indirect
2711
github.com/kelseyhightower/envconfig v1.4.0
28-
github.com/kisielk/errcheck v1.2.0 // indirect
29-
github.com/kr/pty v1.1.5 // indirect
30-
github.com/mailru/easyjson v0.7.7 // indirect
3112
github.com/mitchellh/mapstructure v1.5.0 // indirect
32-
github.com/oklog/ulid v1.3.1 // indirect
33-
github.com/opentracing/opentracing-go v1.2.0 // indirect
34-
github.com/pborman/uuid v1.2.0 // indirect
3513
github.com/pkg/errors v0.9.1
3614
github.com/sirupsen/logrus v1.8.1
3715
github.com/slack-go/slack v0.10.3
38-
github.com/stretchr/objx v0.2.0 // indirect
39-
github.com/vektah/gqlparser v1.1.2 // indirect
40-
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c // indirect
41-
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc // indirect
4216
go.mongodb.org/mongo-driver v1.9.1 // indirect
4317
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 // indirect
4418
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401 // indirect
45-
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
46-
golang.org/x/text v0.3.7 // indirect
4719
google.golang.org/appengine v1.6.7 // indirect
4820
google.golang.org/protobuf v1.28.0 // indirect
4921
gopkg.in/errgo.v2 v2.1.0
50-
gopkg.in/yaml.v2 v2.4.0 // indirect
5122
gopkg.in/yaml.v3 v3.0.0
5223
)

0 commit comments

Comments
 (0)