Skip to content

Commit b60bf67

Browse files
committed
Fix pagination for messaging client
Zaqar returns paths rather than URLs in 'links' response fields and the 'Location' header. In addition, since Dalmatian, it deploys under a path ('/messaging') rather then behind a port. This combination has highlighted a bug in our pagination page handling, namely that we are ignoring the path element of the endpoint URL. While this is not an issue when the 'next' link is an absolute URL, as with most other services, it results in incomplete URLs when the link URL is relative ('/v2/messages') and the endpoint URL contains a path ('https://example.com/messaging'). Fix this by concatenating the two paths, rather than overwriting the endpoint URLs path. Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
1 parent 93ff101 commit b60bf67

File tree

6 files changed

+24
-12
lines changed

6 files changed

+24
-12
lines changed

openstack/messaging/v2/messages/requests.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ func List(client *gophercloud.ServiceClient, queueName string, opts ListOptsBuil
4848
}
4949

5050
pager := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
51-
return MessagePage{pagination.LinkedPageBase{PageResult: r}}
51+
return MessagePage{
52+
serviceURL: client.ServiceURL(),
53+
LinkedPageBase: pagination.LinkedPageBase{PageResult: r},
54+
}
5255
})
5356
return pager
5457
}

openstack/messaging/v2/messages/results.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type CreateResult struct {
1212

1313
// MessagePage contains a single page of all clusters from a ListDetails call.
1414
type MessagePage struct {
15+
serviceURL string
1516
pagination.LinkedPageBase
1617
}
1718

@@ -127,5 +128,5 @@ func (r MessagePage) NextPageURL() (string, error) {
127128
if err != nil {
128129
return "", err
129130
}
130-
return nextPageURL(r.String(), next)
131+
return nextPageURL(r.serviceURL, next)
131132
}

openstack/messaging/v2/messages/urls.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ func messageURL(client *gophercloud.ServiceClient, queueName string, messageID s
3535
return client.ServiceURL(apiVersion, apiName, queueName, "messages", messageID)
3636
}
3737

38-
// Builds next page full url based on current url.
39-
func nextPageURL(currentURL string, next string) (string, error) {
40-
base, err := url.Parse(currentURL)
38+
// builds next page full url based on service endpoint
39+
func nextPageURL(serviceURL, next string) (string, error) {
40+
base, err := url.Parse(serviceURL)
4141
if err != nil {
4242
return "", err
4343
}
4444
rel, err := url.Parse(next)
4545
if err != nil {
4646
return "", err
4747
}
48-
return base.ResolveReference(rel).String(), nil
48+
combined := base.JoinPath(rel.Path)
49+
combined.RawQuery = rel.RawQuery
50+
return combined.String(), nil
4951
}

openstack/messaging/v2/queues/requests.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ func List(client *gophercloud.ServiceClient, opts ListOptsBuilder) pagination.Pa
4949
}
5050

5151
pager := pagination.NewPager(client, url, func(r pagination.PageResult) pagination.Page {
52-
return QueuePage{pagination.LinkedPageBase{PageResult: r}}
52+
return QueuePage{
53+
serviceURL: client.ServiceURL(),
54+
LinkedPageBase: pagination.LinkedPageBase{PageResult: r},
55+
}
5356

5457
})
5558
return pager

openstack/messaging/v2/queues/results.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type commonResult struct {
1414

1515
// QueuePage contains a single page of all queues from a List operation.
1616
type QueuePage struct {
17+
serviceURL string
1718
pagination.LinkedPageBase
1819
}
1920

@@ -173,7 +174,7 @@ func (r QueuePage) NextPageURL() (string, error) {
173174
if err != nil {
174175
return "", err
175176
}
176-
return nextPageURL(r.String(), next)
177+
return nextPageURL(r.serviceURL, next)
177178
}
178179

179180
// GetCount value if it request was supplied `WithCount` param

openstack/messaging/v2/queues/urls.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ func purgeURL(client *gophercloud.ServiceClient, queueName string) string {
4747
return client.ServiceURL(apiVersion, apiName, queueName, "purge")
4848
}
4949

50-
// builds next page full url based on current url
51-
func nextPageURL(currentURL string, next string) (string, error) {
52-
base, err := url.Parse(currentURL)
50+
// builds next page full url based on service endpoint
51+
func nextPageURL(serviceURL string, next string) (string, error) {
52+
base, err := url.Parse(serviceURL)
5353
if err != nil {
5454
return "", err
5555
}
5656
rel, err := url.Parse(next)
5757
if err != nil {
5858
return "", err
5959
}
60-
return base.ResolveReference(rel).String(), nil
60+
combined := base.JoinPath(rel.Path)
61+
combined.RawQuery = rel.RawQuery
62+
return combined.String(), nil
6163
}

0 commit comments

Comments
 (0)