diff --git a/client/client.yml b/client/client.yml index 3cd5736c..d3ba2722 100644 --- a/client/client.yml +++ b/client/client.yml @@ -5,10 +5,14 @@ # # default-host: https://ntfy.sh -# Defaults below will be used when a topic does not have its own settings +# Default username and password will be used with "ntfy publish" if no credentials are provided on command line +# Default username and password will be used with "ntfy subscribe" if no credentials are provided in subscription below +# For an empty password, use empty double-quotes ("") # # default-user: # default-password: + +# Default command will execute after "ntfy subscribe" receives a message if no command is provided in subscription below # default-command: # Subscriptions to topics and their actions. This option is primarily used by the systemd service, diff --git a/cmd/publish.go b/cmd/publish.go index 0b995258..efa875bf 100644 --- a/cmd/publish.go +++ b/cmd/publish.go @@ -160,6 +160,8 @@ func execPublish(c *cli.Context) error { fmt.Fprintf(c.App.ErrWriter, "\r%s\r", strings.Repeat(" ", 20)) } options = append(options, client.WithBasicAuth(user, pass)) + } else if conf.DefaultUser != "" && conf.DefaultPassword != nil { + options = append(options, client.WithBasicAuth(conf.DefaultUser, *conf.DefaultPassword)) } if pid > 0 { newMessage, err := waitForProcess(pid) diff --git a/docs/releases.md b/docs/releases.md index 2e310103..efa0fae9 100644 --- a/docs/releases.md +++ b/docs/releases.md @@ -14,6 +14,7 @@ and the [ntfy Android app](https://github.com/binwiederhier/ntfy-android/release * Bump Go version to Go 18.x ([#422](https://github.com/binwiederhier/ntfy/issues/422)) * Web: Strip trailing slash when subscribing ([#428](https://github.com/binwiederhier/ntfy/issues/428), thanks to [@raining1123](https://github.com/raining1123) for reporting, and [@wunter8](https://github.com/wunter8) for fixing) * Allow empty passwords in `client.yml` ([#374](https://github.com/binwiederhier/ntfy/issues/374), thanks to [@cyqsimon](https://github.com/cyqsimon) for reporting, and [@wunter8](https://github.com/wunter8) for fixing) +* `ntfy pub` will now use default username and password from `client.yml` ([#431](https://github.com/binwiederhier/ntfy/issues/431), thanks to [@wunter8](https://github.com/wunter8) for fixing) **Documentation:**