Skip to content

Commit

Permalink
Added CDN SSL URI stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Weidenkeller committed Mar 9, 2011
1 parent 23c07df commit 8a2e881
Show file tree
Hide file tree
Showing 40 changed files with 759 additions and 584 deletions.
19 changes: 19 additions & 0 deletions cloudfiles/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(self, connection=None, name=None, count=None, size=None):
self.object_count = count
self.size_used = size
self.cdn_uri = None
self.cdn_ssl_uri = None
self.cdn_ttl = None
self.cdn_log_retention = None
if connection.cdn_enabled:
Expand All @@ -87,6 +88,8 @@ def _fetch_cdn_data(self):
self.cdn_uri = hdr[1]
if hdr[0].lower() == 'x-ttl':
self.cdn_ttl = int(hdr[1])
if hdr[0].lower() == 'x-cdn-ssl-uri':
self.cdn_ssl_uri = hdr[1]
if hdr[0].lower() == 'x-log-retention':
self.cdn_log_retention = hdr[1] == "True" and True or False

Expand Down Expand Up @@ -223,6 +226,22 @@ def public_uri(self):
raise ContainerNotPublic()
return self.cdn_uri

@requires_name(InvalidContainerName)
def public_ssl_uri(self):
"""
Return the SSL URI for this container, if it is publically
accessible via the CDN.
>>> connection['container1'].public_ssl_uri()
'https://c00061.cdn.cloudfiles.rackspacecloud.com'
@rtype: str
@return: the public SSL URI for this container
"""
if not self.is_public():
raise ContainerNotPublic()
return self.cdn_ssl_uri

@requires_name(InvalidContainerName)
def create_object(self, object_name):
"""
Expand Down
25 changes: 21 additions & 4 deletions cloudfiles/storage_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@ def _make_headers(self):
headers['Content-Type'] = self.content_type
else:
headers['Content-Type'] = 'application/octet-stream'

for key in self.metadata:
if len(key) > consts.meta_name_limit:
raise(InvalidMetaName(key))
Expand Down Expand Up @@ -604,6 +603,22 @@ def public_uri(self):
"""
return "%s/%s" % (self.container.public_uri().rstrip('/'),
quote(self.name))

def public_ssl_uri(self):
"""
Retrieve the SSL URI for this object, if its container is public.
>>> container1 = connection['container1']
>>> container1.make_public()
>>> container1.create_object('file.txt').write('testing')
>>> container1['file.txt'].public_ssl_uri()
'https://c00061.cdn.cloudfiles.rackspacecloud.com/file.txt'
@return: the public SSL URI for this object
@rtype: str
"""
return "%s/%s" % (self.container.public_ssl_uri().rstrip('/'),
quote(self.name))

def purge_from_cdn(self, email=None):
"""
Expand All @@ -629,11 +644,13 @@ def purge_from_cdn(self, email=None):

if email:
hdrs = {"X-Purge-Email": email}
response = self.container.conn.cdn_request('DELETE', [self.container.name, self.name], hdrs=hdrs)
response = self.container.conn.cdn_request('DELETE',
[self.container.name, self.name], hdrs=hdrs)
else:
response = self.container.conn.cdn_request('DELETE', [self.container.name, self.name])
response = self.container.conn.cdn_request('DELETE',
[self.container.name, self.name])

if (response.status < 200) or (response.status >= 300):
if (response.status < 200) or (response.status >= 299):
raise ResponseError(response.status, response.reason)


Expand Down
2 changes: 2 additions & 0 deletions docs/api-objects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ cloudfiles.container.Container.__init__ cloudfiles.container.Container-class.htm
cloudfiles.container.Container.size_used cloudfiles.container.Container-class.html#size_used
cloudfiles.container.Container.object_count cloudfiles.container.Container-class.html#object_count
cloudfiles.container.Container.cdn_ttl cloudfiles.container.Container-class.html#cdn_ttl
cloudfiles.container.Container.public_ssl_uri cloudfiles.container.Container-class.html#public_ssl_uri
cloudfiles.container.Container.__getitem__ cloudfiles.container.Container-class.html#__getitem__
cloudfiles.container.Container.create_object cloudfiles.container.Container-class.html#create_object
cloudfiles.container.Container.cdn_log_retention cloudfiles.container.Container-class.html#cdn_log_retention
Expand Down Expand Up @@ -98,6 +99,7 @@ cloudfiles.storage_object.Object.etag cloudfiles.storage_object.Object-class.htm
cloudfiles.storage_object.Object.objsum cloudfiles.storage_object.Object-class.html#objsum
cloudfiles.storage_object.Object.copy_to cloudfiles.storage_object.Object-class.html#copy_to
cloudfiles.storage_object.Object.metadata cloudfiles.storage_object.Object-class.html#metadata
cloudfiles.storage_object.Object.public_ssl_uri cloudfiles.storage_object.Object-class.html#public_ssl_uri
cloudfiles.storage_object.Object.read cloudfiles.storage_object.Object-class.html#read
cloudfiles.storage_object.Object.public_uri cloudfiles.storage_object.Object-class.html#public_uri
cloudfiles.storage_object.Object.last_modified cloudfiles.storage_object.Object-class.html#last_modified
Expand Down
2 changes: 1 addition & 1 deletion docs/class-tree.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ <h1 class="epydoc">Class Hierarchy</h1>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Tue Mar 1 15:49:52 2011
Generated by Epydoc 3.0.1 on Wed Mar 9 11:09:13 2011
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
Expand Down
2 changes: 1 addition & 1 deletion docs/cloudfiles-module.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ <h3 class="epydoc"><span class="sig"><span class="sig-name">get_connection</span
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Tue Mar 1 15:49:52 2011
Generated by Epydoc 3.0.1 on Wed Mar 9 11:09:13 2011
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
Expand Down
2 changes: 1 addition & 1 deletion docs/cloudfiles-pysrc.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ <h1 class="epydoc">Source Code for <a href="cloudfiles-module.html">Package clou
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Tue Mar 1 15:49:53 2011
Generated by Epydoc 3.0.1 on Wed Mar 9 11:09:14 2011
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
Expand Down
2 changes: 1 addition & 1 deletion docs/cloudfiles.connection-module.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ <h1 class="epydoc">Module connection</h1><p class="nomargin-top"><span class="co
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Tue Mar 1 15:49:52 2011
Generated by Epydoc 3.0.1 on Wed Mar 9 11:09:13 2011
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
Expand Down
8 changes: 4 additions & 4 deletions docs/cloudfiles.connection-pysrc.html
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ <h1 class="epydoc">Source Code for <a href="cloudfiles.connection-module.html">M
<a name="L13"></a><tt class="py-lineno"> 13</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">urllib</tt> <tt class="py-keyword">import</tt> <tt class="py-name">quote</tt> </tt>
<a name="L14"></a><tt class="py-lineno"> 14</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">httplib</tt> <tt class="py-keyword">import</tt> <tt class="py-name">HTTPSConnection</tt><tt class="py-op">,</tt> <tt class="py-name">HTTPConnection</tt><tt class="py-op">,</tt> <tt class="py-name">HTTPException</tt> </tt>
<a name="L15"></a><tt class="py-lineno"> 15</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-0" class="py-name" targets="Module cloudfiles.container=cloudfiles.container-module.html"><a title="cloudfiles.container" class="py-name" href="#" onclick="return doclink('link-0', 'container', 'link-0');">container</a></tt> <tt class="py-keyword">import</tt> <tt id="link-1" class="py-name" targets="Class cloudfiles.container.Container=cloudfiles.container.Container-class.html"><a title="cloudfiles.container.Container" class="py-name" href="#" onclick="return doclink('link-1', 'Container', 'link-1');">Container</a></tt><tt class="py-op">,</tt> <tt id="link-2" class="py-name" targets="Class cloudfiles.container.ContainerResults=cloudfiles.container.ContainerResults-class.html"><a title="cloudfiles.container.ContainerResults" class="py-name" href="#" onclick="return doclink('link-2', 'ContainerResults', 'link-2');">ContainerResults</a></tt> </tt>
<a name="L16"></a><tt class="py-lineno"> 16</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">utils</tt> <tt class="py-keyword">import</tt> <tt class="py-name">parse_url</tt><tt class="py-op">,</tt> <tt class="py-name">THTTPConnection</tt><tt class="py-op">,</tt> <tt class="py-name">THTTPSConnection</tt> </tt>
<a name="L16"></a><tt class="py-lineno"> 16</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">utils</tt> <tt class="py-keyword">import</tt> <tt class="py-name">unicode_quote</tt><tt class="py-op">,</tt> <tt class="py-name">parse_url</tt><tt class="py-op">,</tt> <tt class="py-name">THTTPConnection</tt><tt class="py-op">,</tt> <tt class="py-name">THTTPSConnection</tt> </tt>
<a name="L17"></a><tt class="py-lineno"> 17</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-3" class="py-name" targets="Module cloudfiles.errors=cloudfiles.errors-module.html"><a title="cloudfiles.errors" class="py-name" href="#" onclick="return doclink('link-3', 'errors', 'link-3');">errors</a></tt> <tt class="py-keyword">import</tt> <tt id="link-4" class="py-name" targets="Class cloudfiles.errors.ResponseError=cloudfiles.errors.ResponseError-class.html"><a title="cloudfiles.errors.ResponseError" class="py-name" href="#" onclick="return doclink('link-4', 'ResponseError', 'link-4');">ResponseError</a></tt><tt class="py-op">,</tt> <tt id="link-5" class="py-name" targets="Class cloudfiles.errors.NoSuchContainer=cloudfiles.errors.NoSuchContainer-class.html"><a title="cloudfiles.errors.NoSuchContainer" class="py-name" href="#" onclick="return doclink('link-5', 'NoSuchContainer', 'link-5');">NoSuchContainer</a></tt><tt class="py-op">,</tt> <tt id="link-6" class="py-name" targets="Class cloudfiles.errors.ContainerNotEmpty=cloudfiles.errors.ContainerNotEmpty-class.html"><a title="cloudfiles.errors.ContainerNotEmpty" class="py-name" href="#" onclick="return doclink('link-6', 'ContainerNotEmpty', 'link-6');">ContainerNotEmpty</a></tt><tt class="py-op">,</tt> \ </tt>
<a name="L18"></a><tt class="py-lineno"> 18</tt> <tt class="py-line"> <tt id="link-7" class="py-name" targets="Class cloudfiles.errors.InvalidContainerName=cloudfiles.errors.InvalidContainerName-class.html"><a title="cloudfiles.errors.InvalidContainerName" class="py-name" href="#" onclick="return doclink('link-7', 'InvalidContainerName', 'link-7');">InvalidContainerName</a></tt><tt class="py-op">,</tt> <tt id="link-8" class="py-name" targets="Class cloudfiles.errors.CDNNotEnabled=cloudfiles.errors.CDNNotEnabled-class.html"><a title="cloudfiles.errors.CDNNotEnabled" class="py-name" href="#" onclick="return doclink('link-8', 'CDNNotEnabled', 'link-8');">CDNNotEnabled</a></tt> </tt>
<a name="L19"></a><tt class="py-lineno"> 19</tt> <tt class="py-line"><tt class="py-keyword">from</tt> <tt class="py-name">Queue</tt> <tt class="py-keyword">import</tt> <tt class="py-name">Queue</tt><tt class="py-op">,</tt> <tt class="py-name">Empty</tt><tt class="py-op">,</tt> <tt class="py-name">Full</tt> </tt>
Expand Down Expand Up @@ -195,7 +195,7 @@ <h1 class="epydoc">Source Code for <a href="cloudfiles.connection-module.html">M
<a name="L134"></a><tt class="py-lineno">134</tt> <tt class="py-line"> <tt class="py-keyword">raise</tt> <tt id="link-17" class="py-name"><a title="cloudfiles.errors.CDNNotEnabled" class="py-name" href="#" onclick="return doclink('link-17', 'CDNNotEnabled', 'link-8');">CDNNotEnabled</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L135"></a><tt class="py-lineno">135</tt> <tt class="py-line"> </tt>
<a name="L136"></a><tt class="py-lineno">136</tt> <tt class="py-line"> <tt class="py-name">path</tt> <tt class="py-op">=</tt> <tt class="py-string">'/%s/%s'</tt> <tt class="py-op">%</tt> \ </tt>
<a name="L137"></a><tt class="py-lineno">137</tt> <tt class="py-line"> <tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">uri</tt><tt class="py-op">.</tt><tt class="py-name">rstrip</tt><tt class="py-op">(</tt><tt class="py-string">'/'</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-string">'/'</tt><tt class="py-op">.</tt><tt class="py-name">join</tt><tt class="py-op">(</tt><tt class="py-op">[</tt><tt class="py-name">quote</tt><tt class="py-op">(</tt><tt class="py-name">i</tt><tt class="py-op">)</tt> <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">path</tt><tt class="py-op">]</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L137"></a><tt class="py-lineno">137</tt> <tt class="py-line"> <tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">uri</tt><tt class="py-op">.</tt><tt class="py-name">rstrip</tt><tt class="py-op">(</tt><tt class="py-string">'/'</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-string">'/'</tt><tt class="py-op">.</tt><tt class="py-name">join</tt><tt class="py-op">(</tt><tt class="py-op">[</tt><tt class="py-name">unicode_quote</tt><tt class="py-op">(</tt><tt class="py-name">i</tt><tt class="py-op">)</tt> <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">path</tt><tt class="py-op">]</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L138"></a><tt class="py-lineno">138</tt> <tt class="py-line"> <tt class="py-name">headers</tt> <tt class="py-op">=</tt> <tt class="py-op">{</tt><tt class="py-string">'Content-Length'</tt><tt class="py-op">:</tt> <tt class="py-name">str</tt><tt class="py-op">(</tt><tt class="py-name">len</tt><tt class="py-op">(</tt><tt class="py-name">data</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> </tt>
<a name="L139"></a><tt class="py-lineno">139</tt> <tt class="py-line"> <tt class="py-string">'User-Agent'</tt><tt class="py-op">:</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">user_agent</tt><tt class="py-op">,</tt> </tt>
<a name="L140"></a><tt class="py-lineno">140</tt> <tt class="py-line"> <tt class="py-string">'X-Auth-Token'</tt><tt class="py-op">:</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">token</tt><tt class="py-op">}</tt> </tt>
Expand Down Expand Up @@ -227,7 +227,7 @@ <h1 class="epydoc">Source Code for <a href="cloudfiles.connection-module.html">M
<a name="L166"></a><tt class="py-lineno">166</tt> <tt class="py-line"><tt class="py-docstring"> performs an http request.</tt> </tt>
<a name="L167"></a><tt class="py-lineno">167</tt> <tt class="py-line"><tt class="py-docstring"> """</tt> </tt>
<a name="L168"></a><tt class="py-lineno">168</tt> <tt class="py-line"> <tt class="py-name">path</tt> <tt class="py-op">=</tt> <tt class="py-string">'/%s/%s'</tt> <tt class="py-op">%</tt> \ </tt>
<a name="L169"></a><tt class="py-lineno">169</tt> <tt class="py-line"> <tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">uri</tt><tt class="py-op">.</tt><tt class="py-name">rstrip</tt><tt class="py-op">(</tt><tt class="py-string">'/'</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-string">'/'</tt><tt class="py-op">.</tt><tt class="py-name">join</tt><tt class="py-op">(</tt><tt class="py-op">[</tt><tt class="py-name">quote</tt><tt class="py-op">(</tt><tt class="py-name">i</tt><tt class="py-op">)</tt> <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">path</tt><tt class="py-op">]</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L169"></a><tt class="py-lineno">169</tt> <tt class="py-line"> <tt class="py-op">(</tt><tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">uri</tt><tt class="py-op">.</tt><tt class="py-name">rstrip</tt><tt class="py-op">(</tt><tt class="py-string">'/'</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-string">'/'</tt><tt class="py-op">.</tt><tt class="py-name">join</tt><tt class="py-op">(</tt><tt class="py-op">[</tt><tt class="py-name">unicode_quote</tt><tt class="py-op">(</tt><tt class="py-name">i</tt><tt class="py-op">)</tt> <tt class="py-keyword">for</tt> <tt class="py-name">i</tt> <tt class="py-keyword">in</tt> <tt class="py-name">path</tt><tt class="py-op">]</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L170"></a><tt class="py-lineno">170</tt> <tt class="py-line"> </tt>
<a name="L171"></a><tt class="py-lineno">171</tt> <tt class="py-line"> <tt class="py-keyword">if</tt> <tt class="py-name">isinstance</tt><tt class="py-op">(</tt><tt class="py-name">parms</tt><tt class="py-op">,</tt> <tt class="py-name">dict</tt><tt class="py-op">)</tt> <tt class="py-keyword">and</tt> <tt class="py-name">parms</tt><tt class="py-op">:</tt> </tt>
<a name="L172"></a><tt class="py-lineno">172</tt> <tt class="py-line"> <tt class="py-name">query_args</tt> <tt class="py-op">=</tt> \ </tt>
Expand Down Expand Up @@ -584,7 +584,7 @@ <h1 class="epydoc">Source Code for <a href="cloudfiles.connection-module.html">M
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Tue Mar 1 15:49:53 2011
Generated by Epydoc 3.0.1 on Wed Mar 9 11:09:14 2011
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
Expand Down
2 changes: 1 addition & 1 deletion docs/cloudfiles.connection.Connection-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ <h3 class="epydoc"><span class="sig"><span class="sig-name">__getitem__</span>(<
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Tue Mar 1 15:49:52 2011
Generated by Epydoc 3.0.1 on Wed Mar 9 11:09:13 2011
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
Expand Down
2 changes: 1 addition & 1 deletion docs/cloudfiles.connection.ConnectionPool-class.html
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ <h3 class="epydoc"><span class="sig"><span class="sig-name">put</span>(<span cla
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Tue Mar 1 15:49:52 2011
Generated by Epydoc 3.0.1 on Wed Mar 9 11:09:13 2011
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
Expand Down
2 changes: 1 addition & 1 deletion docs/cloudfiles.container-module.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ <h1 class="epydoc">Module container</h1><p class="nomargin-top"><span class="cod
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
<tr>
<td align="left" class="footer">
Generated by Epydoc 3.0.1 on Tue Mar 1 15:49:52 2011
Generated by Epydoc 3.0.1 on Wed Mar 9 11:09:13 2011
</td>
<td align="right" class="footer">
<a target="mainFrame" href="http://epydoc.sourceforge.net"
Expand Down
Loading

0 comments on commit 8a2e881

Please sign in to comment.