Browse code

finish merge of #186

Added --server-side-encryption as an option and adds the header to put
and put-copy

Matt Domsch authored on 2013/11/26 10:01:56
Showing 3 changed files
... ...
@@ -36,6 +36,7 @@ class Config(object):
36 36
     human_readable_sizes = False
37 37
     extra_headers = SortedDict(ignore_case = True)
38 38
     force = False
39
+    server_side_encryption = False
39 40
     enable = None
40 41
     get_continue = False
41 42
     put_continue = False
... ...
@@ -403,7 +403,11 @@ class S3(object):
403 403
         headers = SortedDict(ignore_case = True)
404 404
         if extra_headers:
405 405
             headers.update(extra_headers)
406
-
406
+        
407
+        ## Set server side encryption
408
+        if self.config.server_side_encryption:
409
+            headers["x-amz-server-side-encryption"] = "AES256"
410
+    
407 411
         ## MIME-type handling
408 412
         content_type = self.config.mime_type
409 413
         content_encoding = None
... ...
@@ -499,6 +503,11 @@ class S3(object):
499 499
             headers["x-amz-storage-class"] = "REDUCED_REDUNDANCY"
500 500
         # if extra_headers:
501 501
         #   headers.update(extra_headers)
502
+        
503
+        ## Set server side encryption
504
+        if self.config.server_side_encryption:
505
+            headers["x-amz-server-side-encryption"] = "AES256" 
506
+        
502 507
         request = self.create_request("OBJECT_PUT", uri = dst_uri, headers = headers)
503 508
         response = self.send_request(request)
504 509
         return response
... ...
@@ -626,6 +626,11 @@ def cmd_info(args):
626 626
                 except KeyError:
627 627
                     pass
628 628
                 output(u"   MD5 sum:   %s" % md5)
629
+                if 'x-amz-server-side-encryption' in info['headers']:
630
+                    output(u"   SSE:       %s" % info['headers']['x-amz-server-side-encryption'])
631
+                else:
632
+                    output(u"   SSE:       NONE")		
633
+
629 634
             else:
630 635
                 info = s3.bucket_info(uri)
631 636
                 output(u"%s (bucket):" % uri.uri())
... ...
@@ -1928,6 +1933,8 @@ def main():
1928 1928
 
1929 1929
     optparser.add_option(      "--add-header", dest="add_header", action="append", metavar="NAME:VALUE", help="Add a given HTTP header to the upload request. Can be used multiple times. For instance set 'Expires' or 'Cache-Control' headers (or both) using this options if you like.")
1930 1930
 
1931
+    optparser.add_option(      "--server-side-encryption", dest="server_side_encryption", action="store_true", help="Specifies that server-side encryption will be used when putting objects.")
1932
+
1931 1933
     optparser.add_option(      "--encoding", dest="encoding", metavar="ENCODING", help="Override autodetected terminal and filesystem encoding (character set). Autodetected: %s" % preferred_encoding)
1932 1934
     optparser.add_option(      "--disable-content-encoding", dest="add_content_encoding", action="store_false", help="Don't include a Content-encoding header to the the uploaded objects")
1933 1935
     optparser.add_option(      "--add-encoding-exts", dest="add_encoding_exts", metavar="EXTENSIONs", help="Add encoding to these comma delimited extensions i.e. (css,js,html) when uploading to S3 )")