Skip to content

Commit 3d8d6ae

Browse files
authored
fix: use list users as healthcheck (#510)
* fix: use list users as healthcheck * fix: lint
1 parent 918de54 commit 3d8d6ae

File tree

6 files changed

+40
-33
lines changed

6 files changed

+40
-33
lines changed

app/integrations/aws/client.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,3 @@ def paginator(client, operation, keys=None, **kwargs):
135135
results.extend(page[key])
136136

137137
return results
138-
139-
140-
def healthcheck():
141-
"""Check the health of the AWS integration.
142-
143-
Returns:
144-
bool: True if the integration is healthy, False otherwise.
145-
"""
146-
return execute_aws_api_call("sts", "get_caller_identity") is not False

app/integrations/aws/identity_store.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ def resolve_identity_store_id(kwargs):
2424
return kwargs
2525

2626

27+
def healthcheck():
28+
"""Check the health of the AWS integration.
29+
30+
Returns:
31+
bool: True if the integration is healthy, False otherwise.
32+
"""
33+
healthy = False
34+
try:
35+
response = list_users()
36+
healthy = True if response else False
37+
logger.info(f"AWS IdentityStore healthcheck result: {response}")
38+
except Exception as error:
39+
logger.error(f"AWS IdentityStore healthcheck failed: {error}")
40+
return healthy
41+
42+
2743
@handle_aws_api_errors
2844
def create_user(email, first_name, family_name, **kwargs):
2945
"""Creates a new user in the AWS Identity Center (identitystore)

app/jobs/scheduled_tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from integrations import google_drive, maxmind, opsgenie
99

10-
from integrations.aws import client as aws_client
10+
from integrations.aws import identity_store
1111
from modules.aws import identity_center
1212

1313
logging.basicConfig(level=logging.INFO)
@@ -36,7 +36,7 @@ def integration_healthchecks():
3636
"google_drive": google_drive.healthcheck,
3737
"maxmind": maxmind.healthcheck,
3838
"opsgenie": opsgenie.healthcheck,
39-
"aws": aws_client.healthcheck,
39+
"aws": identity_store.healthcheck,
4040
}
4141
for key, healthcheck in healthchecks.items():
4242
if not healthcheck():

app/tests/integrations/aws/test_client.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -312,23 +312,3 @@ def test_execute_aws_api_call_raises_exception_when_role_arn_not_provided(
312312
)
313313
mock_assume_role.assert_not_called()
314314
mock_convert_kwargs_to_pascal_case.assert_not_called()
315-
316-
317-
@patch("integrations.aws.client.execute_aws_api_call")
318-
def test_healtcheck_is_healthy(mock_execute_aws_api_call):
319-
mock_execute_aws_api_call.return_value = {"key": "value"}
320-
321-
result = aws_client.healthcheck()
322-
323-
assert result is True
324-
mock_execute_aws_api_call.assert_called_once_with("sts", "get_caller_identity")
325-
326-
327-
@patch("integrations.aws.client.execute_aws_api_call")
328-
def test_healtcheck_is_unhealthy(mock_execute_aws_api_call):
329-
mock_execute_aws_api_call.return_value = False
330-
331-
result = aws_client.healthcheck()
332-
333-
assert result is False
334-
mock_execute_aws_api_call.assert_called_once_with("sts", "get_caller_identity")

app/tests/integrations/aws/test_identity_store.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ def test_resolve_identity_store_id_no_env():
5555
identity_store.resolve_identity_store_id({})
5656

5757

58+
@patch("integrations.aws.identity_store.list_users")
59+
def test_healtcheck_is_healthy(mock_list_users):
60+
mock_list_users.return_value = ["User1", "User2"]
61+
62+
result = identity_store.healthcheck()
63+
64+
assert result is True
65+
mock_list_users.assert_called_once
66+
67+
68+
@patch("integrations.aws.identity_store.list_users")
69+
def test_healtcheck_is_unhealthy(mock_list_users):
70+
mock_list_users.return_value = []
71+
72+
result = identity_store.healthcheck()
73+
74+
assert result is False
75+
mock_list_users.assert_called_once
76+
77+
5878
@patch("integrations.aws.identity_store.execute_aws_api_call")
5979
@patch("integrations.aws.identity_store.resolve_identity_store_id")
6080
def test_create_user(mock_resolve_identity_store_id, mock_execute_aws_api_call):

app/tests/jobs/test_scheduled_tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_run_continuously(time_mock, threading_mock, schedule_mock):
2424
assert result == cease_continuous_run
2525

2626

27-
@patch("jobs.scheduled_tasks.aws_client")
27+
@patch("jobs.scheduled_tasks.identity_store")
2828
@patch("jobs.scheduled_tasks.google_drive")
2929
@patch("jobs.scheduled_tasks.maxmind")
3030
@patch("jobs.scheduled_tasks.opsgenie")
@@ -43,7 +43,7 @@ def test_integration_healthchecks_healthy(
4343
assert mock_logging.error.call_count == 0
4444

4545

46-
@patch("jobs.scheduled_tasks.aws_client")
46+
@patch("jobs.scheduled_tasks.identity_store")
4747
@patch("jobs.scheduled_tasks.google_drive")
4848
@patch("jobs.scheduled_tasks.maxmind")
4949
@patch("jobs.scheduled_tasks.opsgenie")

0 commit comments

Comments
 (0)