mirror of
https://github.com/glanceapp/glance.git
synced 2025-06-21 18:31:24 +02:00
feat(monitor): add basic-auth feature for protected sites
this closes [issue #316](https://github.com/glanceapp/glance/issues/316) Furthermore, this could be expanded to also pass the configured basic auth credentials to the request when the user clicks on the specific monitor widget
This commit is contained in:
parent
c33fe45d4c
commit
c00d937f4c
@ -28,6 +28,10 @@ type monitorWidget struct {
|
|||||||
StatusText string `yaml:"-"`
|
StatusText string `yaml:"-"`
|
||||||
StatusStyle string `yaml:"-"`
|
StatusStyle string `yaml:"-"`
|
||||||
AltStatusCodes []int `yaml:"alt-status-codes"`
|
AltStatusCodes []int `yaml:"alt-status-codes"`
|
||||||
|
BasicAuth struct {
|
||||||
|
Username string `yaml:"username"`
|
||||||
|
Password string `yaml:"password"`
|
||||||
|
} `yaml:"basic-auth"`
|
||||||
} `yaml:"sites"`
|
} `yaml:"sites"`
|
||||||
Style string `yaml:"style"`
|
Style string `yaml:"style"`
|
||||||
ShowFailingOnly bool `yaml:"show-failing-only"`
|
ShowFailingOnly bool `yaml:"show-failing-only"`
|
||||||
@ -45,6 +49,10 @@ func (widget *monitorWidget) update(ctx context.Context) {
|
|||||||
|
|
||||||
for i := range widget.Sites {
|
for i := range widget.Sites {
|
||||||
requests[i] = widget.Sites[i].SiteStatusRequest
|
requests[i] = widget.Sites[i].SiteStatusRequest
|
||||||
|
if widget.Sites[i].BasicAuth.Username != "" || widget.Sites[i].BasicAuth.Password != "" {
|
||||||
|
requests[i].Username = widget.Sites[i].BasicAuth.Username
|
||||||
|
requests[i].Password = widget.Sites[i].BasicAuth.Password
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
statuses, err := fetchStatusForSites(requests)
|
statuses, err := fetchStatusForSites(requests)
|
||||||
@ -118,6 +126,8 @@ type SiteStatusRequest struct {
|
|||||||
DefaultURL string `yaml:"url"`
|
DefaultURL string `yaml:"url"`
|
||||||
CheckURL string `yaml:"check-url"`
|
CheckURL string `yaml:"check-url"`
|
||||||
AllowInsecure bool `yaml:"allow-insecure"`
|
AllowInsecure bool `yaml:"allow-insecure"`
|
||||||
|
Username string `yaml:"-"`
|
||||||
|
Password string `yaml:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type siteStatus struct {
|
type siteStatus struct {
|
||||||
@ -141,6 +151,10 @@ func fetchSiteStatusTask(statusRequest *SiteStatusRequest) (siteStatus, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if statusRequest.Username != "" || statusRequest.Password != "" {
|
||||||
|
request.SetBasicAuth(statusRequest.Username, statusRequest.Password)
|
||||||
|
}
|
||||||
|
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
request = request.WithContext(ctx)
|
request = request.WithContext(ctx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user