Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: container registry test connection not checking the correct endpoint
Kyle Mendell9d2c2513a2f6
diff --git a/backend/internal/utils/registry/test_connection.go b/backend/internal/utils/registry/test_connection.goindex 6b5ba2b24..bbbc9ebc6 100644--- a/backend/internal/utils/registry/test_connection.go+++ b/backend/internal/utils/registry/test_connection.go@@ -2,7 +2,9 @@ package registryimport ("context"+ "encoding/base64""fmt"+ "net/http""strings""time")@@ -40,24 +42,67 @@ func TestRegistryConnection(ctx context.Context, registryURL string, creds *Credres.PingSuccess = true}+ var authHeader string+if authURL != "" && creds != nil {- tok, err := c.GetToken(ctx, authURL, "library/hello-world", creds)- if err != nil {- res.Errors = append(res.Errors, fmt.Sprintf("Auth failed: %v", err))- res.AuthSuccess = false+ if tok, err := c.GetTokenMulti(ctx, authURL, []string{}, creds); err == nil && tok != "" {+ res.AuthSuccess = true+ authHeader = "Bearer " + tok} else {- res.AuthSuccess = tok != ""+ pingURL := c.GetRegistryURL(reg) + "/v2/"+ ctx2, cancel := context.WithTimeout(ctx, 10*time.Second)+ defer cancel()+ req, rerr := http.NewRequestWithContext(ctx2, http.MethodGet, pingURL, nil)+ if rerr == nil {+ req.SetBasicAuth(creds.Username, creds.Token)+ resp, derr := c.http.Do(req)+ if derr == nil {+ defer resp.Body.Close()+ if resp.StatusCode == http.StatusOK {+ res.AuthSuccess = true+ ba := []byte(creds.Username + ":" + creds.Token)+ authHeader = "Basic " + base64.StdEncoding.EncodeToString(ba)+ } else {+ res.Errors = append(res.Errors, fmt.Sprintf("Auth failed: status %d", resp.StatusCode))+ res.AuthSuccess = false+ }+ } else {+ res.Errors = append(res.Errors, fmt.Sprintf("Auth request failed: %v", derr))+ res.AuthSuccess = false+ }+ } else {+ res.Errors = append(res.Errors, fmt.Sprintf("Auth request creation failed: %v", rerr))+ res.AuthSuccess = false+ }}} else {- res.AuthSuccess = authURL == ""+ res.AuthSuccess = (authURL == "")}- tags, err := c.GetImageTags(ctx, reg, "library/hello-world", "")+ catalogURL := c.GetRegistryURL(reg) + "/v2/_catalog"+ ctx3, cancel3 := context.WithTimeout(ctx, 15*time.Second)+ defer cancel3()+ req, err := http.NewRequestWithContext(ctx3, http.MethodGet, catalogURL, nil)if err != nil {- res.Errors = append(res.Errors, fmt.Sprintf("Catalog failed: %v", err))+ res.Errors = append(res.Errors, fmt.Sprintf("Catalog request creation failed: %v", err))res.CatalogSuccess = false} else {- res.CatalogSuccess = len(tags) > 0+ if authHeader != "" {+ req.Header.Set("Authorization", authHeader)+ }+ resp, derr := c.http.Do(req)+ if derr != nil {+ res.Errors = append(res.Errors, fmt.Sprintf("Catalog request failed: %v", derr))+ res.CatalogSuccess = false+ } else {+ defer resp.Body.Close()+ if resp.StatusCode == http.StatusOK {+ res.CatalogSuccess = true+ } else {+ res.CatalogSuccess = false+ res.Errors = append(res.Errors, fmt.Sprintf("Catalog returned status: %d", resp.StatusCode))+ }+ }}res.OverallSuccess = res.PingSuccess && res.AuthSuccess && res.CatalogSuccess