Skip to content

Commit 6dde43b

Browse files
authored
Merge pull request #24 from cruxstack/dev
feat: add optional footer note for pc compliance
2 parents 4d58cdf + a555a5e commit 6dde43b

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ APP_SLACK_CHANNEL=C01234ABCDE
3030
# APP_SLACK_CHANNEL_PR_BYPASS=C01234ABCDE
3131
# APP_SLACK_CHANNEL_OKTA_SYNC=C01234ABCDE
3232
# APP_SLACK_CHANNEL_ORPHANED_USERS=C01234ABCDE
33+
# optional: custom footer note for PR bypass notifications (supports Slack mrkdwn)
34+
# APP_SLACK_FOOTER_NOTE_PR_BYPASS=_Please review the <https://example.com/policy|security policy>._
3335

3436
# api gateway base path (optional, for lambda deployments with stage prefix)
3537
# APP_BASE_PATH=v1

internal/app/app.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ func New(ctx context.Context, cfg *config.Config) (*App, error) {
7272
OktaSync: cfg.SlackChannelOktaSync,
7373
OrphanedUsers: cfg.SlackChannelOrphanedUsers,
7474
}
75-
app.Notifier = notifiers.NewSlackNotifierWithAPIURL(cfg.SlackToken, channels, cfg.SlackAPIURL)
75+
messages := notifiers.SlackMessages{
76+
PRBypassFooterNote: cfg.SlackPRBypassFooterNote,
77+
}
78+
app.Notifier = notifiers.NewSlackNotifierWithAPIURL(cfg.SlackToken, channels, messages, cfg.SlackAPIURL)
7679
}
7780

7881
return app, nil

internal/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Config struct {
5656
SlackChannelPRBypass string
5757
SlackChannelOktaSync string
5858
SlackChannelOrphanedUsers string
59+
SlackPRBypassFooterNote string
5960
SlackAPIURL string
6061
}
6162

@@ -179,6 +180,7 @@ func NewConfigWithContext(ctx context.Context) (*Config, error) {
179180
SlackChannelPRBypass: os.Getenv("APP_SLACK_CHANNEL_PR_BYPASS"),
180181
SlackChannelOktaSync: os.Getenv("APP_SLACK_CHANNEL_OKTA_SYNC"),
181182
SlackChannelOrphanedUsers: os.Getenv("APP_SLACK_CHANNEL_ORPHANED_USERS"),
183+
SlackPRBypassFooterNote: os.Getenv("APP_SLACK_FOOTER_NOTE_PR_BYPASS"),
182184
SlackAPIURL: os.Getenv("APP_SLACK_API_URL"),
183185
}
184186

@@ -371,6 +373,7 @@ type RedactedConfig struct {
371373
SlackChannelPRBypass string `json:"slack_channel_pr_bypass"`
372374
SlackChannelOktaSync string `json:"slack_channel_okta_sync"`
373375
SlackChannelOrphanedUsers string `json:"slack_channel_orphaned_users"`
376+
SlackPRBypassFooterNote string `json:"slack_pr_bypass_footer_note"`
374377
SlackAPIURL string `json:"slack_api_url"`
375378
}
376379

@@ -426,6 +429,7 @@ func (c *Config) Redacted() RedactedConfig {
426429
SlackChannelPRBypass: c.SlackChannelPRBypass,
427430
SlackChannelOktaSync: c.SlackChannelOktaSync,
428431
SlackChannelOrphanedUsers: c.SlackChannelOrphanedUsers,
432+
SlackPRBypassFooterNote: c.SlackPRBypassFooterNote,
429433
SlackAPIURL: c.SlackAPIURL,
430434
}
431435
}

internal/notifiers/slack.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,35 @@ type SlackChannels struct {
1414
OrphanedUsers string
1515
}
1616

17+
// SlackMessages holds optional custom messages for different notification
18+
// types. empty values are excluded from the notification.
19+
type SlackMessages struct {
20+
PRBypassFooterNote string
21+
}
22+
1723
// SlackNotifier sends formatted messages to Slack channels.
1824
type SlackNotifier struct {
1925
client *slack.Client
2026
channels SlackChannels
27+
messages SlackMessages
2128
}
2229

2330
// NewSlackNotifier creates a Slack notifier with default API URL.
24-
func NewSlackNotifier(token string, channels SlackChannels) *SlackNotifier {
25-
return NewSlackNotifierWithAPIURL(token, channels, "")
31+
func NewSlackNotifier(token string, channels SlackChannels, messages SlackMessages) *SlackNotifier {
32+
return NewSlackNotifierWithAPIURL(token, channels, messages, "")
2633
}
2734

2835
// NewSlackNotifierWithAPIURL creates a Slack notifier with custom API URL.
2936
// useful for testing with mock servers.
30-
func NewSlackNotifierWithAPIURL(token string, channels SlackChannels, apiURL string) *SlackNotifier {
37+
func NewSlackNotifierWithAPIURL(token string, channels SlackChannels, messages SlackMessages, apiURL string) *SlackNotifier {
3138
var opts []slack.Option
3239
if apiURL != "" {
3340
opts = append(opts, slack.OptionAPIURL(apiURL))
3441
}
3542
return &SlackNotifier{
3643
client: slack.New(token, opts...),
3744
channels: channels,
45+
messages: messages,
3846
}
3947
}
4048

internal/notifiers/slack_messages.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ func (s *SlackNotifier) NotifyPRBypass(ctx context.Context, result *client.PRCom
6767
))
6868
}
6969

70+
if s.messages.PRBypassFooterNote != "" {
71+
blocks = append(blocks, slack.NewContextBlock(
72+
"footer",
73+
slack.NewTextBlockObject("mrkdwn", s.messages.PRBypassFooterNote, false, false),
74+
))
75+
}
76+
7077
channel := s.channelFor(s.channels.PRBypass)
7178
_, _, err := s.client.PostMessageContext(
7279
ctx,

0 commit comments

Comments
 (0)