Adding a pubic endpoint to storage client for CLI compaT

Change-Id: Iee94c34bcdcb084cd0ab9658c742c9b122c7dfa8
This commit is contained in:
Wayne Foley 2014-03-24 09:41:07 -07:00
parent 23fdb90c2b
commit 0cf38a29c0
3 changed files with 32 additions and 0 deletions

View File

@ -32,6 +32,8 @@ namespace Openstack.Test.Storage
public class StorageServiceClientTests public class StorageServiceClientTests
{ {
internal TestStorageServicePocoClient ServicePocoClient; internal TestStorageServicePocoClient ServicePocoClient;
internal TestOpenstackServiceEndpointResolver resovler;
internal string authId = "12345"; internal string authId = "12345";
internal string endpoint = "http://teststorageendpoint.com/v1/1234567890"; internal string endpoint = "http://teststorageendpoint.com/v1/1234567890";
@ -39,15 +41,18 @@ namespace Openstack.Test.Storage
public void TestSetup() public void TestSetup()
{ {
this.ServicePocoClient = new TestStorageServicePocoClient(); this.ServicePocoClient = new TestStorageServicePocoClient();
this.resovler = new TestOpenstackServiceEndpointResolver();
ServiceLocator.Reset(); ServiceLocator.Reset();
var manager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>(); var manager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(IStorageServicePocoClientFactory), new TestStorageServicePocoClientFactory(ServicePocoClient)); manager.RegisterServiceInstance(typeof(IStorageServicePocoClientFactory), new TestStorageServicePocoClientFactory(ServicePocoClient));
manager.RegisterServiceInstance(typeof(IOpenstackServiceEndpointResolver), resovler);
} }
[TestCleanup] [TestCleanup]
public void TestCleanup() public void TestCleanup()
{ {
this.resovler = new TestOpenstackServiceEndpointResolver();
this.ServicePocoClient = new TestStorageServicePocoClient(); this.ServicePocoClient = new TestStorageServicePocoClient();
ServiceLocator.Reset(); ServiceLocator.Reset();
} }
@ -59,6 +64,16 @@ namespace Openstack.Test.Storage
return creds; return creds;
} }
[TestMethod]
public void CanGetPublicEndpoint()
{
var expectedUri = new Uri(endpoint);
this.resovler.Endpoint = expectedUri;
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
Assert.AreEqual(expectedUri, client.GetPublicEndpoint());
}
[TestMethod] [TestMethod]
public async Task CanListStorageObjects() public async Task CanListStorageObjects()
{ {

View File

@ -14,6 +14,8 @@
// limitations under the License. // limitations under the License.
// ============================================================================ */ // ============================================================================ */
using System;
namespace Openstack.Storage namespace Openstack.Storage
{ {
using System.Collections.Generic; using System.Collections.Generic;
@ -25,6 +27,12 @@ namespace Openstack.Storage
/// </summary> /// </summary>
public interface IStorageServiceClient : IOpenstackServiceClient public interface IStorageServiceClient : IOpenstackServiceClient
{ {
/// <summary>
/// Gets the current public endpoint that this client is using.
/// </summary>
/// <returns>The public Uri.</returns>
Uri GetPublicEndpoint();
/// <summary> /// <summary>
/// Creates a storage container on the remote Openstack instance. /// Creates a storage container on the remote Openstack instance.
/// </summary> /// </summary>

View File

@ -35,6 +35,15 @@ namespace Openstack.Storage
//TODO: make this configurable //TODO: make this configurable
internal string defaultRegion = "region-a.geo-1"; internal string defaultRegion = "region-a.geo-1";
public Uri GetPublicEndpoint()
{
//TODO: This should be removed as soon as the CLI can deprecate it's usage of it.
// The reason is that this breaks encapsulation. The rest layer/client is responsible for resolving it's own endpoint,
// This object should not also try and resolve the uri. In general we abstracted the consumer away from the URI, we should not break that
// abstraction.
return this.Context.Credential.ServiceCatalog.GetPublicEndpoint(StorageServiceName, this.defaultRegion);
}
/// <summary> /// <summary>
/// Creates a new instance of the StorageServiceClient class. /// Creates a new instance of the StorageServiceClient class.
/// </summary> /// </summary>