diff --git a/OpenStack/Examples/CustomServiceClientExample/EchoServiceClientDefinition.cs b/OpenStack/Examples/CustomServiceClientExample/EchoServiceClientDefinition.cs index 3bd64dc..c3a31ac 100644 --- a/OpenStack/Examples/CustomServiceClientExample/EchoServiceClientDefinition.cs +++ b/OpenStack/Examples/CustomServiceClientExample/EchoServiceClientDefinition.cs @@ -31,7 +31,7 @@ namespace CustomServiceClientExample this.Name = typeof(EchoServiceClient).Name; } - public IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator) + public IOpenStackServiceClient Create(ICredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator) { return new EchoServiceClient(credential, cancellationToken, serviceLocator); } @@ -41,7 +41,7 @@ namespace CustomServiceClientExample return new List(); } - public bool IsSupported(ICredential credential) + public bool IsSupported(ICredential credential, string serviceName) { return true; } diff --git a/OpenStack/Examples/SimpleStorageExample/SimpleStorageExample.csproj b/OpenStack/Examples/SimpleStorageExample/SimpleStorageExample.csproj index 506b261..eeca3fa 100644 --- a/OpenStack/Examples/SimpleStorageExample/SimpleStorageExample.csproj +++ b/OpenStack/Examples/SimpleStorageExample/SimpleStorageExample.csproj @@ -33,7 +33,7 @@ - ..\..\Bin\Debug\Newtonsoft.Json.dll + ..\..\Bin\net45\Debug\Newtonsoft.Json.dll False diff --git a/OpenStack/OpenStack.Test/HttpAbstraction/HttpAbstractionClientTests.cs b/OpenStack/OpenStack.Test/HttpAbstraction/HttpAbstractionClientTests.cs index 2ed9c72..7b0c847 100644 --- a/OpenStack/OpenStack.Test/HttpAbstraction/HttpAbstractionClientTests.cs +++ b/OpenStack/OpenStack.Test/HttpAbstraction/HttpAbstractionClientTests.cs @@ -70,7 +70,7 @@ namespace OpenStack.Test.HttpAbstraction Assert.IsTrue(response.Headers.Contains("Content-Length")); Assert.IsTrue(response.Headers.Contains("Content-Type")); - Assert.AreEqual("214", response.Headers["Content-Length"].First()); + Assert.AreEqual("213", response.Headers["Content-Length"].First()); Assert.AreEqual("application/json", response.Headers["Content-Type"].First()); Assert.IsNotNull(response.Content); diff --git a/OpenStack/OpenStack.Test/Identity/IdentityServiceClientDefinitionTests.cs b/OpenStack/OpenStack.Test/Identity/IdentityServiceClientDefinitionTests.cs index ff72921..396e02b 100644 --- a/OpenStack/OpenStack.Test/Identity/IdentityServiceClientDefinitionTests.cs +++ b/OpenStack/OpenStack.Test/Identity/IdentityServiceClientDefinitionTests.cs @@ -11,7 +11,7 @@ namespace OpenStack.Test.Identity { public IOpenStackCredential GetValidCredentials() { - var endpoint = new Uri("https://someidentityendpoint:35357/v2.0/tokens"); + var endpoint = new Uri("https://someidentityendpoint:35357/v2.0"); var userName = "TestUser"; var password = "RandomPassword"; var tenantId = "12345"; @@ -24,7 +24,7 @@ namespace OpenStack.Test.Identity { var client = new IdentityServiceClientDefinition(); - Assert.IsTrue(client.IsSupported(GetValidCredentials())); + Assert.IsTrue(client.IsSupported(GetValidCredentials(), string.Empty)); } [TestMethod] @@ -39,7 +39,7 @@ namespace OpenStack.Test.Identity var client = new IdentityServiceClientDefinition(); - Assert.IsFalse(client.IsSupported(creds)); + Assert.IsFalse(client.IsSupported(creds, string.Empty)); } [TestMethod] diff --git a/OpenStack/OpenStack.Test/Identity/IdentityServiceClientTests.cs b/OpenStack/OpenStack.Test/Identity/IdentityServiceClientTests.cs index 748ec37..6e2ca86 100644 --- a/OpenStack/OpenStack.Test/Identity/IdentityServiceClientTests.cs +++ b/OpenStack/OpenStack.Test/Identity/IdentityServiceClientTests.cs @@ -69,7 +69,7 @@ namespace OpenStack.Test.Identity return Task.Factory.StartNew(() => creds); }; - var client = new IdentityServiceClientDefinition().Create(GetValidCredentials(), CancellationToken.None, this.ServiceLocator) as IdentityServiceClient; + var client = new IdentityServiceClientDefinition().Create(GetValidCredentials(), string.Empty, CancellationToken.None, this.ServiceLocator) as IdentityServiceClient; var resp = await client.Authenticate(); Assert.AreEqual(creds, resp); diff --git a/OpenStack/OpenStack.Test/Identity/IdentityServicePocoClientTests.cs b/OpenStack/OpenStack.Test/Identity/IdentityServicePocoClientTests.cs index a01f9f8..e85f199 100644 --- a/OpenStack/OpenStack.Test/Identity/IdentityServicePocoClientTests.cs +++ b/OpenStack/OpenStack.Test/Identity/IdentityServicePocoClientTests.cs @@ -113,7 +113,7 @@ namespace OpenStack.Test.Identity this.RestClient.Response = restResp; var client = - new IdentityServicePocoClientFactory().Create(creds, CancellationToken.None, this.ServiceLocator) as + new IdentityServicePocoClientFactory().Create(creds, "Swift", CancellationToken.None, this.ServiceLocator) as IdentityServicePocoClient; var result = await client.Authenticate(); @@ -172,7 +172,7 @@ namespace OpenStack.Test.Identity var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation); this.RestClient.Response = restResp; - var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator); + var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator); var result = await client.Authenticate(); Assert.IsNotNull(result); @@ -229,7 +229,7 @@ namespace OpenStack.Test.Identity var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation); this.RestClient.Response = restResp; - var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator); + var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator); var result = await client.Authenticate(); Assert.AreEqual(expectedRegion, result.Region); @@ -244,7 +244,7 @@ namespace OpenStack.Test.Identity var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized); this.RestClient.Response = restResp; - var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator); + var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator); await client.Authenticate(); } @@ -257,7 +257,7 @@ namespace OpenStack.Test.Identity var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.BadRequest); this.RestClient.Response = restResp; - var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator); + var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator); await client.Authenticate(); } @@ -270,7 +270,7 @@ namespace OpenStack.Test.Identity var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError); this.RestClient.Response = restResp; - var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator); + var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator); await client.Authenticate(); } @@ -283,7 +283,7 @@ namespace OpenStack.Test.Identity var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Forbidden); this.RestClient.Response = restResp; - var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator); + var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator); await client.Authenticate(); } @@ -296,7 +296,7 @@ namespace OpenStack.Test.Identity var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.MethodNotAllowed); this.RestClient.Response = restResp; - var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator); + var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator); await client.Authenticate(); } @@ -309,7 +309,7 @@ namespace OpenStack.Test.Identity var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.RequestEntityTooLarge); this.RestClient.Response = restResp; - var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator); + var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator); await client.Authenticate(); } @@ -322,7 +322,7 @@ namespace OpenStack.Test.Identity var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.ServiceUnavailable); this.RestClient.Response = restResp; - var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator); + var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator); await client.Authenticate(); } @@ -335,7 +335,7 @@ namespace OpenStack.Test.Identity var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NotFound); this.RestClient.Response = restResp; - var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator); + var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator); await client.Authenticate(); } } diff --git a/OpenStack/OpenStack.Test/Identity/IdentityServiceRestClientTests.cs b/OpenStack/OpenStack.Test/Identity/IdentityServiceRestClientTests.cs index 3065233..a70c433 100644 --- a/OpenStack/OpenStack.Test/Identity/IdentityServiceRestClientTests.cs +++ b/OpenStack/OpenStack.Test/Identity/IdentityServiceRestClientTests.cs @@ -67,8 +67,8 @@ namespace OpenStack.Test.Identity var client = new IdentityServiceRestClientFactory().Create(creds,CancellationToken.None, this.ServiceLocator); await client.Authenticate(); - - Assert.AreEqual(creds.AuthenticationEndpoint, this.simulator.Uri); + var expectedUri = new Uri(string.Format("{0}/tokens", creds.AuthenticationEndpoint)); + Assert.AreEqual(expectedUri, this.simulator.Uri); Assert.AreEqual(HttpMethod.Post, this.simulator.Method); } diff --git a/OpenStack/OpenStack.Test/Identity/OpenStackRegionResolverTests.cs b/OpenStack/OpenStack.Test/Identity/OpenStackRegionResolverTests.cs index 4572948..8dd5ec5 100644 --- a/OpenStack/OpenStack.Test/Identity/OpenStackRegionResolverTests.cs +++ b/OpenStack/OpenStack.Test/Identity/OpenStackRegionResolverTests.cs @@ -78,6 +78,29 @@ namespace OpenStack.Test.Identity Assert.AreEqual(expectedRegion, region); } + [TestMethod] + public void CanResolveRegionWhenNoMatchingServicesButMatchingEndpoint() + { + var expectedRegion = "Some Region"; + var catalog = new OpenStackServiceCatalog(); + catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service", + new List() + { + new OpenStackServiceEndpoint("http://the.endpoint.org", "Some Region" , "1.0", + "http://www.someplace.com", "http://www.someplace.com") + })); + + catalog.Add(new OpenStackServiceDefinition("Other Test Service", "Test-Service", + new List() + { + new OpenStackServiceEndpoint("http://other.endpoint.org", "some other region", "1.0", + "http://www.someplace.com", "http://www.someplace.com") + })); + var resolver = new OpenStackRegionResolver(); + var region = resolver.Resolve(new Uri("http://the.endpoint.org/v2/tokens"), catalog, "No Matching Service"); + Assert.AreEqual(expectedRegion, region); + } + [TestMethod] public void CannotResolveRegionWhenMatchingEndpointHasEmptyRegion() { diff --git a/OpenStack/OpenStack.Test/Identity/OpenStackServiceEndpointPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Identity/OpenStackServiceEndpointPayloadConverterTests.cs index 809550b..207304a 100644 --- a/OpenStack/OpenStack.Test/Identity/OpenStackServiceEndpointPayloadConverterTests.cs +++ b/OpenStack/OpenStack.Test/Identity/OpenStackServiceEndpointPayloadConverterTests.cs @@ -97,8 +97,7 @@ namespace OpenStack.Test.Identity } [TestMethod] - [ExpectedException(typeof(FormatException))] - public void CannotConvertJsonPayloadWithMissingVersion() + public void CanConvertJsonPayloadWithMissingVersion() { var endpointPayload = @" { ""tenantId"": ""10244656540440"", @@ -114,8 +113,7 @@ namespace OpenStack.Test.Identity } [TestMethod] - [ExpectedException(typeof(FormatException))] - public void CannotConvertJsonPayloadWithMissingVersionInfoUri() + public void CanConvertJsonPayloadWithMissingVersionInfoUri() { var endpointPayload = @" { ""tenantId"": ""10244656540440"", @@ -131,8 +129,7 @@ namespace OpenStack.Test.Identity } [TestMethod] - [ExpectedException(typeof(FormatException))] - public void CannotConvertJsonPayloadWithMissingVersionListUri() + public void CanConvertJsonPayloadWithMissingVersionListUri() { var endpointPayload = @" { ""tenantId"": ""10244656540440"", diff --git a/OpenStack/OpenStack.Test/Identity/TestIdentityServicePocoClient.cs b/OpenStack/OpenStack.Test/Identity/TestIdentityServicePocoClient.cs index e0fd38a..d4886b3 100644 --- a/OpenStack/OpenStack.Test/Identity/TestIdentityServicePocoClient.cs +++ b/OpenStack/OpenStack.Test/Identity/TestIdentityServicePocoClient.cs @@ -41,7 +41,7 @@ namespace OpenStack.Test.Identity this.client = client; } - public IIdentityServicePocoClient Create(IOpenStackCredential credentials, CancellationToken token, IServiceLocator serviceLocator) + public IIdentityServicePocoClient Create(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator) { return client; } diff --git a/OpenStack/OpenStack.Test/OpenStackClientManagerTests.cs b/OpenStack/OpenStack.Test/OpenStackClientManagerTests.cs index 8e17899..729c0ca 100644 --- a/OpenStack/OpenStack.Test/OpenStackClientManagerTests.cs +++ b/OpenStack/OpenStack.Test/OpenStackClientManagerTests.cs @@ -83,6 +83,16 @@ namespace OpenStack.Test throw new NotImplementedException(); } + public T CreateServiceClientByName(string serviceName) where T : IOpenStackServiceClient + { + throw new NotImplementedException(); + } + + public T CreateServiceClientByName(string serviceName, string version) where T : IOpenStackServiceClient + { + throw new NotImplementedException(); + } + public IEnumerable GetSupportedVersions() { throw new NotImplementedException(); @@ -122,6 +132,16 @@ namespace OpenStack.Test throw new NotImplementedException(); } + public T CreateServiceClientByName(string serviceName) where T : IOpenStackServiceClient + { + throw new NotImplementedException(); + } + + public T CreateServiceClientByName(string serviceName, string version) where T : IOpenStackServiceClient + { + throw new NotImplementedException(); + } + public IEnumerable GetSupportedVersions() { throw new NotImplementedException(); @@ -166,6 +186,16 @@ namespace OpenStack.Test throw new NotImplementedException(); } + public T CreateServiceClientByName(string serviceName) where T : IOpenStackServiceClient + { + throw new NotImplementedException(); + } + + public T CreateServiceClientByName(string serviceName, string version) where T : IOpenStackServiceClient + { + throw new NotImplementedException(); + } + public IEnumerable GetSupportedVersions() { throw new NotImplementedException(); diff --git a/OpenStack/OpenStack.Test/OpenStackClientTests.cs b/OpenStack/OpenStack.Test/OpenStackClientTests.cs index 6281b2a..a908aa0 100644 --- a/OpenStack/OpenStack.Test/OpenStackClientTests.cs +++ b/OpenStack/OpenStack.Test/OpenStackClientTests.cs @@ -56,7 +56,7 @@ namespace OpenStack.Test { public string Name { get; private set; } - public IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator) + public IOpenStackServiceClient Create(ICredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator) { return new TestIdentityServiceClient((IOpenStackCredential)credential, cancellationToken); } @@ -66,7 +66,7 @@ namespace OpenStack.Test return new List(); } - public bool IsSupported(ICredential credential) + public bool IsSupported(ICredential credential, string serviceName) { return true; } diff --git a/OpenStack/OpenStack.Test/OpenStackServiceClientManagerTests.cs b/OpenStack/OpenStack.Test/OpenStackServiceClientManagerTests.cs index fabdadd..3ab6f50 100644 --- a/OpenStack/OpenStack.Test/OpenStackServiceClientManagerTests.cs +++ b/OpenStack/OpenStack.Test/OpenStackServiceClientManagerTests.cs @@ -39,7 +39,7 @@ namespace OpenStack.Test { public string Name { get; private set; } - public IOpenStackServiceClient Create(ICredential credential, CancellationToken token, IServiceLocator serviceLocator) + public IOpenStackServiceClient Create(ICredential credential, string serviceName, CancellationToken token, IServiceLocator serviceLocator) { return new TestOpenStackServiceClient(credential, token); } @@ -49,7 +49,7 @@ namespace OpenStack.Test throw new NotImplementedException(); } - public bool IsSupported(ICredential credential) + public bool IsSupported(ICredential credential, string serviceName) { return true; } @@ -82,7 +82,7 @@ namespace OpenStack.Test { public string Name { get; private set; } - public IOpenStackServiceClient Create(ICredential credential, CancellationToken token, IServiceLocator serviceLocator) + public IOpenStackServiceClient Create(ICredential credential, string serviceName, CancellationToken token, IServiceLocator serviceLocator) { return new OtherTestOpenStackServiceClient(credential, token); } @@ -92,7 +92,7 @@ namespace OpenStack.Test throw new NotImplementedException(); } - public bool IsSupported(ICredential credential) + public bool IsSupported(ICredential credential, string serviceName) { return false; } @@ -221,7 +221,7 @@ namespace OpenStack.Test { var manager = new OpenStackServiceClientManager(new ServiceLocator()); - var service = manager.CreateServiceClientInstance(new TestOpenStackServiceClientDefinition(), new OpenStackClientManagerTests.TestCredential(), CancellationToken.None); + var service = manager.CreateServiceClientInstance(new TestOpenStackServiceClientDefinition(), new OpenStackClientManagerTests.TestCredential(), string.Empty, CancellationToken.None); Assert.IsNotNull(service); Assert.IsInstanceOfType(service, typeof(TestOpenStackServiceClient)); } @@ -231,7 +231,7 @@ namespace OpenStack.Test public void CanCreateAnInstanceOfAServiceWithNullFactory() { var manager = new OpenStackServiceClientManager(new ServiceLocator()); - manager.CreateServiceClientInstance(null, new OpenStackClientManagerTests.TestCredential(), CancellationToken.None); + manager.CreateServiceClientInstance(null, new OpenStackClientManagerTests.TestCredential(), string.Empty, CancellationToken.None); } } } diff --git a/OpenStack/OpenStack.Test/Storage/StorageServiceClientDefinitionTests.cs b/OpenStack/OpenStack.Test/Storage/StorageServiceClientDefinitionTests.cs index 68cd7c6..d0142bc 100644 --- a/OpenStack/OpenStack.Test/Storage/StorageServiceClientDefinitionTests.cs +++ b/OpenStack/OpenStack.Test/Storage/StorageServiceClientDefinitionTests.cs @@ -29,7 +29,7 @@ namespace OpenStack.Test.Storage var catalog = new OpenStackServiceCatalog { - new OpenStackServiceDefinition("Object Storage", "Test", + new OpenStackServiceDefinition("Swift", "Test", new List() { new OpenStackServiceEndpoint("http://someplace.com", "somewhere", "1.0", @@ -37,7 +37,7 @@ namespace OpenStack.Test.Storage }) }; creds.SetServiceCatalog(catalog); - Assert.IsTrue(client.IsSupported(creds)); + Assert.IsTrue(client.IsSupported(creds, "Swift")); } [TestMethod] @@ -48,7 +48,7 @@ namespace OpenStack.Test.Storage var catalog = new OpenStackServiceCatalog { - new OpenStackServiceDefinition("Object Storage", "Test", + new OpenStackServiceDefinition("Swift", "Test", new List() { new OpenStackServiceEndpoint("http://someplace.com", "somewhere", "2.0.0.0", @@ -56,7 +56,26 @@ namespace OpenStack.Test.Storage }) }; creds.SetServiceCatalog(catalog); - Assert.IsFalse(client.IsSupported(creds)); + Assert.IsFalse(client.IsSupported(creds, "Swift")); + } + + [TestMethod] + public void CannotSupportUnknownServiceName() + { + var client = new StorageServiceClientDefinition(); + var creds = GetValidCreds(); + var catalog = + new OpenStackServiceCatalog + { + new OpenStackServiceDefinition("Swift", "Test", + new List() + { + new OpenStackServiceEndpoint("http://someplace.com", "somewhere", "1.0", + "http://www.someplace.com", "http://www.someplace.com") + }) + }; + creds.SetServiceCatalog(catalog); + Assert.IsFalse(client.IsSupported(creds, "BadServiceName")); } [TestMethod] diff --git a/OpenStack/OpenStack.Test/Storage/StorageServiceClientTests.cs b/OpenStack/OpenStack.Test/Storage/StorageServiceClientTests.cs index 2f0d80a..5858164 100644 --- a/OpenStack/OpenStack.Test/Storage/StorageServiceClientTests.cs +++ b/OpenStack/OpenStack.Test/Storage/StorageServiceClientTests.cs @@ -62,7 +62,7 @@ namespace OpenStack.Test.Storage IOpenStackCredential GetValidCreds() { var catalog = new OpenStackServiceCatalog(); - catalog.Add(new OpenStackServiceDefinition(StorageServiceClient.StorageServiceName, "Storage Service", + catalog.Add(new OpenStackServiceDefinition("Swift", "Storage Service", new List() { new OpenStackServiceEndpoint(endpoint, string.Empty, "some version", "some version info", "1,2,3") @@ -97,7 +97,7 @@ namespace OpenStack.Test.Storage return Task.Factory.StartNew(() => obj); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.ListStorageObjects(containerName); Assert.AreEqual(1,numberObjCalls); @@ -122,7 +122,7 @@ namespace OpenStack.Test.Storage throw new InvalidOperationException("Cannot get storage object. '" +HttpStatusCode.NotFound +"'"); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var resp = await client.ListStorageObjects(containerName); Assert.AreEqual(0, resp.Count()); @@ -132,7 +132,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task ListingStorageObjectsWithNullContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.ListStorageObjects(null); } @@ -156,7 +156,7 @@ namespace OpenStack.Test.Storage this.ServicePocoClient.GetStorageAccountDelegate = () => Task.Factory.StartNew(() => account); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var resp = await client.ListStorageContainers(); var containers = resp.ToList(); @@ -175,7 +175,7 @@ namespace OpenStack.Test.Storage return Task.Factory.StartNew(() => account); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var resp = await client.GetStorageAccount(); Assert.AreEqual(account, resp); @@ -197,7 +197,7 @@ namespace OpenStack.Test.Storage return Task.Factory.StartNew(() => obj); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var resp = await client.GetStorageObject(containerName, objectName); Assert.AreEqual(obj, resp); @@ -209,7 +209,7 @@ namespace OpenStack.Test.Storage { var objectName = "TestObject"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageObject(null, objectName); } @@ -219,7 +219,7 @@ namespace OpenStack.Test.Storage { var objectName = "TestObject"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageObject(string.Empty, objectName); } @@ -229,7 +229,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageObject(containerName, null); } @@ -239,7 +239,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageObject(containerName, string.Empty); } @@ -259,7 +259,7 @@ namespace OpenStack.Test.Storage return Task.Factory.StartNew(() => (StorageManifest)obj); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var resp = await client.GetStorageManifest(containerName, manifestName); Assert.AreEqual(obj, resp); @@ -271,7 +271,7 @@ namespace OpenStack.Test.Storage { var manifestName = "TestManifest"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageManifest(null, manifestName); } @@ -281,7 +281,7 @@ namespace OpenStack.Test.Storage { var manifestName = "TestManifest"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageObject(string.Empty, manifestName); } @@ -291,7 +291,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageManifest(containerName, null); } @@ -301,7 +301,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageManifest(containerName, string.Empty); } @@ -320,7 +320,7 @@ namespace OpenStack.Test.Storage return Task.Factory.StartNew(() => obj); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var resp = await client.GetStorageFolder(containerName, folderName); Assert.AreEqual(obj, resp); @@ -341,7 +341,7 @@ namespace OpenStack.Test.Storage return Task.Factory.StartNew(() => obj); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var resp = await client.GetStorageFolder(containerName, folderName); Assert.AreEqual(obj, resp); @@ -353,7 +353,7 @@ namespace OpenStack.Test.Storage { var folderName = "TestFolder"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageFolder(null, folderName); } @@ -363,7 +363,7 @@ namespace OpenStack.Test.Storage { var folderName = "TestFolder"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageFolder(string.Empty, folderName); } @@ -373,7 +373,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageFolder(containerName, null); } @@ -383,7 +383,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageFolder(containerName, string.Empty); } @@ -405,7 +405,7 @@ namespace OpenStack.Test.Storage return await Task.Run(()=>obj); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var resp = await client.CreateStorageObject(containerName, objectName, new Dictionary(), content); Assert.AreEqual(obj, resp); @@ -414,7 +414,7 @@ namespace OpenStack.Test.Storage [TestMethod] public async Task CreatingAnObjectLargerThanTheThresholdCreatesObjectWithSegments() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var containerName = "TestContainer"; var objectName = "TestObject"; @@ -465,7 +465,7 @@ namespace OpenStack.Test.Storage return await Task.Run(() => new StorageObject(o,c)); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var res = await client.CreateLargeStorageObject(containerName, objectName, metadata, contentStream, 3); Assert.AreEqual(containerName, res.ContainerName); @@ -481,7 +481,7 @@ namespace OpenStack.Test.Storage var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP"; var contentStream = content.ConvertToStream(); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var res = await client.CreateLargeStorageObject(null, objectName, metadata, contentStream, 3); } @@ -494,7 +494,7 @@ namespace OpenStack.Test.Storage var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP"; var contentStream = content.ConvertToStream(); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var res = await client.CreateLargeStorageObject(string.Empty, objectName, metadata, contentStream, 3); } @@ -507,7 +507,7 @@ namespace OpenStack.Test.Storage var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP"; var contentStream = content.ConvertToStream(); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var res = await client.CreateLargeStorageObject(containerName, null, metadata, contentStream, 3); } @@ -520,7 +520,7 @@ namespace OpenStack.Test.Storage var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP"; var contentStream = content.ConvertToStream(); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var res = await client.CreateLargeStorageObject(containerName, string.Empty, metadata, contentStream, 3); } @@ -533,7 +533,7 @@ namespace OpenStack.Test.Storage var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP"; var contentStream = content.ConvertToStream(); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var res = await client.CreateLargeStorageObject(containerName, objectName, null, contentStream, 3); } @@ -545,7 +545,7 @@ namespace OpenStack.Test.Storage var objectName = "TestObject"; var metadata = new Dictionary(); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var res = await client.CreateLargeStorageObject(containerName, objectName, metadata, null, 3); } @@ -559,7 +559,7 @@ namespace OpenStack.Test.Storage var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP"; var contentStream = content.ConvertToStream(); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var res = await client.CreateLargeStorageObject(containerName, objectName, metadata, contentStream, -3); } @@ -573,7 +573,7 @@ namespace OpenStack.Test.Storage var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP"; var contentStream = content.ConvertToStream(); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var res = await client.CreateLargeStorageObject(containerName, objectName, metadata, contentStream, 0); } @@ -583,7 +583,7 @@ namespace OpenStack.Test.Storage { var objectName = "TestObject"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageObject(null, objectName, new Dictionary(), new MemoryStream()); } @@ -593,7 +593,7 @@ namespace OpenStack.Test.Storage { var objectName = "TestObject"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageObject(string.Empty, objectName, new Dictionary(), new MemoryStream()); } @@ -603,7 +603,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageObject(containerName, null, new Dictionary(), new MemoryStream()); } @@ -613,7 +613,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageObject(containerName, string.Empty, new Dictionary(), new MemoryStream()); } @@ -624,7 +624,7 @@ namespace OpenStack.Test.Storage var containerName = "TestContainer"; var objectName = "TestObject"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageObject(containerName, objectName, new Dictionary(), null); } @@ -635,7 +635,7 @@ namespace OpenStack.Test.Storage var containerName = "TestContainer"; var objectName = "TestObject"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageObject(containerName, objectName, null, new MemoryStream()); } @@ -654,7 +654,7 @@ namespace OpenStack.Test.Storage return await Task.Run(() => m); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, objectName, new Dictionary(), new List() { obj }); } @@ -670,7 +670,7 @@ namespace OpenStack.Test.Storage return await Task.Run(() => m); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, objectName, new Dictionary(), "segments"); } @@ -681,7 +681,7 @@ namespace OpenStack.Test.Storage var manifestName = "TestManifest"; var segmentPath = "segments"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(null, manifestName, new Dictionary(), segmentPath); } @@ -692,7 +692,7 @@ namespace OpenStack.Test.Storage var manifestName = "TestManifest"; var segmentPath = "segments"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(string.Empty, manifestName, new Dictionary(), segmentPath); } @@ -703,7 +703,7 @@ namespace OpenStack.Test.Storage var containerName = "TestContainer"; var segmentPath = "segments"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, null, new Dictionary(), segmentPath); } @@ -714,7 +714,7 @@ namespace OpenStack.Test.Storage var containerName = "TestContainer"; var segmentPath = "segments"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, string.Empty, new Dictionary(), segmentPath); } @@ -725,7 +725,7 @@ namespace OpenStack.Test.Storage var containerName = "TestContainer"; var manifestName = "TestManifest"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, manifestName, new Dictionary(), (string)null); } @@ -736,7 +736,7 @@ namespace OpenStack.Test.Storage var containerName = "TestContainer"; var manifestName = "TestManifest"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, manifestName, new Dictionary(), string.Empty); } @@ -748,7 +748,7 @@ namespace OpenStack.Test.Storage var manifestName = "TestManifest"; var segmentPath = "segments"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, manifestName, null, segmentPath); } @@ -762,7 +762,7 @@ namespace OpenStack.Test.Storage var obj = new StorageObject(objectName, containerName, DateTime.UtcNow, "12345", 12345, "application/octet-stream", new Dictionary()); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(null, objectName, new Dictionary(), new List() { obj }); } @@ -776,7 +776,7 @@ namespace OpenStack.Test.Storage var obj = new StorageObject(objectName, containerName, DateTime.UtcNow, "12345", 12345, "application/octet-stream", new Dictionary()); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(string.Empty, objectName, new Dictionary(), new List() { obj }); } @@ -790,7 +790,7 @@ namespace OpenStack.Test.Storage var obj = new StorageObject(objectName, containerName, DateTime.UtcNow, "12345", 12345, "application/octet-stream", new Dictionary()); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, null, new Dictionary(), new List() { obj }); } @@ -804,7 +804,7 @@ namespace OpenStack.Test.Storage var obj = new StorageObject(objectName, containerName, DateTime.UtcNow, "12345", 12345, "application/octet-stream", new Dictionary()); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, string.Empty, new Dictionary(), new List() { obj }); } @@ -815,7 +815,7 @@ namespace OpenStack.Test.Storage var containerName = "TestContainer"; var objectName = "TestObject"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, objectName, new Dictionary(), (List)null); } @@ -829,7 +829,7 @@ namespace OpenStack.Test.Storage var obj = new StorageObject(objectName, containerName, DateTime.UtcNow, "12345", 12345, "application/octet-stream", new Dictionary()); - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageManifest(containerName, objectName, null, new List() { obj }); } @@ -850,7 +850,7 @@ namespace OpenStack.Test.Storage }); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageFolder(containerName, folderName); } @@ -871,7 +871,7 @@ namespace OpenStack.Test.Storage }); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageFolder(containerName, folderName); } @@ -882,7 +882,7 @@ namespace OpenStack.Test.Storage var containerName = "someContainer"; var folderName = "Test//Folder"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageFolder(containerName, folderName); } @@ -892,7 +892,7 @@ namespace OpenStack.Test.Storage { var folderName = "TestFolder"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageFolder(null, folderName); } @@ -902,7 +902,7 @@ namespace OpenStack.Test.Storage { var folderName = "TestFolder"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageFolder(string.Empty, folderName); } @@ -912,7 +912,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageFolder(containerName, null); } @@ -922,7 +922,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageFolder(containerName, string.Empty); } @@ -939,7 +939,7 @@ namespace OpenStack.Test.Storage return await Task.Run(()=>obj); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageContainer(containerName, new Dictionary()); } @@ -947,7 +947,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task CreatingStorageContainersWithNullContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageContainer(null, new Dictionary()); } @@ -955,7 +955,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentException))] public async Task CreatingStorageContainersWithEmptyContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageContainer(string.Empty, new Dictionary()); } @@ -963,7 +963,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task CreatingStorageContainersWithNullMetadataThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.CreateStorageContainer("TestContainer", null); } @@ -980,7 +980,7 @@ namespace OpenStack.Test.Storage return Task.Factory.StartNew(() => obj); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var resp = await client.GetStorageContainer(containerName); Assert.AreEqual(obj, resp); @@ -990,7 +990,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task GettingStorageContainersWithNullContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageContainer(null); } @@ -998,7 +998,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof (ArgumentException))] public async Task GettingStorageContainersWithEmptyContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.GetStorageContainer(string.Empty); } @@ -1014,7 +1014,7 @@ namespace OpenStack.Test.Storage await Task.Run(() => Assert.AreEqual(s.Name, obj.Name)); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.UpdateStorageContainer(obj); } @@ -1022,7 +1022,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task UpdatingStorageContainersWithNullContainerThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.UpdateStorageContainer(null); } @@ -1038,7 +1038,7 @@ namespace OpenStack.Test.Storage await Task.Run(()=>Assert.AreEqual(s, obj.Name)); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageContainer(obj.Name); } @@ -1046,7 +1046,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task DeletingStorageContainersWithNullContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageContainer(null); } @@ -1054,7 +1054,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentException))] public async Task DeletingStorageContainersWithEmptyContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageContainer(string.Empty); } @@ -1076,7 +1076,7 @@ namespace OpenStack.Test.Storage }); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageObject(obj.ContainerName,obj.Name); } @@ -1084,7 +1084,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task DeletingStorageObjectWithNullContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageObject(null,"TestObject"); } @@ -1092,7 +1092,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentException))] public async Task DeletingStorageObjectsWithEmptyContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageObject(string.Empty, "TestObject"); } @@ -1100,7 +1100,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task DeletingStorageObjectWithNullObjectNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageObject("TestContainer", null); } @@ -1108,7 +1108,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentException))] public async Task DeletingStorageObjectsWithEmptyObjectNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageObject("TestContainer", string.Empty); } @@ -1127,7 +1127,7 @@ namespace OpenStack.Test.Storage }); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageFolder(containerName, folderName); } @@ -1146,7 +1146,7 @@ namespace OpenStack.Test.Storage }); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageFolder(containerName, folderName); } @@ -1154,7 +1154,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task DeletingStorageFolderWithNullContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageFolder(null, "TestFolder"); } @@ -1162,7 +1162,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentException))] public async Task DeletingStorageFolderWithEmptyContainerNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageFolder(string.Empty, "TestFolder"); } @@ -1170,7 +1170,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task DeletingStorageFolderWithNullObjectNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageFolder("TestContainer", null); } @@ -1178,7 +1178,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentException))] public async Task DeletingStorageFolderWithEmptyObjectNameThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DeleteStorageFolder("TestContainer", string.Empty); } @@ -1200,7 +1200,7 @@ namespace OpenStack.Test.Storage }); }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.UpdateStorageObject(obj); } @@ -1208,7 +1208,7 @@ namespace OpenStack.Test.Storage [ExpectedException(typeof(ArgumentNullException))] public async Task UpdatingStorageObjectWithNullContainerThrows() { - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.UpdateStorageObject(null); } @@ -1234,7 +1234,7 @@ namespace OpenStack.Test.Storage return obj; }; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); var resp = await client.DownloadStorageObject(containerName, objectName, respStream); respStream.Position = 0; @@ -1248,7 +1248,7 @@ namespace OpenStack.Test.Storage { var objectName = "TestObject"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DownloadStorageObject(null, objectName, new MemoryStream()); } @@ -1258,7 +1258,7 @@ namespace OpenStack.Test.Storage { var objectName = "TestObject"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DownloadStorageObject(string.Empty, objectName, new MemoryStream()); } @@ -1268,7 +1268,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DownloadStorageObject(containerName, null, new MemoryStream() ); } @@ -1278,7 +1278,7 @@ namespace OpenStack.Test.Storage { var containerName = "TestContainer"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DownloadStorageObject(containerName, string.Empty, new MemoryStream()); } @@ -1289,7 +1289,7 @@ namespace OpenStack.Test.Storage var containerName = "TestContainer"; var objectName = "TestObject"; - var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator); + var client = new StorageServiceClient(GetValidCreds(), "Swift", CancellationToken.None, this.ServiceLocator); await client.DownloadStorageObject(containerName, objectName, null); } } diff --git a/OpenStack/OpenStack/IOpenStackClient.cs b/OpenStack/OpenStack/IOpenStackClient.cs index ba61104..ddad5e8 100644 --- a/OpenStack/OpenStack/IOpenStackClient.cs +++ b/OpenStack/OpenStack/IOpenStackClient.cs @@ -58,6 +58,23 @@ namespace OpenStack /// An implementation of the requested client. T CreateServiceClient(string version) where T : IOpenStackServiceClient; + /// + /// Creates a client for a given OpenStack service. + /// + /// The type of client to create. + /// The name of the service that must be supported. + /// An implementation of the requested client. + T CreateServiceClientByName(string serviceName) where T : IOpenStackServiceClient; + + /// + /// Creates a client for a given OpenStack service that supports the given version. + /// + /// The type of client to create. + /// The name of the service that must be supported. + /// The version that must be supported. + /// An implementation of the requested client. + T CreateServiceClientByName(string serviceName, string version) where T : IOpenStackServiceClient; + /// /// Gets a list of supported OpenStack versions for this client. /// diff --git a/OpenStack/OpenStack/IOpenStackServiceClientDefinition.cs b/OpenStack/OpenStack/IOpenStackServiceClientDefinition.cs index b2a32a0..14a6752 100644 --- a/OpenStack/OpenStack/IOpenStackServiceClientDefinition.cs +++ b/OpenStack/OpenStack/IOpenStackServiceClientDefinition.cs @@ -32,10 +32,11 @@ namespace OpenStack /// Creates an instance of the service client being defined. /// /// The credential that the client will use. + /// The name of the service that the client will use. /// The cancellation token that the client will use. /// A service locator to be used to locate/inject dependent services. /// - IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator); + IOpenStackServiceClient Create(ICredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator); /// /// Gets a list of supported versions. @@ -47,7 +48,8 @@ namespace OpenStack /// Determines if this client is currently supported. /// /// The credential for the service to use. + /// The serviceName for the service. /// A value indicating if the client is supported. - bool IsSupported(ICredential credential); + bool IsSupported(ICredential credential, string serviceName); } } diff --git a/OpenStack/OpenStack/IOpenStackServiceClientManager.cs b/OpenStack/OpenStack/IOpenStackServiceClientManager.cs index 9a645e7..35e43fe 100644 --- a/OpenStack/OpenStack/IOpenStackServiceClientManager.cs +++ b/OpenStack/OpenStack/IOpenStackServiceClientManager.cs @@ -26,6 +26,16 @@ namespace OpenStack /// public interface IOpenStackServiceClientManager { + /// + /// Create a client that can interact with the requested OpenStack service. + /// + /// The type of client to be created. + /// The credential to be used by the client. + /// The name of the service to be used by the client. + /// The cancellation token to be used by the client. + /// An instance of the requested client. + T CreateServiceClient(ICredential credential, string serviceName, CancellationToken cancellationToken) where T : IOpenStackServiceClient; + /// /// Create a client that can interact with the requested OpenStack service. /// diff --git a/OpenStack/OpenStack/Identity/IIdentityServicePocoClientFactory.cs b/OpenStack/OpenStack/Identity/IIdentityServicePocoClientFactory.cs index 663f031..dfe4074 100644 --- a/OpenStack/OpenStack/Identity/IIdentityServicePocoClientFactory.cs +++ b/OpenStack/OpenStack/Identity/IIdentityServicePocoClientFactory.cs @@ -28,9 +28,10 @@ namespace OpenStack.Identity /// Creates a client that can be used to interact with the remote OpenStack service. /// /// The credential to be used when interacting with OpenStack. + /// The name of the service to be used when interacting with OpenStack. /// The cancellation token to be used when interacting with OpenStack. /// A service locator to be used to locate/inject dependent services. /// An instance of the client. - IIdentityServicePocoClient Create(IOpenStackCredential credentials, CancellationToken token, IServiceLocator serviceLocator); + IIdentityServicePocoClient Create(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator); } } diff --git a/OpenStack/OpenStack/Identity/IdentityServiceClient.cs b/OpenStack/OpenStack/Identity/IdentityServiceClient.cs index e82966b..fef1a83 100644 --- a/OpenStack/OpenStack/Identity/IdentityServiceClient.cs +++ b/OpenStack/OpenStack/Identity/IdentityServiceClient.cs @@ -27,25 +27,29 @@ namespace OpenStack.Identity internal IOpenStackCredential Credential; internal CancellationToken CancellationToken; internal IServiceLocator ServiceLocator; + internal string ServiceName; /// /// Creates a new instance of the IdentityServiceClient class. /// /// The credential to be used by the client. + /// The name of the service to be used by the client. /// A cancellation token to be used when completing requests. /// A service locator to be used to locate/inject dependent services. - internal IdentityServiceClient(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator) + internal IdentityServiceClient(IOpenStackCredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator) { serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an identity service client with a null service locator."); + this.ServiceLocator = serviceLocator; this.Credential = credential; this.CancellationToken = cancellationToken; + this.ServiceName = serviceName; } /// public async Task Authenticate() { - var client = this.ServiceLocator.Locate().Create(this.Credential, this.CancellationToken, this.ServiceLocator); + var client = this.ServiceLocator.Locate().Create(this.Credential, this.ServiceName, this.CancellationToken, this.ServiceLocator); this.Credential = await client.Authenticate(); return this.Credential; } diff --git a/OpenStack/OpenStack/Identity/IdentityServiceClientDefinition.cs b/OpenStack/OpenStack/Identity/IdentityServiceClientDefinition.cs index 1244299..37e8543 100644 --- a/OpenStack/OpenStack/Identity/IdentityServiceClientDefinition.cs +++ b/OpenStack/OpenStack/Identity/IdentityServiceClientDefinition.cs @@ -25,6 +25,8 @@ namespace OpenStack.Identity /// internal class IdentityServiceClientDefinition : IOpenStackServiceClientDefinition { + internal const string DefaultServiceName = "Keystone"; + /// public string Name { get; private set; } @@ -37,9 +39,10 @@ namespace OpenStack.Identity } /// - public IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator) + public IOpenStackServiceClient Create(ICredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator) { - return new IdentityServiceClient((IOpenStackCredential)credential, cancellationToken, serviceLocator); + var srvName = string.IsNullOrEmpty(serviceName) ? DefaultServiceName : serviceName; + return new IdentityServiceClient((IOpenStackCredential)credential, srvName, cancellationToken, serviceLocator); } /// @@ -49,13 +52,13 @@ namespace OpenStack.Identity } /// - public bool IsSupported(ICredential credential) + public bool IsSupported(ICredential credential, string serviceName) { if (credential != null && credential.AuthenticationEndpoint != null) { - //https://someidentityendpoint:35357/v2.0/tokens + //https://someidentityendpoint:35357/v2.0 var endpointSegs = credential.AuthenticationEndpoint.Segments; - if (endpointSegs.Count() == 3 && string.Equals(endpointSegs[1].Trim('/'), "v2.0", StringComparison.Ordinal)) + if (endpointSegs.Count() == 2 && string.Equals(endpointSegs[1].Trim('/'), "v2.0", StringComparison.Ordinal)) { return true; } diff --git a/OpenStack/OpenStack/Identity/IdentityServicePocoClient.cs b/OpenStack/OpenStack/Identity/IdentityServicePocoClient.cs index 0c5811d..fcafdd0 100644 --- a/OpenStack/OpenStack/Identity/IdentityServicePocoClient.cs +++ b/OpenStack/OpenStack/Identity/IdentityServicePocoClient.cs @@ -28,7 +28,7 @@ namespace OpenStack.Identity { internal IOpenStackCredential credential; internal CancellationToken cancellationToken; - internal const string IdentityServiceName = "Identity"; + internal string ServiceName; internal IServiceLocator ServiceLocator; /// @@ -37,15 +37,17 @@ namespace OpenStack.Identity /// The credential to be used when interacting with OpenStack. /// The cancellation token to be used when interacting with OpenStack. /// A service locator to be used to locate/inject dependent services. - public IdentityServicePocoClient(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator) + public IdentityServicePocoClient(IOpenStackCredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator) { credential.AssertIsNotNull("credential"); cancellationToken.AssertIsNotNull("cancellationToken"); serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an identity service poco client with a null service locator."); + serviceName.AssertIsNotNullOrEmpty("serviceName", "Cannot create an identity service poco client with a null or empty service name."); this.credential = credential; this.cancellationToken = cancellationToken; this.ServiceLocator = serviceLocator; + this.ServiceName = serviceName; } /// @@ -74,7 +76,7 @@ namespace OpenStack.Identity if (string.IsNullOrEmpty(this.credential.Region)) { var resolver = this.ServiceLocator.Locate(); - var region = resolver.Resolve(this.credential.AuthenticationEndpoint, this.credential.ServiceCatalog, IdentityServiceName); + var region = resolver.Resolve(this.credential.AuthenticationEndpoint, this.credential.ServiceCatalog, this.ServiceName); //TODO: figure out if we want to throw in the case where the region cannot be resolved... this.credential.SetRegion(region); diff --git a/OpenStack/OpenStack/Identity/IdentityServicePocoClientFactory.cs b/OpenStack/OpenStack/Identity/IdentityServicePocoClientFactory.cs index c4f8c5c..8bf6f7a 100644 --- a/OpenStack/OpenStack/Identity/IdentityServicePocoClientFactory.cs +++ b/OpenStack/OpenStack/Identity/IdentityServicePocoClientFactory.cs @@ -23,9 +23,9 @@ namespace OpenStack.Identity internal class IdentityServicePocoClientFactory :IIdentityServicePocoClientFactory { /// - public IIdentityServicePocoClient Create(IOpenStackCredential credentials, CancellationToken token, IServiceLocator serviceLocator) + public IIdentityServicePocoClient Create(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator) { - return new IdentityServicePocoClient(credentials, token, serviceLocator); + return new IdentityServicePocoClient(credentials, serviceName, token, serviceLocator); } } } diff --git a/OpenStack/OpenStack/Identity/IdentityServiceRestClient.cs b/OpenStack/OpenStack/Identity/IdentityServiceRestClient.cs index 670ed43..ebfe998 100644 --- a/OpenStack/OpenStack/Identity/IdentityServiceRestClient.cs +++ b/OpenStack/OpenStack/Identity/IdentityServiceRestClient.cs @@ -14,6 +14,7 @@ // limitations under the License. // ============================================================================ */ +using System; using System.Net.Http; using System.Text; using System.Threading; @@ -55,7 +56,7 @@ namespace OpenStack.Identity client.Headers.Add("Accept", "application/json"); client.ContentType = "application/json"; - client.Uri = this.Credential.AuthenticationEndpoint; + client.Uri = new Uri(string.Format("{0}/tokens", this.Credential.AuthenticationEndpoint)); client.Method = HttpMethod.Post; client.Content = CreateAuthenticationJsonPayload(this.Credential).ConvertToStream(); diff --git a/OpenStack/OpenStack/Identity/OpenStackRegionResolver.cs b/OpenStack/OpenStack/Identity/OpenStackRegionResolver.cs index cf532ce..73059fa 100644 --- a/OpenStack/OpenStack/Identity/OpenStackRegionResolver.cs +++ b/OpenStack/OpenStack/Identity/OpenStackRegionResolver.cs @@ -30,19 +30,27 @@ namespace OpenStack.Identity serviceName.AssertIsNotNullOrEmpty("serviceName", "Cannot resolve a region with a null or empty service name."); var ret = string.Empty; + var cat = catalog.ToList(); - var identService = catalog.FirstOrDefault(s => string.Equals(s.Name, serviceName, StringComparison.OrdinalIgnoreCase)); + var identService = cat.FirstOrDefault(s => string.Equals(s.Name, serviceName, StringComparison.OrdinalIgnoreCase)); if (identService == null) { - return ret; + //Fall back and see if any service can be found that publishes an endpoint that matches the one given. + identService = cat.FirstOrDefault(s => s.Endpoints.Any(e => endpoint.AbsoluteUri.TrimEnd('/').Contains(e.PublicUri.TrimEnd('/')))); + if (identService == null) + { + //if no service can be found, either by name or endpoint, then return string.empty + return ret; + } } - var defaultRegionEndpoint = identService.Endpoints.FirstOrDefault(e => endpoint.AbsoluteUri.Contains(e.PublicUri)); + var defaultRegionEndpoint = identService.Endpoints.FirstOrDefault(e => endpoint.AbsoluteUri.TrimEnd('/').Contains(e.PublicUri.TrimEnd('/'))); if (defaultRegionEndpoint != null && !string.IsNullOrEmpty(defaultRegionEndpoint.Region)) { ret = defaultRegionEndpoint.Region; } + return ret; } } diff --git a/OpenStack/OpenStack/Identity/OpenStackServiceEndpoint.cs b/OpenStack/OpenStack/Identity/OpenStackServiceEndpoint.cs index 7472138..73c094f 100644 --- a/OpenStack/OpenStack/Identity/OpenStackServiceEndpoint.cs +++ b/OpenStack/OpenStack/Identity/OpenStackServiceEndpoint.cs @@ -60,15 +60,12 @@ namespace OpenStack.Identity { publicUri.AssertIsNotNull("publicUri", "Cannot create a service endpoint with a null public URI."); region.AssertIsNotNull("region", "Cannot create a service endpoint with a null public URI."); - version.AssertIsNotNull("version", "Cannot create a service endpoint with a null version."); - versionInfo.AssertIsNotNull("versionInfo", "Cannot create a service endpoint with a null version information URI."); - versionList.AssertIsNotNull("versionList", "Cannot create a service endpoint with a null version list URI."); this.PublicUri = publicUri; this.Region = region; - this.Version = version; - this.VersionInformation = versionInfo; - this.VersionList = versionList; + this.Version = version ?? string.Empty; + this.VersionInformation = versionInfo ?? string.Empty; + this.VersionList = versionList ?? string.Empty; } } } diff --git a/OpenStack/OpenStack/OpenStackClient.cs b/OpenStack/OpenStack/OpenStackClient.cs index 82d99b0..4580205 100644 --- a/OpenStack/OpenStack/OpenStackClient.cs +++ b/OpenStack/OpenStack/OpenStackClient.cs @@ -79,6 +79,19 @@ namespace OpenStack return manager.CreateServiceClient(this.Credential, this.CancellationToken); } + /// + public T CreateServiceClientByName(string serviceName) where T : IOpenStackServiceClient + { + return this.CreateServiceClientByName(serviceName, string.Empty); + } + + /// + public T CreateServiceClientByName(string serviceName, string version) where T : IOpenStackServiceClient + { + var manager = this.ServiceLocator.Locate(); + return manager.CreateServiceClient(this.Credential, serviceName, this.CancellationToken); + } + /// public IEnumerable GetSupportedVersions() { diff --git a/OpenStack/OpenStack/OpenStackServiceClientManager.cs b/OpenStack/OpenStack/OpenStackServiceClientManager.cs index 2e25b89..79b8edb 100644 --- a/OpenStack/OpenStack/OpenStackServiceClientManager.cs +++ b/OpenStack/OpenStack/OpenStackServiceClientManager.cs @@ -17,7 +17,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; using System.Threading; using OpenStack.Common; using OpenStack.Common.ServiceLocation; @@ -41,7 +40,14 @@ namespace OpenStack } /// - public T CreateServiceClient(ICredential credential, CancellationToken cancellationToken) where T : IOpenStackServiceClient + public T CreateServiceClient(ICredential credential, CancellationToken cancellationToken) + where T : IOpenStackServiceClient + { + return CreateServiceClient(credential, string.Empty, cancellationToken); + } + + /// + public T CreateServiceClient(ICredential credential, string serviceName, CancellationToken cancellationToken) where T : IOpenStackServiceClient { credential.AssertIsNotNull("credential", "Cannot create an OpenStack service with a null credential."); cancellationToken.AssertIsNotNull("cancellationToken", "Cannot create an OpenStack service with a null cancellationToken."); @@ -54,9 +60,9 @@ namespace OpenStack foreach (var serviceClientDef in this.serviceClientDefinitions.Where(s =>typeof(T).IsAssignableFrom(s.Key))) { - if (serviceClientDef.Value != null && serviceClientDef.Value.IsSupported(credential)) + if (serviceClientDef.Value != null && serviceClientDef.Value.IsSupported(credential, serviceName)) { - var client = this.CreateServiceClientInstance(serviceClientDef.Value, credential, cancellationToken); + var client = this.CreateServiceClientInstance(serviceClientDef.Value, credential, serviceName, cancellationToken); return (T) client; } } @@ -69,16 +75,17 @@ namespace OpenStack /// /// A object that can be used to validate and create the give client type. /// The credential to be used by the created client. + /// The name of the service to be used by the created client. /// The cancellation token to be used by the created client. /// An instance of the requested client. - internal IOpenStackServiceClient CreateServiceClientInstance(IOpenStackServiceClientDefinition clientDefinition, ICredential credential, CancellationToken cancellationToken) + internal IOpenStackServiceClient CreateServiceClientInstance(IOpenStackServiceClientDefinition clientDefinition, ICredential credential, string serviceName, CancellationToken cancellationToken) { clientDefinition.AssertIsNotNull("clientDefinition", "Cannot create an OpenStack service with a null client definition."); IOpenStackServiceClient instance; try { - instance = clientDefinition.Create(credential, cancellationToken, this.ServiceLocator) as IOpenStackServiceClient; + instance = clientDefinition.Create(credential, serviceName, cancellationToken, this.ServiceLocator) as IOpenStackServiceClient; } catch (Exception ex) { diff --git a/OpenStack/OpenStack/Storage/StorageServiceClient.cs b/OpenStack/OpenStack/Storage/StorageServiceClient.cs index 4196a8f..fa1457f 100644 --- a/OpenStack/OpenStack/Storage/StorageServiceClient.cs +++ b/OpenStack/OpenStack/Storage/StorageServiceClient.cs @@ -31,7 +31,6 @@ namespace OpenStack.Storage internal class StorageServiceClient : IStorageServiceClient { internal StorageServiceClientContext Context; - internal const string StorageServiceName = "Object Storage"; internal IServiceLocator ServiceLocator; /// @@ -49,7 +48,7 @@ namespace OpenStack.Storage /// The credential to be used by this client. /// The cancellation token to be used by this client. /// A service locator to be used to locate/inject dependent services. - public StorageServiceClient(IOpenStackCredential credentials, CancellationToken token, IServiceLocator serviceLocator) + public StorageServiceClient(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator) { serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a storage service client with a null service locator."); @@ -58,8 +57,8 @@ namespace OpenStack.Storage this.LargeObjectSegmentContainer = "LargeObjectSegments"; //set the default name of the container that will hold segments to 'LargeObjectSegments'; this.ServiceLocator = serviceLocator; - var endpoint = new Uri(credentials.ServiceCatalog.GetPublicEndpoint(StorageServiceName, credentials.Region)); - this.Context = new StorageServiceClientContext(credentials, token, StorageServiceName, endpoint); + var endpoint = new Uri(credentials.ServiceCatalog.GetPublicEndpoint(serviceName, credentials.Region)); + this.Context = new StorageServiceClientContext(credentials, token, serviceName, endpoint); } /// diff --git a/OpenStack/OpenStack/Storage/StorageServiceClientDefinition.cs b/OpenStack/OpenStack/Storage/StorageServiceClientDefinition.cs index 2d8e4db..d3a010c 100644 --- a/OpenStack/OpenStack/Storage/StorageServiceClientDefinition.cs +++ b/OpenStack/OpenStack/Storage/StorageServiceClientDefinition.cs @@ -26,6 +26,8 @@ namespace OpenStack.Storage /// internal class StorageServiceClientDefinition : IOpenStackServiceClientDefinition { + internal const string DefaultStorageServiceName = "Swift"; + /// public string Name { get; private set; } @@ -38,9 +40,9 @@ namespace OpenStack.Storage } /// - public IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator) + public IOpenStackServiceClient Create(ICredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator) { - return new StorageServiceClient((IOpenStackCredential)credential, cancellationToken, serviceLocator); + return new StorageServiceClient((IOpenStackCredential)credential, GetServiceName(serviceName), cancellationToken, serviceLocator); } /// @@ -50,18 +52,29 @@ namespace OpenStack.Storage } /// - public bool IsSupported(ICredential credential) + public bool IsSupported(ICredential credential, string serviceName) { - if (credential != null && credential.ServiceCatalog != null) + if (credential == null || credential.ServiceCatalog == null) { - var catalog = credential.ServiceCatalog; - return - catalog.Any( - s => - string.Equals(s.Name, StorageServiceClient.StorageServiceName, StringComparison.OrdinalIgnoreCase) && - s.Endpoints.Any(e => this.ListSupportedVersions().Contains(e.Version))); + return false; } - return false; + + var catalog = credential.ServiceCatalog; + return + catalog.Any( + s => + string.Equals(s.Name, GetServiceName(serviceName), StringComparison.OrdinalIgnoreCase) && + s.Endpoints.Any(e => this.ListSupportedVersions().Contains(e.Version) || e.PublicUri.Contains("/v1"))); + } + + /// + /// Gets the service name to use. + /// + /// The given service name. + /// The given service name if it is not empty or null, otherwise the default service name will be returned. + internal string GetServiceName(string serviceName) + { + return string.IsNullOrEmpty(serviceName) ? DefaultStorageServiceName : serviceName; } } }