mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 17:09:03 +00:00
Module functionality for support of state module
This commit is contained in:
parent
0d211a4fd5
commit
549d0b8d8b
@ -296,3 +296,98 @@ def list(region=None, key=None, keyid=None, profile=None):
|
||||
return {'trails': trails.get('trailList',[])}
|
||||
except ClientError as e:
|
||||
return {'error': salt.utils.boto3.get_error(e)}
|
||||
|
||||
|
||||
def update(Name,
|
||||
S3BucketName, S3KeyPrefix=None,
|
||||
SnsTopicName=None,
|
||||
IncludeGlobalServiceEvents=None,
|
||||
#IsMultiRegionTrail=None,
|
||||
EnableLogFileValidation=None,
|
||||
CloudWatchLogsLogGroupArn=None,
|
||||
CloudWatchLogsRoleArn=None,
|
||||
KmsKeyId=None,
|
||||
region=None, key=None, keyid=None, profile=None):
|
||||
'''
|
||||
Given a valid config, update a trail.
|
||||
|
||||
Returns {created: true} if the trail was created and returns
|
||||
{created: False} if the trail was not created.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt myminion boto_cloudtrail.update my_trail my_bucket
|
||||
|
||||
'''
|
||||
|
||||
try:
|
||||
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
|
||||
kwargs={}
|
||||
for arg in ('S3KeyPrefix', 'SnsTopicName', 'IncludeGlobalServiceEvents',
|
||||
#'IsMultiRegionTrail',
|
||||
'EnableLogFileValidation', 'CloudWatchLogsLogGroupArn',
|
||||
'CloudWatchLogsRoleArn', 'KmsKeyId'):
|
||||
if locals()[arg] is not None:
|
||||
kwargs[arg] = locals()[arg]
|
||||
trail = conn.update_trail(Name=Name,
|
||||
S3BucketName=S3BucketName,
|
||||
**kwargs)
|
||||
if trail:
|
||||
log.info('The updated trail name is {0}'.format(trail['Name']))
|
||||
|
||||
return {'updated': True, 'name': trail['Name']}
|
||||
else:
|
||||
log.warning('Trail was not created')
|
||||
return {'updated': False}
|
||||
except ClientError as e:
|
||||
return {'updated': False, 'error': salt.utils.boto3.get_error(e)}
|
||||
|
||||
|
||||
def start_logging(Name,
|
||||
region=None, key=None, keyid=None, profile=None):
|
||||
'''
|
||||
Start logging for a trail
|
||||
|
||||
Returns {started: true} if the trail was started and returns
|
||||
{started: False} if the trail was not started.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt myminion boto_cloudtrail.start_logging my_trail
|
||||
|
||||
'''
|
||||
|
||||
try:
|
||||
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
|
||||
conn.start_logging(Name=Name)
|
||||
return {'started': True }
|
||||
except ClientError as e:
|
||||
return {'started': False, 'error': salt.utils.boto3.get_error(e)}
|
||||
|
||||
|
||||
def stop_logging(Name,
|
||||
region=None, key=None, keyid=None, profile=None):
|
||||
'''
|
||||
Stop logging for a trail
|
||||
|
||||
Returns {stopped: true} if the trail was stopped and returns
|
||||
{stopped: False} if the trail was not stopped.
|
||||
|
||||
CLI Example:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
salt myminion boto_cloudtrail.stop_logging my_trail
|
||||
|
||||
'''
|
||||
|
||||
try:
|
||||
conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
|
||||
conn.stop_logging(Name=Name)
|
||||
return {'stopped': True }
|
||||
except ClientError as e:
|
||||
return {'stopped': False, 'error': salt.utils.boto3.get_error(e)}
|
||||
|
@ -273,6 +273,61 @@ class BotoCloudTrailTestCase(BotoCloudTrailTestCaseBase, BotoCloudTrailTestCaseM
|
||||
result = boto_cloudtrail.list(**conn_parameters)
|
||||
self.assertEqual(result.get('error', {}).get('message'), error_message.format('list_trails'))
|
||||
|
||||
def test_that_when_updating_a_trail_succeeds_the_update_trail_method_returns_true(self):
|
||||
'''
|
||||
tests True trail updated.
|
||||
'''
|
||||
self.conn.update_trail.return_value = trail_ret
|
||||
result = boto_cloudtrail.update(Name=trail_ret['Name'],
|
||||
S3BucketName=trail_ret['S3BucketName'],
|
||||
**conn_parameters)
|
||||
|
||||
self.assertTrue(result['updated'])
|
||||
|
||||
def test_that_when_updating_a_trail_fails_the_update_trail_method_returns_error(self):
|
||||
'''
|
||||
tests False trail not updated.
|
||||
'''
|
||||
self.conn.update_trail.side_effect = ClientError(error_content, 'update_trail')
|
||||
result = boto_cloudtrail.update(Name=trail_ret['Name'],
|
||||
S3BucketName=trail_ret['S3BucketName'],
|
||||
**conn_parameters)
|
||||
self.assertEqual(result.get('error', {}).get('message'), error_message.format('update_trail'))
|
||||
|
||||
def test_that_when_starting_logging_succeeds_the_start_logging_method_returns_true(self):
|
||||
'''
|
||||
tests True logging started.
|
||||
'''
|
||||
result = boto_cloudtrail.start_logging(Name=trail_ret['Name'], **conn_parameters)
|
||||
|
||||
self.assertTrue(result['started'])
|
||||
|
||||
def test_that_when_start_logging_fails_the_start_logging_method_returns_false(self):
|
||||
'''
|
||||
tests False logging not started.
|
||||
'''
|
||||
self.conn.describe_trails.return_value = {'trailList': []}
|
||||
self.conn.start_logging.side_effect = ClientError(error_content, 'start_logging')
|
||||
result = boto_cloudtrail.start_logging(Name=trail_ret['Name'], **conn_parameters)
|
||||
self.assertFalse(result['started'])
|
||||
|
||||
def test_that_when_stopping_logging_succeeds_the_stop_logging_method_returns_true(self):
|
||||
'''
|
||||
tests True logging stopped.
|
||||
'''
|
||||
result = boto_cloudtrail.stop_logging(Name=trail_ret['Name'], **conn_parameters)
|
||||
|
||||
self.assertTrue(result['stopped'])
|
||||
|
||||
def test_that_when_stop_logging_fails_the_stop_logging_method_returns_false(self):
|
||||
'''
|
||||
tests False logging not stopped.
|
||||
'''
|
||||
self.conn.describe_trails.return_value = {'trailList': []}
|
||||
self.conn.stop_logging.side_effect = ClientError(error_content, 'stop_logging')
|
||||
result = boto_cloudtrail.stop_logging(Name=trail_ret['Name'], **conn_parameters)
|
||||
self.assertFalse(result['stopped'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from integration import run_tests # pylint: disable=import-error
|
||||
|
Loading…
Reference in New Issue
Block a user