Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(monitor): add basic-auth feature for protected sites #367

Merged
merged 3 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ Properties for each site:
| allow-insecure | boolean | no | false |
| same-tab | boolean | no | false |
| alt-status-codes | array | no | |
| basic-auth | object | no | |

`title`

Expand Down Expand Up @@ -1524,6 +1525,16 @@ alt-status-codes:
- 403
```

`basic-auth`

HTTP Basic Authentication credentials for protected sites.

```yaml
basic-auth:
usename: your-username
password: your-password
```

### Releases
Display a list of latest releases for specific repositories on Github, GitLab, Codeberg or Docker Hub.

Expand Down
8 changes: 8 additions & 0 deletions internal/glance/widget-monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ type SiteStatusRequest struct {
DefaultURL string `yaml:"url"`
CheckURL string `yaml:"check-url"`
AllowInsecure bool `yaml:"allow-insecure"`
BasicAuth struct {
Username string `yaml:"username"`
Password string `yaml:"password"`
} `yaml:"basic-auth"`
}

type siteStatus struct {
Expand All @@ -141,6 +145,10 @@ func fetchSiteStatusTask(statusRequest *SiteStatusRequest) (siteStatus, error) {
}, nil
}

if statusRequest.BasicAuth.Username != "" || statusRequest.BasicAuth.Password != "" {
request.SetBasicAuth(statusRequest.BasicAuth.Username, statusRequest.BasicAuth.Password)
}

ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()
request = request.WithContext(ctx)
Expand Down