diff --git a/pymisp/api.py b/pymisp/api.py index e17e464..ff21fa9 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -815,9 +815,12 @@ class PyMISP(object): def _encode_file_to_upload(self, filepath_or_bytes): """Helper to encode a file to upload""" - if isinstance(filepath_or_bytes, basestring) and os.path.isfile(filepath_or_bytes): - with open(filepath_or_bytes, 'rb') as f: - binblob = f.read() + if isinstance(filepath_or_bytes, basestring): + if os.path.isfile(filepath_or_bytes): + with open(filepath_or_bytes, 'rb') as f: + binblob = f.read() + else: + binblob = filepath_or_bytes.encode() else: binblob = filepath_or_bytes return base64.b64encode(binblob).decode() @@ -1583,6 +1586,18 @@ class PyMISP(object): response = self.__prepare_request('GET', url) return self._check_response(response) + # ############## Galaxies/Clusters ################## + + def get_galaxies(self): + url = urljoin(self.root_url, '/galaxies') + response = self.__prepare_request('GET', url) + return self._check_response(response) + + def get_galaxy(self, galaxy_id): + url = urljoin(self.root_url, '/galaxies/view/{}'.format(galaxy_id)) + response = self.__prepare_request('GET', url) + return self._check_response(response) + # ############################################## # ############### Non-JSON output ############## # ############################################## diff --git a/tests/test_offline.py b/tests/test_offline.py index 53f0be8..1a1fd75 100644 --- a/tests/test_offline.py +++ b/tests/test_offline.py @@ -444,11 +444,11 @@ class TestOffline(unittest.TestCase): self.assertEqual((False, None), pymisp.download_samples()) def test_sample_upload(self, m): - if (3, 0) < sys.version_info < (3, 5): - return unittest.SkipTest() self.initURI(m) pymisp = PyMISP(self.domain, self.key) upload = pymisp.upload_sample("tmux", "tests/viper-test-files/test_files/tmux", 1) + upload = pymisp.upload_sample("tmux", "non_existing_file", 1) + upload = pymisp.upload_sample("tmux", b"binblob", 1) def test_get_all_tags(self, m): self.initURI(m)