mirror of
https://github.com/andreicscs/HoneyWire
synced 2026-06-26 12:39:53 +00:00
fixed timeout on registry fetching and fixed version comparison of sensors against registry for updates
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
@@ -55,7 +56,8 @@ func (s *Service) RefreshIndex() error {
|
||||
indexURL := strings.TrimRight(registryURL, "/") + "/index.json"
|
||||
var idx RegistryIndex
|
||||
|
||||
resp, err := http.Get(indexURL)
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
resp, err := client.Get(indexURL)
|
||||
if err != nil || resp.StatusCode != http.StatusOK {
|
||||
return fmt.Errorf("failed to fetch registry index")
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"golang.org/x/mod/semver"
|
||||
|
||||
@@ -103,7 +104,8 @@ func (s *Service) fetchStrictCatalogManifests(currentHubVersion string) ([]model
|
||||
sensorName := strings.TrimPrefix(sensor.ID, "hw-sensor-")
|
||||
manifestURL := fmt.Sprintf("%s/%s-v%s.json", strings.TrimRight(registryURL, "/"), sensorName, targetVersion)
|
||||
|
||||
mResp, fetchErr := http.Get(manifestURL)
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
mResp, fetchErr := client.Get(manifestURL)
|
||||
if fetchErr != nil {
|
||||
log.Printf("[WARNING] Failed to fetch %s: %v", manifestURL, fetchErr)
|
||||
continue
|
||||
@@ -151,7 +153,8 @@ func (s *Service) FetchSpecificManifest(sensorID, targetVersion string) (*models
|
||||
return &cached, nil
|
||||
}
|
||||
|
||||
mResp, fetchErr := http.Get(manifestURL)
|
||||
client := &http.Client{Timeout: 10 * time.Second}
|
||||
mResp, fetchErr := client.Get(manifestURL)
|
||||
if fetchErr != nil {
|
||||
log.Printf("[ERROR] FetchSpecificManifest network error: %v", fetchErr)
|
||||
return nil, fetchErr
|
||||
|
||||
@@ -8,6 +8,9 @@ import (
|
||||
"log"
|
||||
"sort"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/mod/semver"
|
||||
|
||||
"github.com/honeywire/hub/internal/catalog"
|
||||
"github.com/honeywire/hub/internal/models"
|
||||
@@ -131,8 +134,17 @@ func (s *Service) GetNodeDetails(nodeID string) (*models.Node, error) {
|
||||
for i, sensor := range node.InstalledSensors {
|
||||
latest, err := s.catalog.GetLatestCompatibleVersion(sensor.ID, models.HubVersion)
|
||||
if err == nil && latest != "" {
|
||||
deployedVer := sensor.DeployedVersion
|
||||
if deployedVer != latest {
|
||||
deployedVer := strings.TrimSpace(sensor.DeployedVersion)
|
||||
if !strings.HasPrefix(deployedVer, "v") && deployedVer != "" {
|
||||
deployedVer = "v" + deployedVer
|
||||
}
|
||||
|
||||
latestVer := strings.TrimSpace(latest)
|
||||
if !strings.HasPrefix(latestVer, "v") && latestVer != "" {
|
||||
latestVer = "v" + latestVer
|
||||
}
|
||||
|
||||
if deployedVer != "" && semver.Compare(deployedVer, latestVer) < 0 {
|
||||
node.InstalledSensors[i].UpdateAvailable = true
|
||||
node.HasUpdateAvailable = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user