Skip to content

GIS-8085 Improve StrictPlatformException and mapping #158

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

Merged
merged 7 commits into from
Jun 25, 2024
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
16 changes: 14 additions & 2 deletions uncoder-core/app/translator/core/exceptions/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import Optional


class NotImplementedException(BaseException):
...

Expand All @@ -7,8 +10,17 @@ class BasePlatformException(BaseException):


class StrictPlatformException(BasePlatformException):
def __init__(self, platform_name: str, field_name: str):
message = f"Platform {platform_name} has strict mapping. Source field {field_name} has no mapping."
field_name: str = None

def __init__(
self, platform_name: str, field_name: str, mapping: str = None, detected_fields: Optional[list] = None
):
message = (
f"Platform {platform_name} has strict mapping. "
f"Source fields: {', '.join(detected_fields) if detected_fields else field_name} has no mapping."
f" Mapping file: {mapping}." if mapping else ""
)
self.field_name = field_name
super().__init__(message)


Expand Down
10 changes: 9 additions & 1 deletion uncoder-core/app/translator/core/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,16 @@ def apply_token(self, token: Union[FieldValue, Keyword, Identifier], source_mapp

def generate_query(self, tokens: list[TOKEN_TYPE], source_mapping: SourceMapping) -> str:
result_values = []
not_found_mapping_fields = set()
for token in tokens:
result_values.append(self.apply_token(token=token, source_mapping=source_mapping))
try:
result_values.append(self.apply_token(token=token, source_mapping=source_mapping))
except StrictPlatformException as err:
not_found_mapping_fields.add(err.field_name)
if not_found_mapping_fields:
raise StrictPlatformException(
self.details.name, "", source_mapping.source_id, sorted(list(not_found_mapping_fields))
)
return "".join(result_values)

def wrap_query_with_meta_info(self, meta_info: MetaInfoContainer, query: str) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ field_mapping:
SourceOS: xdm.source.host.os
DestinationOS: xdm.target.host.os
url_category: xdm.network.http.url_category
EventSeverity: xdm.alert.severity
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ field_mapping:
dst-port:
- DstPort
- DestinationPort
- remoteport
dst-hostname: DstHost
src-hostname: SrcHost
src-port: SourcePort
src-port:
- SourcePort
- localport
src-ip:
- sourceip
- source_ip
Expand All @@ -27,6 +30,7 @@ field_mapping:
- destination_ip
- destinationIP
- destinationaddress
- destination
User:
- userName
- EventUserName
Expand Down Expand Up @@ -64,4 +68,5 @@ field_mapping:
DestinationOS: DestinationOS
TargetUserName: DestinationUserName
SourceUserName: SourceUserName
url_category: XForceCategoryByURL
url_category: XForceCategoryByURL
EventSeverity: EventSeverity
Loading