def test_environment_audit_local_update_active(self): env_status_key = 'test-audit-config-update.json' env_status_key_result = 'test-audit-config-update-result.json' expected_result = 'test-audit-config-update-expected-result.json' timestamp = '2000-01-02T01:00:00.00000' utils.put_json(env_status_key_result, environment.audit(utils.get_json(env_status_key), timestamp=timestamp)) self.assertEqual(utils.get_json(expected_result), utils.get_json(env_status_key_result), "Audit result is not correct")
def test_environment_audit_dynamo(self): env_status_key = 'test-audit-config.json' s3_obj = s3.AwsS3(s3=self.S3_BUCKET, aws_profile=self.AWS_PROFILE, aws_region=self.AWS_REGION) ddb_obj = dynamo_db.AwsDynamoDb(table_name=self.DB_TABLE_NAME, aws_profile=self.AWS_PROFILE, aws_region=self.AWS_REGION) audit_data = environment.audit(s3_obj.get_json(env_status_key)) active_environment = environment.minify(environment.get_current_active_environment(audit_data['environments'])) ddb_obj.save_audit(active_environment['last-time-active'].split('T')[0], active_environment)
def test_environment_audit_s3_update_active(self): env_status_key = 'test-audit-config-update.json' env_status_key_result = 'test-audit-config-update-result.json' expected_result = 'test-audit-config-update-expected-result.json' timestamp = '2000-01-02T01:00:00.00000' s3_obj = s3.AwsS3(s3=self.S3_BUCKET, aws_profile=self.AWS_PROFILE, aws_region=self.AWS_REGION) s3_obj.copy_to_s3(env_status_key) s3_obj.put_json(env_status_key_result, environment.audit(s3_obj.get_json(env_status_key), timestamp=timestamp)) self.assertEqual(utils.get_json(expected_result), s3_obj.get_json(env_status_key_result), "Audit result is not correct")
def run(event, context): """ Basic algorithm: 1. Read existing audit data from S3 bucket (location defined as S3_BUCKET and ENV_STATUS_KEY) 2. Determine currently active environment 3. Save updated data to the S3 using same bucket and key 4. Add audit results to DynamoDB :param event: :param context: :return: """ local_vars = get_variables() s3_obj = s3.AwsS3(s3=local_vars['S3_BUCKET']) ddb_obj = dynamo_db.AwsDynamoDb(table_name=local_vars['DB_TABLE_NAME']) audit_data = environment.audit( s3_obj.get_json(local_vars['ENV_STATUS_KEY'])) active_environment = environment.minify( environment.get_current_active_environment(audit_data['environments'])) s3_obj.put_json(local_vars['ENV_STATUS_KEY'], audit_data) ddb_obj.save_audit(active_environment['last-time-active'].split('T')[0], active_environment)