Skip to content

Commit efe713c

Browse files
authored
FEATURE: Set --notify via creds.json so that preview or push can always notify (#3910)
Either setting these new options OR using --notify on the commandline will send notification for any specific execution. Fixes #3906 In a second commit (feel free to remove) I added some logging to indicate that notifications were enabled or not (useful when testing each case). I've manually tested combinations of the various options, for both preview and push: * --notify set or unset on commandline * notify_on_* set to "true" or "ASDAS" or "false" or not mentioned All seem to provide the correct logging line - invalid boolean values are considered false (not an error). I've made an attempt at documentation of the options, not sure if you want it elsewhere as well. <!-- ## Before submiting a pull request Please make sure you've run the following commands from the root directory. bin/generate-all.sh (this runs commands like "go generate", fixes formatting, and so on) ## Release changelog section Help keep the release changelog clear by pre-naming the proper section in the GitHub pull request title. Some examples: * CICD: Add required GHA permissions for goreleaser * DOCS: Fixed providers with "contributor support" table * ROUTE53: Allow R53_ALIAS records to enable target health evaluation More examples/context can be found in the file .goreleaser.yml under the 'build' > 'changelog' key. !-->
1 parent 6d4a185 commit efe713c

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

commands/ppreviewPush.go

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"os"
99
"regexp"
10+
"strconv"
1011
"strings"
1112
"sync"
1213
"sync/atomic"
@@ -210,8 +211,30 @@ func prun(args PPreviewArgs, push bool, interactive bool, out printer.CLI, repor
210211
return err
211212
}
212213

214+
var notify = args.Notify
215+
216+
// We want to notify if args.Notify OR notify_on_*
217+
if notifications, ok := providerConfigs["notifications"]; ok && notifications != nil {
218+
if push {
219+
if notifyOnPush, ok := notifications["notify_on_push"]; ok {
220+
if b, _ := strconv.ParseBool(notifyOnPush); b {
221+
notify = true
222+
}
223+
}
224+
} else {
225+
if notifyOnPreview, ok := notifications["notify_on_preview"]; ok {
226+
if b, _ := strconv.ParseBool(notifyOnPreview); b {
227+
notify = true
228+
}
229+
}
230+
}
231+
}
232+
if notify {
233+
out.PrintfIf(fullMode, "Notifications are enabled...\n")
234+
}
235+
213236
out.PrintfIf(fullMode, "Creating an in-memory model of 'desired'...\n")
214-
notifier, err := PInitializeProviders(cfg, providerConfigs, args.Notify)
237+
notifier, err := PInitializeProviders(cfg, providerConfigs, notify)
215238
if err != nil {
216239
return err
217240
}

documentation/advanced-features/notifications.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ Notifications are configured in the `creds.json` file, since they often contain
1212
"r53": {},
1313
"gcloud": {},
1414
"notifications": {
15+
"notify_on_push": false,
16+
"notify_on_preview": false,
1517
"slack_url": "https://api.slack.com/apps/0XXX0X0XX0/incoming-webhooks",
1618
"teams_url": "https://outlook.office.com/webhook/00000000-0000-0000-0000-000000000000@00000000-0000-0000-0000-000000000000/IncomingWebhook/00000000000000000000000000000000/00000000-0000-0000-0000-000000000000",
1719
"shoutrrr_url": "discover://token@id"
@@ -22,7 +24,9 @@ Notifications are configured in the `creds.json` file, since they often contain
2224

2325
## Usage
2426

25-
If you want to send a notification, add the `--notify` flag to the `dnscontrol preview` or `dnscontrol push` commands.
27+
If you want to send a notification for a specific execution, add the `--notify` flag to the `dnscontrol preview` or `dnscontrol push` commands.
28+
29+
To always send notifications, enable one or more of the `notify_on_push` or `notify_on_preview` options.
2630

2731
Below is an example where we add [the A record](../language-reference/domain-modifiers/A.md) `foo` and display the notification output.
2832

0 commit comments

Comments
 (0)