Skip to content

Commit

Permalink
Merge pull request #5 from headyj/main
Browse files Browse the repository at this point in the history
add basic auth capabilities
  • Loading branch information
academo authored Nov 26, 2024
2 parents 27d6f50 + 2936eb2 commit 8389002
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,12 @@ Usage of grafana-ntfy:
Allow insecure connections to ntfy-url
-ntfy-url string
The ntfy url including the topic. e.g.: https://ntfy.sh/mytopic
-password string
The ntfy password
-port int
The port to listen on (default 8080)
-username string
The ntfy username
```
# No https?
Expand Down
7 changes: 7 additions & 0 deletions pkg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

var (
ntfyUrl = flag.String("ntfy-url", "", "The ntfy url including the topic. e.g.: https://ntfy.sh/mytopic")
username = flag.String("username", "", "The ntfy username")
password = flag.String("password", "", "The ntfy password")
allowInsecure = flag.Bool("allow-insecure", false, "Allow insecure connections to ntfy-url")
port = flag.Int("port", 8080, "The port to listen on")
)
Expand Down Expand Up @@ -160,6 +162,11 @@ func sendNotification(payload NtfyNotification) error {
// Set the content type to json
req.Header.Set("Content-Type", "application/json")

// Add auth if provided
if *username != "" && *password != "" {
req.SetBasicAuth(*username, *password)
}

// Send the request
defer req.Body.Close()
resp, err := http.DefaultClient.Do(req)
Expand Down

0 comments on commit 8389002

Please sign in to comment.