Browse code

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

Kevin Daub authored on 2013/06/11 10:53:17
Showing 4 changed files
... ...
@@ -29,6 +29,7 @@ class Config(object):
29 29
     human_readable_sizes = False
30 30
     extra_headers = SortedDict(ignore_case = True)
31 31
     force = False
32
+    server_side_encryption = False
32 33
     enable = None
33 34
     get_continue = False
34 35
     skip_existing = False
... ...
@@ -410,7 +410,11 @@ class S3(object):
410 410
         headers = SortedDict(ignore_case = True)
411 411
         if extra_headers:
412 412
             headers.update(extra_headers)
413
-
413
+        
414
+        ## Set server side encryption
415
+        if self.config.server_side_encryption:
416
+            headers["x-amz-server-side-encryption"] = "AES256"
417
+    
414 418
         ## MIME-type handling
415 419
         content_type = self.config.mime_type
416 420
         content_encoding = None
... ...
@@ -483,6 +487,11 @@ class S3(object):
483 483
             headers["x-amz-storage-class"] = "REDUCED_REDUNDANCY"
484 484
         # if extra_headers:
485 485
         #   headers.update(extra_headers)
486
+        
487
+        ## Set server side encryption
488
+        if self.config.server_side_encryption:
489
+            headers["x-amz-server-side-encryption"] = "AES256" 
490
+        
486 491
         request = self.create_request("OBJECT_PUT", uri = dst_uri, headers = headers)
487 492
         response = self.send_request(request)
488 493
         return response
... ...
@@ -1751,6 +1751,8 @@ def main():
1751 1751
 
1752 1752
     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.")
1753 1753
 
1754
+    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.")
1755
+
1754 1756
     optparser.add_option(      "--encoding", dest="encoding", metavar="ENCODING", help="Override autodetected terminal and filesystem encoding (character set). Autodetected: %s" % preferred_encoding)
1755 1757
     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 )")
1756 1758
     optparser.add_option(      "--verbatim", dest="urlencoding_mode", action="store_const", const="verbatim", help="Use the S3 name as given on the command line. No pre-processing, encoding, etc. Use with caution!")
... ...
@@ -325,12 +325,14 @@ Follow symbolic links as if they are regular files
325 325
 .TP
326 326
 \fB\-\-cache\-file\fR=FILE
327 327
 Cache FILE containing local source MD5 values
328
-
328
+.TP
329
+\fB\-\-server\-side\-encryption\fR
330
+Specifies that server-side encryption will be used when putting objects.
329 331
 
330 332
 .SH EXAMPLES
331 333
 One of the most powerful commands of \fIs3cmd\fR is \fBs3cmd sync\fR used for 
332
-synchronising complete directory trees to or from remote S3 storage. To some extent 
333
-\fBs3cmd put\fR and \fBs3cmd get\fR share a similar behaviour with \fBsync\fR.
334
+synchronizing complete directory trees to or from remote S3 storage. To some extent 
335
+\fBs3cmd put\fR and \fBs3cmd get\fR share a similar behavior with \fBsync\fR.
334 336
 .PP
335 337
 Basic usage common in backup scenarios is as simple as:
336 338
 .nf