Permalink
Browse files

Merge remote-tracking branch 'joseprio/master' into joseprio-merge

Conflicts:
	s3cmd
  • Loading branch information...
2 parents 8726861 + e364d9f commit bad6e247b4383d0cddb97fe8d91cbb9dde5ec5ea @mdomsch committed Jul 14, 2012
Showing with 46 additions and 13 deletions.
  1. +18 −2 S3/CloudFront.py
  2. +3 −0 S3/Config.py
  3. +25 −11 s3cmd
View
@@ -281,7 +281,7 @@ def __str__(self):
tree = ET.Element("InvalidationBatch")
for path in self.paths:
- if path[0] != "/":
+ if len(path) < 1 or path[0] != "/":
path = "/" + path
appendXmlTextNode("Path", path, tree)
appendXmlTextNode("CallerReference", self.reference, tree)
@@ -423,7 +423,23 @@ def SetDistConfig(self, cfuri, dist_config, etag = None):
body = request_body, headers = headers)
return response
- def InvalidateObjects(self, uri, paths):
+ def InvalidateObjects(self, uri, paths, default_index_file, invalidate_default_index_on_cf, invalidate_default_index_root_on_cf):
+ # joseprio: if the user doesn't want to invalidate the default index
+ # path, or if the user wants to invalidate the root of the default
+ # index, we need to process those paths
+ if default_index_file is not None and (not invalidate_default_index_on_cf or invalidate_default_index_root_on_cf):
+ new_paths = []
+ default_index_suffix = '/' + default_index_file
+ for path in paths:
+ if path.endswith(default_index_suffix) or path == default_index_file:
+ if invalidate_default_index_on_cf:
+ new_paths.append(path)
+ if invalidate_default_index_root_on_cf:
+ new_paths.append(path[:-len(default_index_file)])
+ else:
+ new_paths.append(path)
+ paths = new_paths
+
# uri could be either cf:// or s3:// uri
cfuri = self.get_dist_name_for_bucket(uri)
if len(paths) > 999:
View
@@ -83,6 +83,9 @@ class Config(object):
follow_symlinks = False
socket_timeout = 300
invalidate_on_cf = False
+ # joseprio: new flags for default index invalidation
+ invalidate_default_index_on_cf = False
+ invalidate_default_index_root_on_cf = True
website_index = "index.html"
website_error = ""
website_endpoint = "http://%(bucket)s.s3-website-%(location)s.amazonaws.com/"
View
36 s3cmd
@@ -1066,17 +1066,6 @@ def cmd_sync_local2remote(args):
else:
info(outstr)
- if cfg.invalidate_on_cf:
- if len(uploaded_objects_list) == 0:
- info("Nothing to invalidate in CloudFront")
- else:
- # 'uri' from the last iteration is still valid at this point
- cf = CloudFront(cfg)
- result = cf.InvalidateObjects(uri, uploaded_objects_list)
- if result['status'] == 201:
- output("Created invalidation request for %d paths" % len(uploaded_objects_list))
- output("Check progress with: s3cmd cfinvalinfo cf://%s/%s" % (result['dist_id'], result['request_id']))
-
return
# main execution
@@ -1139,6 +1128,27 @@ def cmd_sync_local2remote(args):
else:
_parent()
+ if cfg.invalidate_on_cf:
+ if len(uploaded_objects_list) == 0:
+ info("Nothing to invalidate in CloudFront")
+ else:
+ # 'uri' from the last iteration is still valid at this point
+ cf = CloudFront(cfg)
+ # joseprio: obtain default index file if we need it for invalidating
+ # the files
+ default_index_file = None
+ if cfg.invalidate_default_index_on_cf or cfg.invalidate_default_index_root_on_cf:
+ info_response = s3.website_info(destination_base_uri, cfg.bucket_location)
+ if info_response:
+ default_index_file = info_response['index_document']
+ if len(default_index_file) < 1:
+ default_index_file = None
+ # joseprio: pass configuration information for invalidating default
+ # index file
+ result = cf.InvalidateObjects(uri, uploaded_objects_list, default_index_file, cfg.invalidate_default_index_on_cf, cfg.invalidate_default_index_root_on_cf)
+ if result['status'] == 201:
+ output("Created invalidation request for %d paths" % len(uploaded_objects_list))
+ output("Check progress with: s3cmd cfinvalinfo cf://%s/%s" % (result['dist_id'], result['request_id']))
def cmd_sync(args):
if (len(args) < 2):
@@ -1727,6 +1737,10 @@ def main():
optparser.add_option( "--enable", dest="enable", action="store_true", help="Enable given CloudFront distribution (only for [cfmodify] command)")
optparser.add_option( "--disable", dest="enable", action="store_false", help="Enable given CloudFront distribution (only for [cfmodify] command)")
optparser.add_option( "--cf-invalidate", dest="invalidate_on_cf", action="store_true", help="Invalidate the uploaded filed in CloudFront. Also see [cfinval] command.")
+ # joseprio: adding options to invalidate the default index and the default
+ # index root
+ optparser.add_option( "--cf-invalidate-default-index", dest="invalidate_default_index_on_cf", action="store_true", help="When using Custom Origin and S3 static website, invalidate the default index file.")
+ optparser.add_option( "--cf-no-invalidate-default-index-root", dest="invalidate_default_index_root_on_cf", action="store_false", help="When using Custom Origin and S3 static website, don't invalidate the path to the default index file.")
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)")

0 comments on commit bad6e24

Please sign in to comment.