Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/corelib/Core/IObjectStoreProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public interface IObjectStoreProvider
void AddContainerHeaders(CloudIdentity identity, string container, Dictionary<string, string> headers, string region = null, bool useInternalUrl = false);
void AddContainerCdnHeaders(CloudIdentity identity, string container, Dictionary<string, string> headers, string region = null, bool useInternalUrl = false);

void EnableStaticWebOnContainer(string container, string index, string error, string css, bool listing, string region = null, bool useInternalUrl = false, CloudIdentity identity = null);
void EnableStaticWebOnContainer(string container, string index, string error, bool listing, string region = null, bool useInternalUrl = false, CloudIdentity identity = null);
void EnableStaticWebOnContainer(string container, string css, bool listing, string region = null, bool useInternalUrl = false, CloudIdentity identity = null);
void EnableStaticWebOnContainer(string container, string index, string error, string region = null, bool useInternalUrl = false, CloudIdentity identity = null);
void DisableStaticWebOnContainer(string container, string region = null, bool useInternalUrl = false, CloudIdentity identity = null);
#endregion

#region Container Objects
Expand Down
141 changes: 124 additions & 17 deletions src/corelib/Providers/Rackspace/ObjectStoreProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ public ObjectStore DeleteContainer(CloudIdentity identity, string container, str

return ObjectStore.Unknown;
}

public Dictionary<string, string> GetContainerHeader(CloudIdentity identity, string container, string region = null, bool useInternalUrl = false)
{
_objectStoreHelper.ValidateContainerName(container);
var urlPath = new Uri(string.Format("{0}/{1}", GetServiceEndpointCloudFiles(identity, region), container));

var response = ExecuteRESTRequest(identity, urlPath, HttpMethod.HEAD);
var response = ExecuteRESTRequest(identity, urlPath, HttpMethod.HEAD);

var processedHeaders = _objectStoreHelper.ProcessMetadata(response.Headers);

Expand Down Expand Up @@ -178,15 +178,7 @@ public void AddContainerCdnHeaders(CloudIdentity identity, string container, Dic
throw new ArgumentNullException();
}

bool cdnEnabled = false;

var cdnHeaders = GetContainerCDNHeader(identity, container);
if (cdnHeaders.ContainsKey(ObjectStoreConstants.CdnEnabled))
{
cdnEnabled = bool.Parse(cdnHeaders.FirstOrDefault(x => x.Key.Equals(ObjectStoreConstants.CdnEnabled, StringComparison.InvariantCultureIgnoreCase)).Value);
}

if (!cdnEnabled)
if (!IsContainerCdnEnabled(identity, container, region, useInternalUrl))
{
throw new CDNNotEnabledException();
}
Expand All @@ -197,6 +189,22 @@ public void AddContainerCdnHeaders(CloudIdentity identity, string container, Dic
}
}

private bool IsContainerCdnEnabled(CloudIdentity identity, string container, string region, bool useInternalUrl)
{
bool cdnEnabled = false;

var cdnHeaders = GetContainerCDNHeader(identity, container, region, useInternalUrl);
if (cdnHeaders.ContainsKey(ObjectStoreConstants.CdnEnabled))
{
cdnEnabled =
bool.Parse(
cdnHeaders.FirstOrDefault(
x => x.Key.Equals(ObjectStoreConstants.CdnEnabled, StringComparison.InvariantCultureIgnoreCase)).
Value);
}
return cdnEnabled;
}

public IEnumerable<ContainerCDN> ListCDNContainers(CloudIdentity identity, int? limit = null, string marker = null, string markerEnd = null, bool cdnEnabled = false, string region = null)
{
var urlPath = new Uri(string.Format("{0}", GetServiceEndpointCloudFilesCDN(identity, region)));
Expand Down Expand Up @@ -264,7 +272,7 @@ public Dictionary<string, string> EnableCDNOnContainer(CloudIdentity identity, s
public Dictionary<string, string> DisableCDNOnContainer(CloudIdentity identity, string container, string region = null)
{
_objectStoreHelper.ValidateContainerName(container);


var headers = new Dictionary<string, string>
{
Expand All @@ -280,6 +288,105 @@ public Dictionary<string, string> DisableCDNOnContainer(CloudIdentity identity,
return response.Headers.ToDictionary(header => header.Key, header => header.Value);
}

public void EnableStaticWebOnContainer(string container, string index, string error, string css, bool listing, string region = null, bool useInternalUrl = false, CloudIdentity identity = null)
{
_objectStoreHelper.ValidateContainerName(container);

if (!IsContainerCdnEnabled(identity, container, region, useInternalUrl))
{
throw new CDNNotEnabledException();
}
else
{
var headers = new Dictionary<string, string>
{
{ObjectStoreConstants.WebIndex, index},
{ObjectStoreConstants.WebError, error},
{ObjectStoreConstants.WebListingsCSS, css},
{ObjectStoreConstants.WebListings, listing.ToString()}
};
AddContainerHeaders(identity, container, headers, region, useInternalUrl);
}
}

public void EnableStaticWebOnContainer(string container, string index, string error, bool listing, string region = null, bool useInternalUrl = false, CloudIdentity identity = null)
{
_objectStoreHelper.ValidateContainerName(container);

if (!IsContainerCdnEnabled(identity, container, region, useInternalUrl))
{
throw new CDNNotEnabledException();
}
else
{
var headers = new Dictionary<string, string>
{
{ObjectStoreConstants.WebIndex, index},
{ObjectStoreConstants.WebError, error},
{ObjectStoreConstants.WebListings, listing.ToString()}
};
AddContainerHeaders(identity, container, headers, region, useInternalUrl);
}
}

public void EnableStaticWebOnContainer(string container, string css, bool listing, string region = null, bool useInternalUrl = false, CloudIdentity identity = null)
{
_objectStoreHelper.ValidateContainerName(container);

if (!IsContainerCdnEnabled(identity, container, region, useInternalUrl))
{
throw new CDNNotEnabledException();
}
else
{
var headers = new Dictionary<string, string>
{
{ObjectStoreConstants.WebListingsCSS, css},
{ObjectStoreConstants.WebListings, listing.ToString()}
};
AddContainerHeaders(identity, container, headers, region, useInternalUrl);
}
}

public void EnableStaticWebOnContainer(string container, string index, string error, string region = null, bool useInternalUrl = false, CloudIdentity identity = null)
{
_objectStoreHelper.ValidateContainerName(container);

if (!IsContainerCdnEnabled(identity, container, region, useInternalUrl))
{
throw new CDNNotEnabledException();
}
else
{
var headers = new Dictionary<string, string>
{
{ObjectStoreConstants.WebIndex, index},
{ObjectStoreConstants.WebError, error}
};
AddContainerHeaders(identity, container, headers, region, useInternalUrl);
}
}

public void DisableStaticWebOnContainer(string container, string region = null, bool useInternalUrl = false, CloudIdentity identity = null)
{
_objectStoreHelper.ValidateContainerName(container);

if (!IsContainerCdnEnabled(identity, container, region, useInternalUrl))
{
throw new CDNNotEnabledException();
}
else
{
var headers = new Dictionary<string, string>
{
{ObjectStoreConstants.WebIndex, string.Empty},
{ObjectStoreConstants.WebError, string.Empty},
{ObjectStoreConstants.WebListingsCSS, string.Empty},
{ObjectStoreConstants.WebListings, string.Empty}
};
AddContainerHeaders(identity, container, headers, region, useInternalUrl);
}
}

#endregion

Expand Down Expand Up @@ -313,7 +420,7 @@ public IEnumerable<ContainerObject> GetObjects(CloudIdentity identity, string co
return response.Data;
}

public Dictionary<string,string> GetObjectHeaders(CloudIdentity identity, string container, string objectName, string format = "json", string region = null)
public Dictionary<string, string> GetObjectHeaders(CloudIdentity identity, string container, string objectName, string format = "json", string region = null)
{
_objectStoreHelper.ValidateContainerName(container);
_objectStoreHelper.ValidateObjectName(objectName);
Expand Down Expand Up @@ -404,7 +511,7 @@ public void GetObject(string container, string objectName, Stream outputStream,
var convertedMd5 = sbuilder.ToString();
if (convertedMd5 != response.Headers.First(h => h.Key.Equals(ObjectStoreConstants.Etag, StringComparison.OrdinalIgnoreCase)).Value.ToLower())
{

throw new InvalidETagException();
}
}
Expand Down Expand Up @@ -472,8 +579,8 @@ public ObjectStore CopyObject(CloudIdentity identity, string sourceContainer, st
headers.Add(ObjectStoreConstants.ContentLength, contentLength);

}
headers.Add(ObjectStoreConstants.CopyFrom,string.Format("{0}/{1}",sourceContainer,sourceObjectName));

headers.Add(ObjectStoreConstants.CopyFrom, string.Format("{0}/{1}", sourceContainer, sourceObjectName));

var urlPath = new Uri(string.Format("{0}/{1}/{2}", GetServiceEndpointCloudFiles(identity, region), destinationContainer, destinationObjectName));

Expand All @@ -493,7 +600,7 @@ public Dictionary<string, string> GetObjectMetaData(string container, string obj
_objectStoreHelper.ValidateObjectName(objectName);
var urlPath = new Uri(string.Format("{0}/{1}/{2}", GetServiceEndpointCloudFiles(identity, region), container, objectName));

var response = ExecuteRESTRequest(identity, urlPath, HttpMethod.HEAD);
var response = ExecuteRESTRequest(identity, urlPath, HttpMethod.HEAD);

var processedHeaders = _objectStoreHelper.ProcessMetadata(response.Headers);

Expand Down
98 changes: 98 additions & 0 deletions src/testing/integration/Providers/Rackspace/ObjectStoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,104 @@ public void Should_Make_Container_CDN_Disabled()
Assert.IsFalse(bool.Parse(cdnContainerHeaderResponse.Where(x => x.Key.Equals("X-Cdn-Enabled", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value));
}

[TestMethod]
public void Should_Enable_Static_Web_On_Container_With_Index_Error_CSS_And_Listing_As_True()
{
const string containerName = "DarkKnight";
const string webIndex = "index.html";
const string webError = "error.html";
const string webListingsCSS = "index.css";
const bool webListing = true;

var provider = new ObjectStoreProvider();
//var cdnEnabledResponse = provider.EnableCDNOnContainer(_testIdentity, containerName, true);

provider.EnableStaticWebOnContainer(containerName, webIndex, webError, webListingsCSS, webListing, null, false, _testIdentity);
var cdnContainerMetaDataResponse = provider.GetContainerMetaData(_testIdentity, containerName);

Assert.AreEqual(webIndex, cdnContainerMetaDataResponse.Where(x => x.Key.Equals("Web-index", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
Assert.AreEqual(webError, cdnContainerMetaDataResponse.Where(x => x.Key.Equals("web-error", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
Assert.AreEqual(webListingsCSS, cdnContainerMetaDataResponse.Where(x => x.Key.Equals("web-listings-css", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
Assert.IsTrue(bool.Parse(cdnContainerMetaDataResponse.Where(x => x.Key.Equals("web-listings", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value));

}

[TestMethod]
public void Should_Enable_Static_Web_On_Container_With_CSS_And_Listing_As_True()
{
const string containerName = "DarkKnight";
const string webListingsCSS = "index.css";
const bool webListing = true;

var provider = new ObjectStoreProvider();
//var cdnEnabledResponse = provider.EnableCDNOnContainer(_testIdentity, containerName, true);

provider.EnableStaticWebOnContainer(containerName, webListingsCSS, webListing, null, false, _testIdentity);
var cdnContainerMetaDataResponse = provider.GetContainerMetaData(_testIdentity, containerName);

Assert.AreEqual(webListingsCSS, cdnContainerMetaDataResponse.Where(x => x.Key.Equals("web-listings-css", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
Assert.IsTrue(bool.Parse(cdnContainerMetaDataResponse.Where(x => x.Key.Equals("web-listings", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value));

}

[TestMethod]
public void Should_Enable_Static_Web_On_Container_With_Index_Error_And_Listing_As_True()
{
const string containerName = "DarkKnight";
const string webIndex = "index.html";
const string webError = "error.html";
const bool webListing = true;

var provider = new ObjectStoreProvider();
//var cdnEnabledResponse = provider.EnableCDNOnContainer(_testIdentity, containerName, true);

provider.EnableStaticWebOnContainer(containerName, webIndex, webError, webListing, null, false, _testIdentity);
var cdnContainerMetaDataResponse = provider.GetContainerMetaData(_testIdentity, containerName);

Assert.AreEqual(webIndex, cdnContainerMetaDataResponse.Where(x => x.Key.Equals("Web-index", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
Assert.AreEqual(webError, cdnContainerMetaDataResponse.Where(x => x.Key.Equals("web-error", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
Assert.IsTrue(bool.Parse(cdnContainerMetaDataResponse.Where(x => x.Key.Equals("web-listings", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value));

}

[TestMethod]
public void Should_Enable_Static_Web_On_Container_With_Index_And_Error()
{
const string containerName = "DarkKnight";
const string webIndex = "index.html";
const string webError = "error.html";

var provider = new ObjectStoreProvider();
//var cdnEnabledResponse = provider.EnableCDNOnContainer(_testIdentity, containerName, true);

provider.EnableStaticWebOnContainer(containerName, webIndex, webError, null, false, _testIdentity);
var cdnContainerMetaDataResponse = provider.GetContainerMetaData(_testIdentity, containerName);

Assert.AreEqual(webIndex, cdnContainerMetaDataResponse.Where(x => x.Key.Equals("Web-index", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
Assert.AreEqual(webError, cdnContainerMetaDataResponse.Where(x => x.Key.Equals("web-error", StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault().Value);
}

[TestMethod]
public void Should_Disable_Static_Web_On_Container()
{
const string containerName = "DarkKnight";

var provider = new ObjectStoreProvider();
//var cdnEnabledResponse = provider.EnableCDNOnContainer(_testIdentity, containerName, true);

provider.DisableStaticWebOnContainer(containerName, null, false, _testIdentity);
var cdnContainerMetaDataResponse = provider.GetContainerMetaData(_testIdentity, containerName);


Assert.IsFalse(cdnContainerMetaDataResponse.ContainsKey("Web-Index"));
Assert.IsFalse(cdnContainerMetaDataResponse.ContainsKey("Web-Error"));
Assert.IsFalse(cdnContainerMetaDataResponse.ContainsKey("Web-Listings-Css"));
Assert.IsFalse(cdnContainerMetaDataResponse.ContainsKey("Web-Listings"));

}



#endregion Container Tests

#region Object Tests
Expand Down