Selaa lähdekoodia

Merge pull request #367 from ejsadiarin/dev

feat(monitor): add basic-auth feature for protected sites
Svilen Markov 4 kuukautta sitten
vanhempi
commit
4d6600b0a3
2 muutettua tiedostoa jossa 19 lisäystä ja 0 poistoa
  1. 11 0
      docs/configuration.md
  2. 8 0
      internal/glance/widget-monitor.go

+ 11 - 0
docs/configuration.md

@@ -1476,6 +1476,7 @@ Properties for each site:
 | allow-insecure | boolean | no | false |
 | allow-insecure | boolean | no | false |
 | same-tab | boolean | no | false |
 | same-tab | boolean | no | false |
 | alt-status-codes | array | no | |
 | alt-status-codes | array | no | |
+| basic-auth | object | no | |
 
 
 `title`
 `title`
 
 
@@ -1524,6 +1525,16 @@ alt-status-codes:
   - 403
   - 403
 ```
 ```
 
 
+`basic-auth`
+
+HTTP Basic Authentication credentials for protected sites.
+
+```yaml
+basic-auth:
+  usename: your-username
+  password: your-password
+```
+
 ### Releases
 ### Releases
 Display a list of latest releases for specific repositories on Github, GitLab, Codeberg or Docker Hub.
 Display a list of latest releases for specific repositories on Github, GitLab, Codeberg or Docker Hub.
 
 

+ 8 - 0
internal/glance/widget-monitor.go

@@ -118,6 +118,10 @@ 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"`
+	BasicAuth     struct {
+		Username string `yaml:"username"`
+		Password string `yaml:"password"`
+	} `yaml:"basic-auth"`
 }
 }
 
 
 type siteStatus struct {
 type siteStatus struct {
@@ -141,6 +145,10 @@ func fetchSiteStatusTask(statusRequest *SiteStatusRequest) (siteStatus, error) {
 		}, nil
 		}, 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)
 	ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
 	defer cancel()
 	defer cancel()
 	request = request.WithContext(ctx)
 	request = request.WithContext(ctx)