Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post data update (dev) #804

Merged
merged 3 commits into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions assemblyline_v4_service/updater/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ def __init__(self, datastore, config=None):
self.classification_override = None

def add_update_many(self, data: List[Union[dict, BadlistModel]]) -> Dict[str, Any]:
return hashlist_add_update_many(self, self.datastore.badlist, data)
response = hashlist_add_update_many(self, self.datastore.badlist, data)

# Ensure new data is available to query
self.datastore.badlist.commit()

return response

class SyncableSafelistClient(SafelistClient):
def __init__(self, datastore, config=None):
Expand All @@ -30,7 +34,12 @@ def __init__(self, datastore, config=None):
self.classification_override = None

def add_update_many(self, data: List[Union[dict, SafelistModel]]) -> Dict[str, Any]:
return hashlist_add_update_many(self, self.datastore.safelist, data)
response = hashlist_add_update_many(self, self.datastore.safelist, data)

# Ensure new data is available to query
self.datastore.safelist.commit()

return response


def hashlist_add_update_many(client: Union[SyncableBadlistClient, SyncableSafelistClient],
Expand Down Expand Up @@ -187,10 +196,11 @@ def add_update_many(self, source: str, sig_type: str, data: List[Union[dict, Sig
[(self.datastore.signature.UPDATE_SET, 'status', 'DISABLED'),
(self.datastore.signature.UPDATE_SET, 'last_modified', 'NOW')])

response = None
# Proceed with adding/updating signatures
if len(data) < SIGNATURE_UPDATE_BATCH:
# Update all of them in a single batch
return super().add_update_many(source, sig_type, data, dedup_name)
response = super().add_update_many(source, sig_type, data, dedup_name)
else:
response = {
'success': 0,
Expand All @@ -213,7 +223,10 @@ def update_response(r: Dict[str, Any]):
batch_num += 1
start = batch_num * SIGNATURE_UPDATE_BATCH

return response
# Ensure new data is available to query
self.datastore.signature.commit()

return response


class UpdaterClient(object):
Expand Down
4 changes: 2 additions & 2 deletions assemblyline_v4_service/updater/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def url_download(source: Dict[str, Any], previous_update: int, logger: Logger, o
if fetch_method == 'get':
response = session.get(uri, auth=auth, headers=headers, proxies=proxies, stream=True)
elif fetch_method == 'post':
json = source.get('post_data') or None
response = session.post(uri, auth=auth, headers=headers, proxies=proxies, json=json, stream=True)
data = source.get('post_data') or None
response = session.post(uri, auth=auth, headers=headers, proxies=proxies, data=data, stream=True)
else:
raise ValueError(f"Unknown fetch method: {fetch_method}")

Expand Down