Permalink
Browse files

Merge branch 'ryansydnor-enc' into develop

* ryansydnor-enc:
  Add encryption capability to AMI copy
  • Loading branch information...
jamesls committed Mar 21, 2016
2 parents dd5f87c + 51e6035 commit 99fbd8a2ce238e088110d031ea9cc06a1e6dd3a4
Showing with 67 additions and 14 deletions.
  1. +6 −1 boto/ec2/connection.py
  2. +61 −13 tests/unit/ec2/test_connection.py
View
@@ -4405,7 +4405,8 @@ def get_all_instance_types(self):
return self.get_list('DescribeInstanceTypes', params, [('item', InstanceType)], verb='POST')
def copy_image(self, source_region, source_image_id, name=None,
description=None, client_token=None, dry_run=False):
description=None, client_token=None, dry_run=False,
encrypted=None, kms_key_id=None):
"""
:type dry_run: bool
:param dry_run: Set to True if the operation should not actually run.
@@ -4422,6 +4423,10 @@ def copy_image(self, source_region, source_image_id, name=None,
params['Description'] = description
if client_token is not None:
params['ClientToken'] = client_token
if encrypted is not None:
params['Encrypted'] = 'true' if encrypted else 'false'
if kms_key_id is not None:
params['KmsKeyId'] = kms_key_id
if dry_run:
params['DryRun'] = 'true'
return self.get_object('CopyImage', params, CopyImage,
@@ -531,37 +531,85 @@ def default_body(self):
</CopyImageResponse>
"""
def test_copy_image(self):
def test_copy_image_required_params(self):
self.set_http_response(status_code=200)
copied_ami = self.ec2.copy_image('us-west-2', 'ami-id',
'name', 'description', 'client-token')
copied_ami = self.ec2.copy_image('us-west-2', 'ami-id')
self.assertEqual(copied_ami.image_id, 'ami-copied-id')
self.assert_request_parameters({
'Action': 'CopyImage',
'SourceRegion': 'us-west-2',
'SourceImageId': 'ami-id'
}, ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
'SignatureVersion', 'Timestamp',
'Version'])
def test_copy_image_name_and_description(self):
self.set_http_response(status_code=200)
copied_ami = self.ec2.copy_image('us-west-2', 'ami-id', 'name', 'description')
self.assertEqual(copied_ami.image_id, 'ami-copied-id')
self.assert_request_parameters({
'Action': 'CopyImage',
'Description': 'description',
'SourceRegion': 'us-west-2',
'SourceImageId': 'ami-id',
'Name': 'name',
'Description': 'description'
}, ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
'SignatureVersion', 'Timestamp',
'Version'])
def test_copy_image_client_token(self):
self.set_http_response(status_code=200)
copied_ami = self.ec2.copy_image('us-west-2', 'ami-id', client_token='client-token')
self.assertEqual(copied_ami.image_id, 'ami-copied-id')
self.assert_request_parameters({
'Action': 'CopyImage',
'SourceRegion': 'us-west-2',
'SourceImageId': 'ami-id',
'ClientToken': 'client-token'},
ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
'ClientToken': 'client-token'
}, ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
'SignatureVersion', 'Timestamp',
'Version'])
def test_copy_image_without_name(self):
def test_copy_image_encrypted(self):
self.set_http_response(status_code=200)
copied_ami = self.ec2.copy_image('us-west-2', 'ami-id',
description='description',
client_token='client-token')
copied_ami = self.ec2.copy_image('us-west-2', 'ami-id', encrypted=True)
self.assertEqual(copied_ami.image_id, 'ami-copied-id')
self.assert_request_parameters({
'Action': 'CopyImage',
'Description': 'description',
'SourceRegion': 'us-west-2',
'SourceImageId': 'ami-id',
'ClientToken': 'client-token'},
ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
'Encrypted': 'true'
}, ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
'SignatureVersion', 'Timestamp',
'Version'])
def test_copy_image_not_encrypted(self):
self.set_http_response(status_code=200)
copied_ami = self.ec2.copy_image('us-west-2', 'ami-id', encrypted=False)
self.assertEqual(copied_ami.image_id, 'ami-copied-id')
self.assert_request_parameters({
'Action': 'CopyImage',
'SourceRegion': 'us-west-2',
'SourceImageId': 'ami-id',
'Encrypted': 'false'
}, ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
'SignatureVersion', 'Timestamp',
'Version'])
def test_copy_image_encrypted_with_kms_key(self):
self.set_http_response(status_code=200)
copied_ami = self.ec2.copy_image('us-west-2', 'ami-id', encrypted=False, kms_key_id='kms-key')
self.assertEqual(copied_ami.image_id, 'ami-copied-id')
self.assert_request_parameters({
'Action': 'CopyImage',
'SourceRegion': 'us-west-2',
'SourceImageId': 'ami-id',
'Encrypted': 'false',
'KmsKeyId': 'kms-key'
}, ignore_params_values=['AWSAccessKeyId', 'SignatureMethod',
'SignatureVersion', 'Timestamp',
'Version'])

0 comments on commit 99fbd8a

Please sign in to comment.