Allow key-based access along with attribute access
parent
31cebdd34a
commit
eeec5a4ce3
|
@ -19,7 +19,7 @@ def format_datetime(dt):
|
||||||
# - modified
|
# - modified
|
||||||
|
|
||||||
|
|
||||||
class Indicator:
|
class Indicator(object):
|
||||||
# REQUIRED (Indicator):
|
# REQUIRED (Indicator):
|
||||||
# - type
|
# - type
|
||||||
# - labels
|
# - labels
|
||||||
|
@ -27,6 +27,9 @@ class Indicator:
|
||||||
# - valid_from
|
# - valid_from
|
||||||
required = ['']
|
required = ['']
|
||||||
|
|
||||||
|
def __getitem__(self, key):
|
||||||
|
return getattr(self, key)
|
||||||
|
|
||||||
def __init__(self, type='indicator', id=None, created=None, modified=None,
|
def __init__(self, type='indicator', id=None, created=None, modified=None,
|
||||||
labels=None, pattern=None, valid_from=None):
|
labels=None, pattern=None, valid_from=None):
|
||||||
now = datetime.now(tz=pytz.UTC)
|
now = datetime.now(tz=pytz.UTC)
|
||||||
|
|
|
@ -68,6 +68,14 @@ def test_indicator_autogenerated_fields():
|
||||||
assert indicator.pattern == "[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']"
|
assert indicator.pattern == "[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']"
|
||||||
assert indicator.valid_from is not None
|
assert indicator.valid_from is not None
|
||||||
|
|
||||||
|
assert indicator['type'] == 'indicator'
|
||||||
|
assert indicator['id'].startswith('indicator--')
|
||||||
|
assert indicator['created'] is not None
|
||||||
|
assert indicator['modified'] is not None
|
||||||
|
assert indicator['labels'] == ['malicious-activity']
|
||||||
|
assert indicator['pattern'] == "[file:hashes.MD5 = 'd41d8cd98f00b204e9800998ecf8427e']"
|
||||||
|
assert indicator['valid_from'] is not None
|
||||||
|
|
||||||
|
|
||||||
def test_indicator_type_must_be_indicator():
|
def test_indicator_type_must_be_indicator():
|
||||||
with pytest.raises(ValueError) as excinfo:
|
with pytest.raises(ValueError) as excinfo:
|
||||||
|
|
Loading…
Reference in New Issue