-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (38 loc) · 1.39 KB
/
main.py
File metadata and controls
51 lines (38 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""Main module for the host-details function handler."""
from crowdstrike.foundry.function import Function, Request, Response, APIError
# Import service collection you'd like to use
from falconpy import Hosts
FUNC = Function.instance()
@FUNC.handler(method="POST", path="/host-details")
def on_post(request: Request) -> Response:
"""
Handle POST requests to /host-details endpoint.
Args:
request: The incoming request object containing the request body.
Returns:
Response: JSON response with host details or error message.
"""
# Validate request
if "host_id" not in request.body:
return Response(
code=400,
errors=[APIError(code=400, message="missing host_id from request body")]
)
host_id = request.body["host_id"]
# Initialize the Hosts class with context-aware authentication
falcon = Hosts()
# Query device details
response = falcon.get_device_details(ids=host_id)
if response["status_code"] != 200:
return Response(
code=response["status_code"],
errors=[APIError(code=response["status_code"],
message=f"Error retrieving host: {response['body']}")],
)
# Return host information
return Response(
body={"host_details": response["body"]["resources"][0]},
code=200,
)
if __name__ == "__main__":
FUNC.run()