Skip to content

Commit

Permalink
Merge pull request #83 from intezer/feat/add-family-tags-to-family-info
Browse files Browse the repository at this point in the history
feat/add-family-tags-to-family-info
  • Loading branch information
matany90 authored Mar 5, 2023
2 parents 3f6057a + 860fe7c commit ce46142
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.16.2
____
- Family info returns also tags related to family

1.16.1
____
- Fix equals to check by reference as well
Expand Down
19 changes: 19 additions & 0 deletions examples/family_by_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sys
from pprint import pprint

from intezer_sdk import api
from intezer_sdk.family import Family


def fetch_family_by_family_id(family_id: str):
api.set_global_api('<api_key>')
family = Family.from_family_id(family_id=family_id)
family.fetch_info()

pprint(family.name)
pprint(family.type)
pprint(family.tags)


if __name__ == '__main__':
fetch_family_by_family_id(*sys.argv[1:])
2 changes: 1 addition & 1 deletion intezer_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.16.1'
__version__ = '1.16.2'
22 changes: 21 additions & 1 deletion intezer_sdk/family.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import typing

from typing import Optional
from typing import List

from intezer_sdk import errors
from intezer_sdk._api import IntezerApi
from intezer_sdk.api import IntezerApiClient
from intezer_sdk.api import get_global_api


class Family:
def __init__(self, family_id: str, name: str = None, family_type: str = None, *, api: IntezerApiClient = None):
def __init__(self,
family_id: str,
name: str = None,
family_type: str = None,
*,
api: IntezerApiClient = None):
self.family_id = family_id
self._name = name
self._type = family_type
self._tags = None
self._api = IntezerApi(api or get_global_api())

def __eq__(self, other):
Expand All @@ -33,6 +42,10 @@ def fetch_info(self):
self._name = info['family_name']
self._type = info['family_type']

family_tags = info.get('family_tags')
if family_tags:
self._tags = family_tags

@property
def name(self) -> str:
if not self._name:
Expand All @@ -47,6 +60,13 @@ def type(self) -> str:

return self._type

@property
def tags(self) -> Optional[List[str]]:
if not self._tags:
self.fetch_info()

return self._tags


def get_family_by_name(family_name: str, api: IntezerApiClient = None) -> typing.Optional[Family]:
family = IntezerApi(api or get_global_api()).get_family_by_name(family_name)
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_family.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ def test_from_family_id_returns_family(self):
# Arrange
family_id = str(uuid.uuid4())
family_name = 'Burla'
family_tags = ['my_tag_1', 'my_tag_2']

with responses.RequestsMock() as mock:
family_type = 'malware'
mock.add('GET',
f'{self.full_url}/families/{family_id}/info',
json={'result': {'family_id': family_id,
'family_name': family_name,
'family_tags': family_tags,
'family_type': family_type}})
# Act
family = Family.from_family_id(family_id)
Expand All @@ -49,18 +51,21 @@ def test_from_family_id_returns_family(self):
self.assertEqual(family_id, family.family_id)
self.assertEqual(family_name, family.name)
self.assertEqual(family_type, family.type)
self.assertListEqual(family_tags, family.tags)

def test_compare_family(self):
# Arrange
family_id = str(uuid.uuid4())
family_name = 'Burla'
family_tags = ['my_tag_1', 'my_tag_2']

with responses.RequestsMock() as mock:
family_type = 'malware'
mock.add('GET',
f'{self.full_url}/families/{family_id}/info',
json={'result': {'family_id': family_id,
'family_name': family_name,
'family_tags': family_tags,
'family_type': family_type}})
# Act
family1 = Family.from_family_id(family_id)
Expand Down

0 comments on commit ce46142

Please sign in to comment.