Skip to content

Commit

Permalink
Fix new pylint violations
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Byers committed Aug 7, 2018
1 parent 12e3892 commit a2c9dda
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 25 deletions.
6 changes: 3 additions & 3 deletions lambda_functions/analyzer/analyzer_aws_lib.py
Expand Up @@ -138,7 +138,7 @@ def put_metric_data(num_yara_rules: int, binaries: List[BinaryInfo]) -> None:
CLOUDWATCH.put_metric_data(Namespace='BinaryAlert', MetricData=metric_data)


class DynamoMatchTable(object):
class DynamoMatchTable:
"""Saves YARA match information into a Dynamo table.
The table uses a composite key:
Expand Down Expand Up @@ -193,8 +193,8 @@ def _most_recent_item(self, sha: str) -> Optional[Tuple[int, Set[str], Set[str],
if len(most_recent_items) >= 2:
previous_s3_objects = set(most_recent_items[1]['S3Objects'])
return analyzer_version, matched_rules, s3_objects, previous_s3_objects
else:
return None

return None

@staticmethod
def _replace_empty_strings(data: Dict[str, str]) -> Dict[str, str]:
Expand Down
2 changes: 1 addition & 1 deletion lambda_functions/analyzer/binary_info.py
Expand Up @@ -19,7 +19,7 @@
from yara_analyzer import YaraAnalyzer, YaraMatch # type: ignore


class BinaryInfo(object):
class BinaryInfo:
"""Organizes the analysis of a single binary blob in S3."""

def __init__(self, bucket_name: str, object_key: str, yara_analyzer: YaraAnalyzer) -> None:
Expand Down
2 changes: 1 addition & 1 deletion lambda_functions/analyzer/yara_analyzer.py
Expand Up @@ -62,7 +62,7 @@ def _convert_yextend_to_yara_match(yextend_json: Dict[str, Any]) -> List[YaraMat
return matches


class YaraAnalyzer(object):
class YaraAnalyzer:
"""Encapsulates YARA analysis and matching functions."""

def __init__(self, compiled_rules_file: str) -> None:
Expand Down
8 changes: 4 additions & 4 deletions lambda_functions/batcher/main.py
Expand Up @@ -23,7 +23,7 @@
SQS_MAX_MESSAGES_PER_BATCH = 10


class SQSMessage(object):
class SQSMessage:
"""Encapsulates a single SQS message (which will contain multiple S3 keys)."""

def __init__(self, msg_id: int) -> None:
Expand Down Expand Up @@ -70,7 +70,7 @@ def reset(self) -> None:
self._keys = []


class SQSBatcher(object):
class SQSBatcher:
"""Collect groups of S3 keys and batch them into as few SQS requests as possible."""

def __init__(self, queue_url: str, objects_per_message: int) -> None:
Expand Down Expand Up @@ -142,7 +142,7 @@ def finalize(self) -> None:
self._send_batch()


class S3BucketEnumerator(object):
class S3BucketEnumerator:
"""Enumerates all of the S3 objects in a given bucket."""

def __init__(self, bucket_name: str, prefix: Optional[str],
Expand All @@ -164,7 +164,7 @@ def __init__(self, bucket_name: str, prefix: Optional[str],
self.finished = False # Have we finished enumerating all of the S3 bucket?

@property
def continuation_token(self) -> str:
def continuation_token(self) -> Optional[str]:
return self.kwargs.get('ContinuationToken')

def next_page(self) -> List[str]:
Expand Down
2 changes: 1 addition & 1 deletion lambda_functions/downloader/main.py
Expand Up @@ -107,7 +107,7 @@ def _process_md5(md5: str) -> bool:
binary = CARBON_BLACK.select(Binary, md5)
download_path = _download_from_carbon_black(binary)
metadata = _build_metadata(binary)
_upload_to_s3(binary.md5, download_path, metadata)
_upload_to_s3(binary.md5, download_path, metadata) # pylint: disable=no-member
return True
except (BotoCoreError, ObjectNotFoundError, ServerError, zipfile.BadZipFile):
LOGGER.exception('Error downloading %s', md5)
Expand Down
4 changes: 2 additions & 2 deletions manage.py
Expand Up @@ -65,7 +65,7 @@ def _get_input(prompt: str, default_value: str) -> str:
return input(prompt).strip().lower() or default_value


class BinaryAlertConfig(object):
class BinaryAlertConfig:
"""Wrapper around reading, validating, and updating the terraform.tfvars config file."""
# Expected configuration value formats.
VALID_AWS_ACCOUNT_ID_FORMAT = r'\d{12}'
Expand Down Expand Up @@ -349,7 +349,7 @@ def save(self) -> None:
config_file.write(raw_config)


class Manager(object):
class Manager:
"""BinaryAlert management utility."""

def __init__(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/common.py
@@ -1,7 +1,7 @@
"""Utilities common to several different unit tests."""


class MockLambdaContext(object):
class MockLambdaContext():
"""http://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html"""
def __init__(self, function_version: int = 1, time_limit_ms: int = 30000,
decrement_ms: int = 10000) -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/lambda_functions/analyzer/main_test.py
Expand Up @@ -31,7 +31,7 @@
TEST_CONTEXT = common.MockLambdaContext(LAMBDA_VERSION)


class MockS3Object(object):
class MockS3Object:
"""Simple mock for boto3.resource('s3').Object"""
def __init__(self, bucket_name, object_key):
self.name = bucket_name
Expand Down
2 changes: 1 addition & 1 deletion tests/lambda_functions/analyzer/yara_mocks.py
Expand Up @@ -27,7 +27,7 @@
"""


class YaraRulesMock(object):
class YaraRulesMock:
"""A wrapper around Yara.Rules which redirects .match() to open files with Python's open()."""

def __init__(self, yara_rules_object):
Expand Down
2 changes: 1 addition & 1 deletion tests/lambda_functions/batcher/main_test.py
Expand Up @@ -207,7 +207,7 @@ def mock_list(**kwargs):

def test_batcher_re_invoke(self):
"""If the batcher runs out of time, it has to re-invoke itself."""
class MockEnumerator(object):
class MockEnumerator:
"""Simple mock for S3BucketEnumerator which never finishes."""
def __init__(self, *args): # pylint: disable=unused-argument
self.continuation_token = 'test-continuation-token'
Expand Down
4 changes: 3 additions & 1 deletion tests/lambda_functions/build_test.py
Expand Up @@ -56,6 +56,7 @@ def test_build_analyzer(self, mock_print: mock.MagicMock):
'compiled_yara_rules.bin',

# Natively compiled binaries
'cryptography/',
'libarchive.so.13',
'libs/',
'libs/bayshore_file_type_detect.o',
Expand Down Expand Up @@ -89,7 +90,8 @@ def test_build_analyzer(self, mock_print: mock.MagicMock):
'YARA_LICENSE',
'YARA_PYTHON_LICENSE',
'YEXTEND_LICENSE'
}
},
subset=True
)
mock_print.assert_called_once()

Expand Down
4 changes: 2 additions & 2 deletions tests/lambda_functions/downloader/main_test.py
Expand Up @@ -10,10 +10,10 @@
from pyfakefs import fake_filesystem_unittest


class MockBinary(object):
class MockBinary:
"""Mock for cbapi.response.models.Binary."""

class MockVirusTotal(object):
class MockVirusTotal:
"""Mock for cbapi.response.models.VirusTotal."""

def __init__(self, score: int = 0) -> None:
Expand Down
12 changes: 6 additions & 6 deletions tests/manage_test.py
Expand Up @@ -19,17 +19,17 @@ def _mock_input(prompt: str) -> str:
# pylint: disable=too-many-return-statements
if prompt.startswith('AWS Account'):
return '111122223333'
elif prompt.startswith('AWS Region'):
if prompt.startswith('AWS Region'):
return 'us-west-2'
elif prompt.startswith('Unique name prefix'):
if prompt.startswith('Unique name prefix'):
return ' NEW_NAME_PREFIX ' # Spaces and case shouldn't matter.
elif prompt.startswith('Enable the CarbonBlack downloader'):
if prompt.startswith('Enable the CarbonBlack downloader'):
return 'yes'
elif prompt.startswith('CarbonBlack URL'):
if prompt.startswith('CarbonBlack URL'):
return 'https://new-example.com'
elif prompt.startswith('Change the CarbonBlack API token'):
if prompt.startswith('Change the CarbonBlack API token'):
return 'yes'
elif prompt.startswith('Delete all S3 objects'):
if prompt.startswith('Delete all S3 objects'):
return 'yes'
return 'UNKNOWN'

Expand Down

0 comments on commit a2c9dda

Please sign in to comment.