Hey All,
Here's a quick patch to enable support for the DefaultRootObject in
CloudFront distributions. I haven't given it extensive testing & I'm not
familiar with the code base, but it seems to work for me.
Cheers,
Luke
Index: S3/CloudFront.py
===================================================================
--- S3/CloudFront.py (revision 437)
+++ S3/CloudFront.py (working copy)
@@ -53,7 +53,7 @@
class DistributionList(object):
## Example:
##
- ## <DistributionList xmlns="http://cloudfront.amazonaws.com/doc/2010-06-01/">
+ ## <DistributionList xmlns="http://cloudfront.amazonaws.com/doc/2010-07-15/">
## <Marker />
## <MaxItems>100</MaxItems>
## <IsTruncated>false</IsTruncated>
@@ -80,7 +80,7 @@
class Distribution(object):
## Example:
##
- ## <Distribution xmlns="http://cloudfront.amazonaws.com/doc/2010-06-01/">
+ ## <Distribution xmlns="http://cloudfront.amazonaws.com/doc/2010-07-15/">
## <Id>1234567890ABC</Id>
## <Status>InProgress</Status>
## <LastModifiedTime>2009-01-16T13:07:11.319Z</LastModifiedTime>
@@ -121,7 +121,7 @@
## </DistributionConfig>
EMPTY_CONFIG = "<DistributionConfig><Origin/><CallerReference/><Enabled>true</Enabled></DistributionConfig>"
- xmlns = "http://cloudfront.amazonaws.com/doc/2010-06-01/"
+ xmlns = "http://cloudfront.amazonaws.com/doc/2010-07-15/"
def __init__(self, xml = None, tree = None):
if not xml:
xml = DistributionConfig.EMPTY_CONFIG
@@ -143,6 +143,8 @@
self.info['CNAME'] = [cname.lower() for cname in self.info['CNAME']]
if not self.info.has_key("Comment"):
self.info['Comment'] = ""
+ if not self.info.has_key("DefaultRootObject"):
+ self.info['DefaultRootObject'] = ""
## Figure out logging - complex node not parsed by getDictFromTree()
logging_nodes = tree.findall(".//Logging")
if logging_nodes:
@@ -166,6 +168,9 @@
if self.info['Comment']:
appendXmlTextNode("Comment", self.info['Comment'], tree)
appendXmlTextNode("Enabled", str(self.info['Enabled']).lower(), tree)
+ # don't create a empty DefaultRootObject element as it would result in a MalformedXML error
+ if str(self.info['DefaultRootObject']):
+ appendXmlTextNode("DefaultRootObject", str(self.info['DefaultRootObject']), tree)
if self.info['Logging']:
logging_el = ET.Element("Logging")
appendXmlTextNode("Bucket", getHostnameFromBucket(self.info['Logging'].bucket()), logging_el)
@@ -201,11 +206,12 @@
## TODO: handle Truncated
return response
- def CreateDistribution(self, uri, cnames_add = [], comment = None, logging = None):
+ def CreateDistribution(self, uri, cnames_add = [], comment = None, logging = None, default_root_object = None):
dist_config = DistributionConfig()
dist_config.info['Enabled'] = True
dist_config.info['Origin'] = uri.host_name()
dist_config.info['CallerReference'] = str(uri)
+ dist_config.info['DefaultRootObject'] = default_root_object
if comment == None:
dist_config.info['Comment'] = uri.public_url()
else:
@@ -222,7 +228,8 @@
return response
def ModifyDistribution(self, cfuri, cnames_add = [], cnames_remove = [],
- comment = None, enabled = None, logging = None):
+ comment = None, enabled = None, logging = None,
+ default_root_object = None):
if cfuri.type != "cf":
raise ValueError("Expected CFUri instead of: %s" % cfuri)
# Get current dist status (enabled/disabled) and Etag
@@ -233,6 +240,8 @@
dc.info['Enabled'] = enabled
if comment != None:
dc.info['Comment'] = comment
+ if default_root_object != None:
+ dc.info['DefaultRootObject'] = default_root_object
for cname in cnames_add:
if dc.info['CNAME'].count(cname) == 0:
dc.info['CNAME'].append(cname)
@@ -390,6 +399,7 @@
cf_comment = None
cf_enable = None
cf_logging = None
+ cf_default_root_object = None
def option_list(self):
return [opt for opt in dir(self) if opt.startswith("cf_")]
@@ -454,6 +464,7 @@
pretty_output("CNAMEs", ", ".join(dc.info['CNAME']))
pretty_output("Comment", dc.info['Comment'])
pretty_output("Enabled", dc.info['Enabled'])
+ pretty_output("DefaultRootObject", dc.info['DefaultRootObject'])
pretty_output("Logging", dc.info['Logging'] or "Disabled")
pretty_output("Etag", response['headers']['etag'])
@@ -476,7 +487,8 @@
info("Creating distribution from: %s" % uri)
response = cf.CreateDistribution(uri, cnames_add = Cmd.options.cf_cnames_add,
comment = Cmd.options.cf_comment,
- logging = Cmd.options.cf_logging)
+ logging = Cmd.options.cf_logging,
+ default_root_object = Cmd.options.cf_default_root_object)
d = response['distribution']
dc = d.info['DistributionConfig']
output("Distribution created:")
@@ -487,6 +499,7 @@
pretty_output("Comment", dc.info['Comment'])
pretty_output("Status", d.info['Status'])
pretty_output("Enabled", dc.info['Enabled'])
+ pretty_output("DefaultRootObject", dc.info['DefaultRootObject'])
pretty_output("Etag", response['headers']['etag'])
@staticmethod
@@ -513,7 +526,8 @@
cnames_remove = Cmd.options.cf_cnames_remove,
comment = Cmd.options.cf_comment,
enabled = Cmd.options.cf_enable,
- logging = Cmd.options.cf_logging)
+ logging = Cmd.options.cf_logging,
+ default_root_object = Cmd.options.cf_default_root_object)
if response['status'] >= 400:
error("Distribution %s could not be modified: %s" % (cfuri, response['reason']))
output("Distribution modified: %s" % cfuri)
@@ -527,4 +541,5 @@
pretty_output("CNAMEs", ", ".join(dc.info['CNAME']))
pretty_output("Comment", dc.info['Comment'])
pretty_output("Enabled", dc.info['Enabled'])
+ pretty_output("DefaultRootObject", dc.info['DefaultRootObject'])
pretty_output("Etag", response['headers']['etag'])
Index: S3/Config.py
===================================================================
--- S3/Config.py (revision 437)
+++ S3/Config.py (working copy)
@@ -19,7 +19,7 @@
host_bucket = "%(bucket)s.s3.amazonaws.com"
simpledb_host = "sdb.amazonaws.com"
cloudfront_host = "cloudfront.amazonaws.com"
- cloudfront_resource = "/2010-06-01/distribution"
+ cloudfront_resource = "/2010-07-15/distribution"
verbosity = logging.WARNING
progress_meter = True
progress_class = Progress.ProgressCR
Index: s3cmd
===================================================================
--- s3cmd (revision 437)
+++ s3cmd (working copy)
@@ -1654,6 +1654,7 @@
optparser.add_option( "--cf-add-cname", dest="cf_cnames_add", action="append", metavar="CNAME", help="Add given CNAME to a CloudFront distribution (only for [cfcreate] and [cfmodify] commands)")
optparser.add_option( "--cf-remove-cname", dest="cf_cnames_remove", action="append", metavar="CNAME", help="Remove given CNAME from a CloudFront distribution (only for [cfmodify] command)")
optparser.add_option( "--cf-comment", dest="cf_comment", action="store", metavar="COMMENT", help="Set COMMENT for a given CloudFront distribution (only for [cfcreate] and [cfmodify] commands)")
+ optparser.add_option( "--cf-default-root-object", dest="cf_default_root_object", action="store", metavar="DEFAULT_ROOT_OBJECT", help="Set the default root object to return when no object is specified in the URL (only for [cfcreate] and [cfmodify] commands)")
optparser.add_option("-v", "--verbose", dest="verbosity", action="store_const", const=logging.INFO, help="Enable verbose output.")
optparser.add_option("-d", "--debug", dest="verbosity", action="store_const", const=logging.DEBUG, help="Enable debug output.")
optparser.add_option( "--version", dest="show_version", action="store_true", help="Show s3cmd version (%s) and exit." % (PkgInfo.version))
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
S3tools-general mailing list
S3tools-general@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/s3tools-general