Skip to content

Commit a6c7ae4

Browse files
josunectCali0707
andauthored
[TOOLSET] Kiali: Allow kiali url with path (#477)
* Allow kiali url with path Signed-off-by: josunect <jcordoba@redhat.com> * Update pkg/kiali/kiali.go Co-authored-by: Calum Murray <cmurray@redhat.com> Signed-off-by: josunect <jcordoba@redhat.com> --------- Signed-off-by: josunect <jcordoba@redhat.com> Co-authored-by: Calum Murray <cmurray@redhat.com>
1 parent 63166ea commit a6c7ae4

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

pkg/kiali/kiali.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,23 @@ func (k *Kiali) validateAndGetURL(endpoint string) (string, error) {
5353
if endpoint == "" {
5454
return baseURL.String(), nil
5555
}
56-
ref, err := url.Parse(endpoint)
56+
// Parse the endpoint to extract path, query, and fragment
57+
endpoint = strings.TrimSpace(endpoint)
58+
endpointURL, err := url.Parse(endpoint)
59+
5760
if err != nil {
5861
return "", fmt.Errorf("invalid endpoint path: %w", err)
5962
}
60-
return baseURL.ResolveReference(ref).String(), nil
63+
resultURL, err := url.JoinPath(baseURL.String(), endpointURL.Path)
64+
if err != nil {
65+
return "", fmt.Errorf("failed to join kiali base URL with endpoint path: %w", err)
66+
}
67+
68+
u, _ := url.Parse(resultURL)
69+
u.RawQuery = endpointURL.RawQuery
70+
u.Fragment = endpointURL.Fragment
71+
72+
return u.String(), nil
6173
}
6274

6375
func (k *Kiali) createHTTPClient() *http.Client {

pkg/kiali/kiali_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,36 @@ func (s *KialiSuite) TestValidateAndGetURL() {
9898
s.Equal("2", u.Query().Get("y"), "Unexpected query parameter y")
9999
})
100100
})
101+
102+
s.Run("With base URL containing path", func() {
103+
s.Config = test.Must(config.ReadToml([]byte(`
104+
[toolset_configs.kiali]
105+
url = "http://kiali-istio-system.apps-crc.testing/kiali"
106+
insecure = true
107+
`)))
108+
k := NewKiali(s.Config, s.MockServer.Config())
109+
110+
s.Run("concatenates base path with endpoint", func() {
111+
full, err := k.validateAndGetURL("/api/namespaces")
112+
s.Require().NoError(err, "Expected no error validating URL")
113+
s.Equal("http://kiali-istio-system.apps-crc.testing/kiali/api/namespaces", full, "Unexpected full URL")
114+
})
115+
116+
s.Run("handles endpoint without leading slash", func() {
117+
full, err := k.validateAndGetURL("api/namespaces")
118+
s.Require().NoError(err, "Expected no error validating URL")
119+
s.Equal("http://kiali-istio-system.apps-crc.testing/kiali/api/namespaces", full, "Unexpected full URL")
120+
})
121+
122+
s.Run("preserves query parameters with base path", func() {
123+
full, err := k.validateAndGetURL("/api/namespaces?health=true")
124+
s.Require().NoError(err, "Expected no error validating URL")
125+
u, err := url.Parse(full)
126+
s.Require().NoError(err, "Expected to parse full URL")
127+
s.Equal("/kiali/api/namespaces", u.Path, "Unexpected path in parsed URL")
128+
s.Equal("true", u.Query().Get("health"), "Unexpected query parameter health")
129+
})
130+
})
101131
}
102132

103133
// CurrentAuthorizationHeader behavior is now implicit via executeRequest using Manager.BearerToken

0 commit comments

Comments
 (0)