Skip to content

Commit f9d641c

Browse files
authored
Update to use crowdstrike-foundry-function 1.1.1 (#3)
1 parent d9a6a7a commit f9d641c

File tree

15 files changed

+58
-58
lines changed

15 files changed

+58
-58
lines changed

functions/hello/main.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from falconfoundry import FoundryFunction, FoundryRequest, FoundryResponse, FoundryAPIError
1+
from crowdstrike.foundry.function import Function, Request, Response, APIError
22

33

4-
func = FoundryFunction.instance()
4+
func = Function.instance()
55

66

77
# Handler hello
88
@func.handler(method='POST', path='/hello')
9-
def on_post(request: FoundryRequest) -> FoundryResponse:
9+
def on_post(request: Request) -> Response:
1010

1111
#
1212
# Replace the following example code with your handler code
@@ -17,14 +17,14 @@ def on_post(request: FoundryRequest) -> FoundryResponse:
1717
if 'name' not in request.body:
1818
# This example expects 'name' field in the request body and returns
1919
# an error response (400 - Bad Request) if not provided by the caller
20-
return FoundryResponse(
20+
return Response(
2121
code=400,
22-
errors=[FoundryAPIError(code=400, message='missing name from request body')]
22+
errors=[APIError(code=400, message='missing name from request body')]
2323
)
2424

2525
# Demonstrates how to return a success response with JSON body
2626
# Replace with your response and update the response_schema.json to match
27-
return FoundryResponse(
27+
return Response(
2828
body={'greeting': f'Hello {request.body["name"]}! It is nice to see you.'},
2929
code=200,
3030
)

functions/hello/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
crowdstrike-falcon-foundry==1.0.0
1+
crowdstrike-foundry-function==1.1.1

functions/hello/test_main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
from unittest.mock import patch
33

4-
from falconfoundry import FoundryRequest
4+
from crowdstrike.foundry.function import Request
55

66
def mock_handler(*args, **kwargs):
77
def identity(func):
@@ -10,7 +10,7 @@ def identity(func):
1010

1111
class FnTestCase(unittest.TestCase):
1212
def setUp(self):
13-
patcher = patch('falconfoundry.FoundryFunction.handler', new=mock_handler)
13+
patcher = patch('crowdstrike.foundry.function.Function.handler', new=mock_handler)
1414
self.addCleanup(patcher.stop)
1515
self.handler_patch = patcher.start()
1616

@@ -20,7 +20,7 @@ def setUp(self):
2020

2121
def test_on_post_success(self):
2222
from main import on_post
23-
request = FoundryRequest()
23+
request = Request()
2424
request.body = {
2525
"name": "Test User"
2626
}
@@ -31,7 +31,7 @@ def test_on_post_success(self):
3131

3232
def test_on_post_missing_name(self):
3333
from main import on_post
34-
request = FoundryRequest()
34+
request = Request()
3535

3636
response = on_post(request)
3737
self.assertEqual(response.code, 400)

functions/host-details/main.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
from falconfoundry import FoundryFunction, FoundryRequest, FoundryResponse, FoundryAPIError
1+
from crowdstrike.foundry.function import Function, Request, Response, APIError
22
# Import service collection you'd like to use
33
from falconpy import Hosts
44

55

6-
func = FoundryFunction.instance()
6+
func = Function.instance()
77

88

99
@func.handler(method='POST', path='/host-details')
10-
def on_post(request: FoundryRequest) -> FoundryResponse:
10+
def on_post(request: Request) -> Response:
1111
# Validate request
1212
if 'host_id' not in request.body:
13-
return FoundryResponse(
13+
return Response(
1414
code=400,
15-
errors=[FoundryAPIError(code=400, message='missing host_id from request body')]
15+
errors=[APIError(code=400, message='missing host_id from request body')]
1616
)
1717

1818
host_id = request.body['host_id']
@@ -24,14 +24,14 @@ def on_post(request: FoundryRequest) -> FoundryResponse:
2424
response = falcon.get_device_details(ids=host_id)
2525

2626
if response["status_code"] != 200:
27-
return FoundryResponse(
27+
return Response(
2828
code=response["status_code"],
29-
errors=[FoundryAPIError(code=response["status_code"],
29+
errors=[APIError(code=response["status_code"],
3030
message=f"Error retrieving host: {response['body']}")],
3131
)
3232

3333
# Return host information
34-
return FoundryResponse(
34+
return Response(
3535
body={"host_details": response["body"]["resources"][0]},
3636
code=200,
3737
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
crowdstrike-falcon-foundry==1.0.0
1+
crowdstrike-foundry-function==1.1.1
22
crowdstrike-falconpy

functions/host-info/main.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
from falconfoundry import FoundryFunction, FoundryRequest, FoundryResponse, FoundryAPIError
1+
from crowdstrike.foundry.function import Function, Request, Response, APIError
22
from utils import validate_host_id, format_error_response
33
from logging import Logger
44
from typing import Dict
55

66

7-
func = FoundryFunction.instance()
7+
func = Function.instance()
88

99
# Handler on_post
1010
@func.handler(method='POST', path='/host-info')
11-
def on_post(request: FoundryRequest, config: Dict[str, object] | None, logger: Logger) -> FoundryResponse:
11+
def on_post(request: Request, config: Dict[str, object] | None, logger: Logger) -> Response:
1212
host_id = request.body.get('host_id')
1313

1414
logger.info(f"Host ID: {host_id}")
1515
logger.info(f"Is valid? {validate_host_id(host_id)}")
1616

1717
if not validate_host_id(host_id):
18-
return FoundryResponse(errors=format_error_response("Invalid host ID format"))
18+
return Response(errors=format_error_response("Invalid host ID format"))
1919

20-
return FoundryResponse(
20+
return Response(
2121
code=200,
2222
body={
2323
"host":host_id
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
crowdstrike-falcon-foundry==1.0.0
1+
crowdstrike-foundry-function==1.1.1

functions/host-info/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22
import json
33
from typing import Dict, Any, Optional, Union, List
4-
from falconfoundry import FoundryAPIError
4+
from crowdstrike.foundry.function import APIError
55

66
def validate_host_id(host_id: str) -> bool:
77
"""Validate that a host ID is in the correct format."""
@@ -16,7 +16,7 @@ def validate_email(email: str) -> bool:
1616

1717
def format_error_response(message: str, code: int = 400) -> list[Any]:
1818
"""Create a standardized error response."""
19-
return [FoundryAPIError(code=code, message=message)]
19+
return [APIError(code=code, message=message)]
2020

2121
def safe_json_parse(data: str) -> Optional[Dict[str, Any]]:
2222
"""Safely parse JSON data."""

functions/log-event/main.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
from falconfoundry import FoundryFunction, FoundryRequest, FoundryResponse, FoundryAPIError
1+
from crowdstrike.foundry.function import Function, Request, Response, APIError
22
from falconpy import APIHarnessV2
33
import time
44
import os
55
import uuid
66

7-
func = FoundryFunction.instance()
7+
func = Function.instance()
88

99

1010
@func.handler(method='POST', path='/log-event')
11-
def on_post(request: FoundryRequest) -> FoundryResponse:
11+
def on_post(request: Request) -> Response:
1212
# Validate request
1313
if 'event_data' not in request.body:
14-
return FoundryResponse(
14+
return Response(
1515
code=400,
16-
errors=[FoundryAPIError(code=400, message='missing event_data')]
16+
errors=[APIError(code=400, message='missing event_data')]
1717
)
1818

1919
event_data = request.body['event_data']
@@ -47,9 +47,9 @@ def on_post(request: FoundryRequest) -> FoundryResponse:
4747

4848
if response["status_code"] != 200:
4949
error_message = response.get('error', {}).get('message', 'Unknown error')
50-
return FoundryResponse(
50+
return Response(
5151
code=response["status_code"],
52-
errors=[FoundryAPIError(
52+
errors=[APIError(
5353
code=response["status_code"],
5454
message=f"Failed to store event: {error_message}"
5555
)]
@@ -63,17 +63,17 @@ def on_post(request: FoundryRequest) -> FoundryResponse:
6363
headers=headers
6464
)
6565

66-
return FoundryResponse(
66+
return Response(
6767
body={
6868
"stored": True,
6969
"metadata": query_response.get("body").get("resources", [])
7070
},
7171
code=200
7272
)
7373
except Exception as e:
74-
return FoundryResponse(
74+
return Response(
7575
code=500,
76-
errors=[FoundryAPIError(code=500, message=f"Error saving collection: {str(e)}")]
76+
errors=[APIError(code=500, message=f"Error saving collection: {str(e)}")]
7777
)
7878

7979

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
crowdstrike-falcon-foundry==1.0.0
1+
crowdstrike-foundry-function==1.1.1
22
crowdstrike-falconpy

0 commit comments

Comments
 (0)