Skip to content

Commit bd271ec

Browse files
committed
Merge pull request #2 from kravi/SwiftSupport
Added support for ObjectStorage, starting with one method, List Containers, added integration tests.
2 parents 6a7f9f9 + 7ff4d22 commit bd271ec

8 files changed

Lines changed: 223 additions & 4 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Runtime.Serialization;
5+
using System.Text;
6+
7+
namespace net.openstack.Core.Domain
8+
{
9+
[DataContract]
10+
public class Container
11+
{
12+
[DataMember]
13+
public string Name { get; set; }
14+
15+
[DataMember]
16+
public int Count { get; set; }
17+
18+
[DataMember]
19+
public long Bytes { get; set; }
20+
}
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using net.openstack.Core.Domain;
6+
7+
namespace net.openstack.Core
8+
{
9+
public interface IObjectStoreProvider
10+
{
11+
#region Container
12+
13+
IEnumerable<Container> ListContainers(CloudIdentity identity, int? limit = null, string markerId = null, string markerEnd = null, string format = "json", string region = null);
14+
15+
#endregion
16+
}
17+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using SimpleRestServices.Client;
5+
using SimpleRestServices.Client.Json;
6+
using net.openstack.Core;
7+
using net.openstack.Core.Domain;
8+
using net.openstack.Providers.Rackspace.Objects.Request;
9+
using net.openstack.Providers.Rackspace.Objects.Response;
10+
11+
namespace net.openstack.Providers.Rackspace
12+
{
13+
public class ObjectStoreProvider : ProviderBase, IObjectStoreProvider
14+
{
15+
#region Constructors
16+
17+
public ObjectStoreProvider()
18+
: this(new IdentityProvider(), new JsonRestServices()) { }
19+
20+
public ObjectStoreProvider(IIdentityProvider identityProvider, IRestService restService)
21+
: base(identityProvider, restService) { }
22+
23+
#endregion
24+
25+
#region Containers
26+
27+
public IEnumerable<Container> ListContainers(CloudIdentity identity, int? limit = null, string marker = null, string markerEnd = null, string format = "json", string region = null)
28+
{
29+
var urlPath = new Uri(string.Format("{0}", GetServiceEndpoint(identity, region)));
30+
31+
var queryStringParameter = new Dictionary<string, string>();
32+
queryStringParameter.Add("format", format);
33+
34+
if (limit != null)
35+
queryStringParameter.Add("limit", limit.ToString());
36+
37+
if (!string.IsNullOrWhiteSpace(marker))
38+
queryStringParameter.Add("marker", marker);
39+
40+
if (!string.IsNullOrWhiteSpace(markerEnd))
41+
queryStringParameter.Add("end_marker", markerEnd);
42+
43+
var response = ExecuteRESTRequest<Container []>(identity, urlPath, HttpMethod.GET, null, queryStringParameter);
44+
45+
if (response == null || response.Data == null)
46+
return null;
47+
48+
return response.Data;
49+
50+
}
51+
52+
#endregion
53+
54+
#region Private methods
55+
56+
protected string GetServiceEndpoint(CloudIdentity identity, string region = null)
57+
{
58+
return base.GetServiceEndpoint(identity, "cloudFiles", region);
59+
}
60+
61+
#endregion
62+
}
63+
}

src/corelib/Providers/Rackspace/ProviderBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ protected ProviderBase(IIdentityProvider identityProvider, IRestService restServ
2323
_restService = restService;
2424
}
2525

26-
protected Response<T> ExecuteRESTRequest<T>(CloudIdentity identity, Uri absoluteUri, HttpMethod method, object body = null, Dictionary<string, string> queryStringParameter = null, Dictionary<string, string> headers = null, bool isRetry = false, JsonRequestSettings requestSettings = null)
26+
protected Response<T> ExecuteRESTRequest<T>(CloudIdentity identity, Uri absoluteUri, HttpMethod method, object body = null, Dictionary<string, string> queryStringParameter = null, Dictionary<string, string> headers = null, bool isRetry = false, JsonRequestSettings requestSettings = null)
2727
{
2828
if (requestSettings == null)
2929
requestSettings = BuildDefaultRequestSettings();

src/corelib/corelib.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
<ItemGroup>
5050
<Compile Include="Core\Domain\Address.cs" />
5151
<Compile Include="Core\Domain\CloudIdentity.cs" />
52+
<Compile Include="Core\Domain\Container.cs" />
5253
<Compile Include="Core\Domain\Flavor.cs" />
5354
<Compile Include="Core\Domain\FlavorDetails.cs" />
5455
<Compile Include="Core\Domain\ImageType.cs" />
@@ -68,6 +69,9 @@
6869
<Compile Include="Core\Exceptions\Response\ServiceLimitReachedException.cs" />
6970
<Compile Include="Core\Exceptions\Response\ServiceUnavailableException.cs" />
7071
<Compile Include="Core\Exceptions\Response\UserNotAuthorizedException.cs" />
72+
<Compile Include="Core\IObjectStoreProvider.cs" />
73+
<Compile Include="Providers\Rackspace\ObjectStoreProvider.cs" />
74+
7175
<Compile Include="Providers\Rackspace\ComputeProvider.cs" />
7276
<Compile Include="Core\Exceptions\InvalidCloudIdentityException.cs" />
7377
<Compile Include="Providers\Rackspace\Objects\Request\AddRoleRequest.cs" />

src/testing/integration/App.config

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<configuration>
33
<appSettings>
4-
<add key="TestIdentityUserName" value="cloud2"/>
4+
<add key="TestIdentityUserName" value=""/>
55
<add key="TestIdentityAPIKey" value=""/>
6-
<add key="TestIdentityPassword" value="Hybr1d99"/>
7-
<add key="TestIdentityGeo" value="DFW"/>
6+
<add key="TestIdentityPassword" value=""/>
7+
<add key="TestIdentityGeo" value=""/>
88
</appSettings>
99
</configuration>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
using System;
2+
using System.Configuration;
3+
using System.Text;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using Microsoft.VisualStudio.TestTools.UnitTesting;
7+
using net.openstack.Core.Domain;
8+
using net.openstack.Providers.Rackspace;
9+
10+
namespace Net.OpenStack.Testing.Integration.Providers.Rackspace
11+
{
12+
[TestClass]
13+
public class ObjectStoreTests
14+
{
15+
16+
public ObjectStoreTests()
17+
{
18+
CloudInstance cloudInstance;
19+
CloudInstance.TryParse(ConfigurationManager.AppSettings["TestIdentityGeo"], true, out cloudInstance);
20+
21+
_testIdentity = new RackspaceCloudIdentity
22+
{
23+
APIKey = ConfigurationManager.AppSettings["TestIdentityAPIKey"],
24+
Password = ConfigurationManager.AppSettings["TestIdentityPassword"],
25+
CloudInstance = cloudInstance,
26+
Username = ConfigurationManager.AppSettings["TestIdentityUserName"],
27+
};
28+
}
29+
30+
private TestContext testContextInstance;
31+
private static CloudIdentity _testIdentity;
32+
33+
/// <summary>
34+
///Gets or sets the test context which provides
35+
///information about and functionality for the current test run.
36+
///</summary>
37+
public TestContext TestContext
38+
{
39+
get
40+
{
41+
return testContextInstance;
42+
}
43+
set
44+
{
45+
testContextInstance = value;
46+
}
47+
}
48+
49+
50+
[TestMethod]
51+
public void Should_Return_Container_List()
52+
{
53+
var provider = new ObjectStoreProvider();
54+
var containerList = provider.ListContainers(_testIdentity);
55+
56+
Assert.IsNotNull(containerList);
57+
Assert.IsTrue(containerList.Any());
58+
}
59+
60+
[TestMethod]
61+
public void Should_Return_Container_List_With_Limit()
62+
{
63+
var provider = new ObjectStoreProvider();
64+
var containerList = provider.ListContainers(_testIdentity,1);
65+
66+
Assert.IsNotNull(containerList);
67+
Assert.AreEqual(1, containerList.Count());
68+
}
69+
70+
[TestMethod]
71+
public void Should_Return_Container_List_With_Start_Marker_Lower_Case()
72+
{
73+
var provider = new ObjectStoreProvider();
74+
var containerList = provider.ListContainers(_testIdentity, null,"a");
75+
76+
Assert.IsNotNull(containerList);
77+
Assert.IsTrue(containerList.Any());
78+
}
79+
80+
[TestMethod]
81+
public void Should_Return_Container_List_With_Start_Marker_Upper_Case()
82+
{
83+
var provider = new ObjectStoreProvider();
84+
var containerList = provider.ListContainers(_testIdentity, null, "A");
85+
86+
Assert.IsNotNull(containerList);
87+
Assert.IsTrue(containerList.Any());
88+
}
89+
90+
91+
[TestMethod]
92+
public void Should_Return_Container_List_With_End_Marker_Upper_Case()
93+
{
94+
var provider = new ObjectStoreProvider();
95+
var containerList = provider.ListContainers(_testIdentity, null, null,"L");
96+
97+
Assert.IsNotNull(containerList);
98+
Assert.IsTrue(containerList.Any());
99+
}
100+
101+
[TestMethod]
102+
public void Should_Return_Container_List_With_End_Marker_Lower_Case()
103+
{
104+
var provider = new ObjectStoreProvider();
105+
var containerList = provider.ListContainers(_testIdentity, null, null, "l");
106+
107+
Assert.IsNotNull(containerList);
108+
Assert.IsTrue(containerList.Any());
109+
}
110+
111+
112+
}
113+
}

src/testing/integration/integration.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
<Compile Include="Properties\AssemblyInfo.cs" />
5656
<Compile Include="Providers\Rackspace\ComputeTests.cs" />
5757
<Compile Include="Providers\Rackspace\IdentityTests.cs" />
58+
<Compile Include="Providers\Rackspace\ObjectStoreTests.cs" />
5859
</ItemGroup>
5960
<ItemGroup>
6061
<ProjectReference Include="..\..\corelib\corelib.csproj">

0 commit comments

Comments
 (0)