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
{
internal TestStorageServicePocoClient ServicePocoClient;
internal TestOpenstackServiceEndpointResolver resovler;
internal string authId = "12345";
internal string endpoint = "http://teststorageendpoint.com/v1/1234567890";
@ -39,15 +41,18 @@ namespace Openstack.Test.Storage
public void TestSetup()
{
this.ServicePocoClient = new TestStorageServicePocoClient();
this.resovler = new TestOpenstackServiceEndpointResolver();
ServiceLocator.Reset();
var manager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(IStorageServicePocoClientFactory), new TestStorageServicePocoClientFactory(ServicePocoClient));
manager.RegisterServiceInstance(typeof(IOpenstackServiceEndpointResolver), resovler);
}
[TestCleanup]
public void TestCleanup()
{
this.resovler = new TestOpenstackServiceEndpointResolver();
this.ServicePocoClient = new TestStorageServicePocoClient();
ServiceLocator.Reset();
}
@ -59,6 +64,16 @@ namespace Openstack.Test.Storage
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]
public async Task CanListStorageObjects()
{

View File

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

View File

@ -35,6 +35,15 @@ namespace Openstack.Storage
//TODO: make this configurable
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>
/// Creates a new instance of the StorageServiceClient class.
/// </summary>