Skip to content

Commit 2bf97ce

Browse files
committed
Add BaseVersionedEndpoint helper
This retrieves the base endpoint without stripping the version information. This is helpful for service catalog entries that include project IDs, like those historically preferred by Cinder for some reason. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent bae4c6f commit 2bf97ce

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

openstack/utils/base_endpoint.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import (
66
"strings"
77
)
88

9-
// BaseEndpoint will return a URL without the /vX.Y
10-
// portion of the URL.
11-
func BaseEndpoint(endpoint string) (string, error) {
9+
func parseEndpoint(endpoint string, includeVersion bool) (string, error) {
1210
u, err := url.Parse(endpoint)
1311
if err != nil {
1412
return "", err
@@ -21,8 +19,23 @@ func BaseEndpoint(endpoint string) (string, error) {
2119

2220
if version := versionRe.FindString(path); version != "" {
2321
versionIndex := strings.Index(path, version)
22+
if includeVersion {
23+
versionIndex += len(version)
24+
}
2425
u.Path = path[:versionIndex]
2526
}
2627

2728
return u.String(), nil
2829
}
30+
31+
// BaseEndpoint will return a URL without the /vX.Y
32+
// portion of the URL.
33+
func BaseEndpoint(endpoint string) (string, error) {
34+
return parseEndpoint(endpoint, false)
35+
}
36+
37+
// BaseVersionedEndpoint will return a URL with the /vX.Y portion of the URL,
38+
// if present, but without a project ID or similar
39+
func BaseVersionedEndpoint(endpoint string) (string, error) {
40+
return parseEndpoint(endpoint, true)
41+
}

0 commit comments

Comments
 (0)