Skip to content

[client] report work expectation without impersonation (#10829) #890

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions pycti/utils/opencti_stix2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2500,6 +2500,11 @@ def import_item(
if processing_count > MAX_PROCESSING_COUNT:
if work_id is not None:
item_str = json.dumps(item)
# report expectation without impersonated user
current_applicant_id = self.opencti.get_request_headers()[
"opencti-applicant-id"
]
self.opencti.set_applicant_id_header("")
self.opencti.work.report_expectation(
work_id,
{
Expand All @@ -2509,6 +2514,7 @@ def import_item(
),
},
)
self.opencti.set_applicant_id_header(current_applicant_id)
return False
try:
self.opencti.set_retry_number(processing_count)
Expand Down Expand Up @@ -2645,7 +2651,13 @@ def import_item(
):
self.import_object(item, update, types)
if work_id is not None:
# report expectation without impersonated user
current_applicant_id = self.opencti.get_request_headers()[
"opencti-applicant-id"
]
self.opencti.set_applicant_id_header("")
self.opencti.work.report_expectation(work_id, None)
self.opencti.set_applicant_id_header(current_applicant_id)
bundles_success_counter.add(1)
return True
except (RequestException, Timeout):
Expand Down Expand Up @@ -2702,20 +2714,31 @@ def import_item(
bundles_technical_error_counter.add(1)
if work_id is not None:
self.opencti.work.api.set_draft_id("")
# report expectation without impersonated user
current_applicant_id = self.opencti.get_request_headers()[
"opencti-applicant-id"
]
self.opencti.set_applicant_id_header("")
self.opencti.work.report_expectation(
work_id,
{
"error": error,
"source": "Draft in read only",
},
)
self.opencti.set_applicant_id_header(current_applicant_id)
return False
# Platform does not know what to do and raises an error:
# That also works for missing reference with too much execution
else:
bundles_technical_error_counter.add(1)
if work_id is not None:
item_str = json.dumps(item)
# report expectation without impersonated user
current_applicant_id = self.opencti.get_request_headers()[
"opencti-applicant-id"
]
self.opencti.set_applicant_id_header("")
self.opencti.work.report_expectation(
work_id,
{
Expand All @@ -2727,6 +2750,7 @@ def import_item(
),
},
)
self.opencti.set_applicant_id_header(current_applicant_id)
return False

def import_bundle(
Expand Down