Fix identity endpoint

Change-Id: I2db64d89a4ebcb2dd37276abaf89400dc055c1a4
Closes-Bug: 1709270
Signed-off-by: mozhuli <21621232@zju.edu.cn>
This commit is contained in:
mozhulee 2017-08-08 19:24:55 +08:00
parent c82bbccf1d
commit 328463416e
3 changed files with 31 additions and 13 deletions

View File

@ -1,23 +1,26 @@
package tenants
import "github.com/gophercloud/gophercloud"
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/utils"
)
func listURL(client *gophercloud.ServiceClient) string {
return client.ServiceURL("v2.0/tenants")
return utils.V2ServiceURL(client, "tenants")
}
func getURL(client *gophercloud.ServiceClient, tenantID string) string {
return client.ServiceURL("v2.0/tenants", tenantID)
return utils.V2ServiceURL(client, "tenants", tenantID)
}
func createURL(client *gophercloud.ServiceClient) string {
return client.ServiceURL("v2.0/tenants")
return utils.V2ServiceURL(client, "tenants")
}
func deleteURL(client *gophercloud.ServiceClient, tenantID string) string {
return client.ServiceURL("v2.0/tenants", tenantID)
return utils.V2ServiceURL(client, "tenants", tenantID)
}
func updateURL(client *gophercloud.ServiceClient, tenantID string) string {
return client.ServiceURL("v2.0/tenants", tenantID)
return utils.V2ServiceURL(client, "tenants", tenantID)
}

View File

@ -1,25 +1,28 @@
package users
import "github.com/gophercloud/gophercloud"
import (
"github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/utils"
)
const (
tenantPath = "v2.0/tenants"
userPath = "v2.0/users"
tenantPath = "tenants"
userPath = "users"
rolePath = "roles"
)
func ResourceURL(c *gophercloud.ServiceClient, id string) string {
return c.ServiceURL(userPath, id)
return utils.V2ServiceURL(c, userPath, id)
}
func rootURL(c *gophercloud.ServiceClient) string {
return c.ServiceURL(userPath)
return utils.V2ServiceURL(c, userPath)
}
func listRolesURL(c *gophercloud.ServiceClient, tenantID, userID string) string {
return c.ServiceURL(tenantPath, tenantID, userPath, userID, rolePath)
return utils.V2ServiceURL(c, tenantPath, tenantID, userPath, userID, rolePath)
}
func listUsersURL(c *gophercloud.ServiceClient, tenantID string) string {
return c.ServiceURL(tenantPath, tenantID, "users")
return utils.V2ServiceURL(c, tenantPath, tenantID, userPath)
}

View File

@ -7,6 +7,18 @@ import (
"github.com/gophercloud/gophercloud"
)
// V2ServiceURL insures service url use v2.0 version.
func V2ServiceURL(client *gophercloud.ServiceClient, parts ...string) string {
baseURL := client.ResourceBaseURL()
if strings.HasSuffix(baseURL, "v2.0/") {
return baseURL + strings.Join(parts, "/")
}
if strings.HasSuffix(baseURL, "v3/") {
return strings.Replace(baseURL, "v3/", "v2.0/", 1) + strings.Join(parts, "/")
}
return baseURL + "v2.0/" + strings.Join(parts, "/")
}
// Version is a supported API version, corresponding to a vN package within the appropriate service.
type Version struct {
ID string