Closed suonto closed 8 years ago
I think the current code is working as intended. If you know your identity endpoint, you can explicitly create a ProviderClient
and set the IdentityBase
/IdentityEndpoint
fields
@jrperritt Could you please share your reasoning supporting the claim that NewClient should strip the relative paths from IdentityBase?
The justification for not stripping it is obvious: IdentityEndpoint is always constructed from IdentityBase + version. Thus, IdentityBase for endpoint http://example.com/foo/v3 should resolve to http://example.com/foo/, not http://example.com/.
Also, there was a similar relative path issue in python-openstacksdk, which was recognized and recently fixed: https://github.com/openstack/python-openstacksdk/commit/1430a8f2479cc0cd1caf72cfaecfcd84925f1227
Could you please share your reasoning supporting the claim that NewClient should strip the relative paths from IdentityBase?
I didn't claim that; I said it's working as intended. What's there works for default OpenStack implementations. Custom deployments can currently create a ProviderClient
explicitly.
I see. I also understand that you can create client and then modify the IdentityBase, but that applies only when you are using gophercloud directly. If you are, for example, running kubernetes with openstack cloud provider, it doesn't really work that way. Anyway, the new code works exactly the same as old for default endpoints (verified by unit tests), but also supports non-default endpoints. So, could you please merge it?
I'll take a look on Monday
I preserved the regexp for a few reasons.
Added also more tests to verify thoroughly
Regular expressions are lazy and error-prone. They are to be used when you don't know what you'll be parsing, nor where it will be. In this case, we know both the options and the location. Because of that, using a regular expression here is not appropriate. I'd gladly review and merge this PR if you want to implement suggestion 1 in my comment above. Otherwise, it looks like we're at an impasse.
@jrperritt have you had time to see the regexp-less implementation?
This looks good. Thank you for all the tests. +2
gophercloud.provider_client.go struct ProviderClient describes IdentityBase as follows: "IdentityBase is the base URL used for a particular provider's identity service - it will be used when issuing authenticatation requests. It should point to the root resource of the identity service, not a specific identity version."
Currently gophercloud.openstack.client.go func NewClient strips endpoints with a non-empty relative path. For example, the IdentityBase returned for endpoint:
http://example.com/foo
is:
http://example.com/
when it should be:
http://example.com/foo/
This change fixes NewClient to correctly handle such cases.
Unit tests are provided in openstack.test_client.go
[1] gophercloud.openstack.client.go
Fixes-Issue: #577