-
Notifications
You must be signed in to change notification settings - Fork 82
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
refactor(RHINENG-12780): Enhance delete events #2111
base: master
Are you sure you want to change the base?
Changes from 2 commits
a833749
0d4b216
916bc88
75a8ba7
0aa2f40
5b76d1a
3461d39
e20daa8
bf0a15e
f4303e4
350baad
67278c6
02cbb2d
b4ac638
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -243,6 +243,7 @@ def delete_hosts_by_filter( | |||||
|
||||||
|
||||||
def _delete_host_list(host_id_list, rbac_filter): | ||||||
request_host = flask.request.headers.get("Host", "") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This may be renamed to another thing? My understand is that this value would be the consoleDOT URL?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jpramos123 I think it's just the hostname of the request, so maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kruai Yup, makes sense |
||||||
current_identity = get_current_identity() | ||||||
payload_tracker = get_payload_tracker( | ||||||
account=current_identity.account_number, org_id=current_identity.org_id, request_id=threadctx.request_id | ||||||
|
@@ -260,6 +261,7 @@ def _delete_host_list(host_id_list, rbac_filter): | |||||
inventory_config().host_delete_chunk_size, | ||||||
identity=current_identity, | ||||||
control_rule=get_control_rule(), | ||||||
is_manual_delete=check_manual_deletion(request_host), | ||||||
) | ||||||
|
||||||
deleted_id_list = [str(r.host_row.id) for r in result_list] | ||||||
|
@@ -312,6 +314,10 @@ def delete_host_by_id(host_id_list, rbac_filter=None): | |||||
return flask.Response(None, HTTPStatus.OK) | ||||||
|
||||||
|
||||||
def check_manual_deletion(origin_host: str = ""): | ||||||
return origin_host in ["console.stage.redhat.com", "console.redhat.com"] | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggest using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this check enough to tell that the request is specifically from the UI? It looks to me like this header gets set to the target hostname for all HTTP requests |
||||||
|
||||||
|
||||||
@api_operation | ||||||
@rbac(RbacResourceType.HOSTS, RbacPermission.READ) | ||||||
@metrics.api_request_time.time() | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,6 +76,8 @@ class HostDeleteEvent(Schema): | |
org_id = fields.Str() | ||
insights_id = fields.Str() | ||
request_id = fields.Str() | ||
subscription_manager_id = fields.Str() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should start using |
||
manual_delete = fields.Bool() | ||
platform_metadata = fields.Dict() | ||
metadata = fields.Nested(HostEventMetadataSchema()) | ||
|
||
|
@@ -113,14 +115,15 @@ def host_create_update_event(event_type, host, platform_metadata=None): | |
) | ||
|
||
|
||
def host_delete_event(event_type, host, platform_metadata=None): | ||
def host_delete_event(event_type, host, is_manual_delete=False, platform_metadata=None): | ||
delete_event = { | ||
"timestamp": datetime.now(timezone.utc), | ||
"type": event_type.name, | ||
"id": host.id, | ||
**serialize_canonical_facts(host.canonical_facts), | ||
"org_id": host.org_id, | ||
"account": host.account, | ||
"manual_delete": is_manual_delete, | ||
"request_id": threadctx.request_id, | ||
"platform_metadata": platform_metadata, | ||
"metadata": {"request_id": threadctx.request_id}, | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -104,7 +104,13 @@ def assert_mq_host_data(actual_id, actual_event, expected_results, host_keys_to_ | |||||
|
||||||
|
||||||
def assert_delete_event_is_valid( | ||||||
event_producer, host, timestamp, expected_request_id=None, expected_metadata=None, identity=USER_IDENTITY | ||||||
event_producer, | ||||||
host, | ||||||
timestamp, | ||||||
expected_request_id=None, | ||||||
expected_metadata=None, | ||||||
identity=USER_IDENTITY, | ||||||
is_manual_delete=False, | ||||||
): | ||||||
event = json.loads(event_producer.event) | ||||||
|
||||||
|
@@ -118,6 +124,8 @@ def assert_delete_event_is_valid( | |||||
"org_id", | ||||||
"insights_id", | ||||||
"request_id", | ||||||
"subscription_manager_id", | ||||||
"manual_delete", | ||||||
"platform_metadata", | ||||||
"metadata", | ||||||
} | ||||||
|
@@ -129,6 +137,11 @@ def assert_delete_event_is_valid( | |||||
|
||||||
assert host.canonical_facts.get("insights_id") == event["insights_id"] | ||||||
|
||||||
assert event["manual_delete"] == is_manual_delete | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
if is_manual_delete: | ||||||
assert event["subscription_manager_id"] is not None | ||||||
|
||||||
assert event_producer.key == str(host.id) | ||||||
assert event_producer.headers == expected_headers( | ||||||
"delete", | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the request_host value, if I make a REST API call from my laptop?
Also suggest using
requesting_host
to leave out any ambiguity.