Description
I'm using docker-socket-proxy on another host behind Traefik and the widget silently replaces https:// with http:// in the sock-path URL.
Running Glance 0.8.4 in a Docker container. The culprit appears to be widget-docker-containers.go line 320 where http:// is hardcoded.
To reproduce, add the following to glances.yml. The second widget will return fetching containers: non-200 response status: 404 Not Found
- type: docker-containers
hide-by-default: false
sock-path: http://dockerproxy:2375
- type: docker-containers
hide-by-default: false
sock-path: https://host.example.com:8443
The following change seems to resolve the issue for me. Happy to have a go at a PR if useful.
diff --git a/internal/glance/widget-docker-containers.go b/internal/glance/widget-docker-containers.go
index 702a34b..6a8ed5f 100644
--- a/internal/glance/widget-docker-containers.go
+++ b/internal/glance/widget-docker-containers.go
@@ -286,9 +286,10 @@ func fetchDockerContainersFromSource(
labelOverrides map[string]map[string]string,
) ([]dockerContainerJsonResponse, error) {
var hostname string
+ var scheme string
var client *http.Client
- if strings.HasPrefix(source, "tcp://") || strings.HasPrefix(source, "http://") {
+ if strings.HasPrefix(source, "tcp://") || strings.HasPrefix(source, "http://") || strings.HasPrefix(source, "https://") {
client = &http.Client{}
parsed, err := url.Parse(source)
if err != nil {
@@ -299,6 +300,7 @@ func fetchDockerContainersFromSource(
if port == "" {
port = "80"
}
+ scheme = parsed.Scheme
hostname = parsed.Hostname() + ":" + port
} else {
@@ -317,7 +319,7 @@ func fetchDockerContainersFromSource(
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
- request, err := http.NewRequestWithContext(ctx, "GET", "http://"+hostname+"/containers/json?all="+fetchAll, nil)
+ request, err := http.NewRequestWithContext(ctx, "GET", scheme+"://"+hostname+"/containers/json?all="+fetchAll, nil)
if err != nil {
return nil, fmt.Errorf("creating request: %w", err)
}
Description
I'm using docker-socket-proxy on another host behind Traefik and the widget silently replaces https:// with http:// in the sock-path URL.
Running Glance 0.8.4 in a Docker container. The culprit appears to be widget-docker-containers.go line 320 where http:// is hardcoded.
To reproduce, add the following to glances.yml. The second widget will return
fetching containers: non-200 response status: 404 Not FoundThe following change seems to resolve the issue for me. Happy to have a go at a PR if useful.