Browse code

URL Encode CloudFront invalidation paths

Matt Whiteley authored on 2014/03/22 01:37:27
Showing 1 changed files
... ...
@@ -16,6 +16,7 @@ try:
16 16
 except ImportError:
17 17
     import elementtree.ElementTree as ET
18 18
 
19
+from S3 import S3
19 20
 from Config import Config
20 21
 from Exceptions import *
21 22
 from Utils import getTreeFromXml, appendXmlTextNode, getDictFromTree, dateS3toPython, sign_string, getBucketFromHostname, getHostnameFromBucket
... ...
@@ -281,11 +282,12 @@ class InvalidationBatch(object):
281 281
 
282 282
     def __str__(self):
283 283
         tree = ET.Element("InvalidationBatch")
284
+        s3 = S3(Config())
284 285
 
285 286
         for path in self.paths:
286 287
             if len(path) < 1 or path[0] != "/":
287 288
                 path = "/" + path
288
-            appendXmlTextNode("Path", path, tree)
289
+            appendXmlTextNode("Path", s3.urlencode_string(path), tree)
289 290
         appendXmlTextNode("CallerReference", self.reference, tree)
290 291
         return ET.tostring(tree)
291 292
 
... ...
@@ -433,7 +435,7 @@ class CloudFront(object):
433 433
             new_paths = []
434 434
             default_index_suffix = '/' + default_index_file
435 435
             for path in paths:
436
-                if path.endswith(default_index_suffix) or path ==  default_index_file:
436
+                if path.endswith(default_index_suffix) or path == default_index_file:
437 437
                     if invalidate_default_index_on_cf:
438 438
                         new_paths.append(path)
439 439
                     if invalidate_default_index_root_on_cf: