-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from CybercentreCanada/feature/new_apis
Feature/new apis
- Loading branch information
Showing
22 changed files
with
473 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from json import dumps | ||
|
||
from assemblyline_client.v4_client.common.utils import api_path | ||
|
||
|
||
class Safelist(object): | ||
def __init__(self, connection): | ||
self._connection = connection | ||
|
||
def __call__(self, qhash): | ||
"""\ | ||
Check if a hash exists in the safelist | ||
Required: | ||
qhash : Hash to check in the safelist (string) | ||
""" | ||
return self._connection.get(api_path('safelist', qhash)) | ||
|
||
def add_update(self, safelist_object): | ||
"""\ | ||
Add a hash in the safelist if it does not exist or update its list of sources if it does | ||
Required: | ||
safelist_object : A dictionary containing the safelist details | ||
Throws a Client exception if the safelist object is invalid. | ||
""" | ||
return self._connection.put(api_path('safelist'), data=dumps(safelist_object)) | ||
|
||
def delete(self, safelist_id): | ||
"""\ | ||
Delete the safelist object using it's ID. | ||
The safelist ID is one of the following: | ||
- One of the hash of the file in order of importance (SHA256 -> SHA1 -> MD5) | ||
- SHA256 hash of the tag type and value concatenated | ||
Required: | ||
safelist_id : ID of the safelist object (string) | ||
Throws a Client exception if the safelist does not exist. | ||
""" | ||
return self._connection.delete(api_path('safelist', safelist_id)) | ||
|
||
def set_enabled(self, safelist_id, enabled): | ||
"""\ | ||
Set the enabled status of a safelist object using it's ID. | ||
The safelist ID is one of the following: | ||
- One of the hash of the file in order of importance (SHA256 -> SHA1 -> MD5) | ||
- SHA256 hash of the tag type and value concatenated | ||
Required: | ||
safelist_id : ID of the safelist object (string) | ||
enabled : True/False value (boolean) | ||
Throws a Client exception if the safelist does not exist. | ||
""" | ||
return self._connection.put(api_path('safelist', 'enable', safelist_id), data=dumps(enabled)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.