Skip to content

Commit

Permalink
Added channel_name for api call logs records (#2023)
Browse files Browse the repository at this point in the history
* feat: added channel_name for api call logs records
  • Loading branch information
MueezKhan246 authored Feb 20, 2024
1 parent 7f2959b commit 844d9a6
Show file tree
Hide file tree
Showing 14 changed files with 72 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Change Log
Unreleased
----------
[4.11.14]
---------
* feat: added channel_name for api call logs records

[4.11.13]
---------
* feat: Update IntegratedChannelAPIRequestLogs list view
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.11.13"
__version__ = "4.11.14"
4 changes: 4 additions & 0 deletions integrated_channels/blackboard/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ def _get(self, url, data=None):
time_taken=time_taken,
status_code=get_response.status_code,
response_body=get_response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if get_response.status_code >= 400:
raise ClientError(get_response.text, get_response.status_code)
Expand All @@ -630,6 +631,7 @@ def _patch(self, url, data):
time_taken=time_taken,
status_code=patch_response.status_code,
response_body=patch_response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if patch_response.status_code >= 400:
raise ClientError(patch_response.text, patch_response.status_code)
Expand All @@ -650,6 +652,7 @@ def _post(self, url, data):
time_taken=time_taken,
status_code=post_response.status_code,
response_body=post_response.text,
channel_name=self.enterprise_configuration.channel_code()
)

if post_response.status_code >= 400:
Expand All @@ -671,6 +674,7 @@ def _delete(self, url):
time_taken=time_taken,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if response.status_code >= 400:
raise ClientError(response.text, response.status_code)
Expand Down
11 changes: 11 additions & 0 deletions integrated_channels/canvas/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def cleanup_duplicate_assignment_records(self, courses):
time_taken=duration_seconds,
status_code=resp.status_code,
response_body=resp.text,
channel_name=self.enterprise_configuration.channel_code()
)

if resp.status_code >= 400:
Expand Down Expand Up @@ -557,6 +558,7 @@ def _post(self, url, data):
time_taken=duration_seconds,
status_code=post_response.status_code,
response_body=post_response.text,
channel_name=self.enterprise_configuration.channel_code()
)

if post_response.status_code >= 400:
Expand All @@ -583,6 +585,7 @@ def _put(self, url, data):
time_taken=duration_seconds,
status_code=put_response.status_code,
response_body=put_response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if put_response.status_code >= 400:
raise ClientError(put_response.text, put_response.status_code)
Expand Down Expand Up @@ -610,6 +613,7 @@ def _delete(self, url):
time_taken=duration_seconds,
status_code=delete_response.status_code,
response_body=delete_response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if delete_response.status_code >= 400:
raise ClientError(delete_response.text, delete_response.status_code)
Expand Down Expand Up @@ -671,6 +675,7 @@ def _search_for_canvas_user_by_email(self, user_email):
time_taken=duration_seconds,
status_code=rsps.status_code,
response_body=rsps.text,
channel_name=self.enterprise_configuration.channel_code()
)

if rsps.status_code >= 400:
Expand Down Expand Up @@ -705,6 +710,7 @@ def _get_canvas_user_courses_by_id(self, user_id):
time_taken=duration_seconds,
status_code=rsps.status_code,
response_body=rsps.text,
channel_name=self.enterprise_configuration.channel_code()
)

if rsps.status_code >= 400:
Expand Down Expand Up @@ -749,6 +755,7 @@ def _handle_canvas_assignment_retrieval(
time_taken=duration_seconds,
status_code=resp.status_code,
response_body=resp.text,
channel_name=self.enterprise_configuration.channel_code()
)

more_pages_present = True
Expand Down Expand Up @@ -796,6 +803,7 @@ def _handle_canvas_assignment_retrieval(
time_taken=duration_seconds,
status_code=resp.status_code,
response_body=resp.text,
channel_name=self.enterprise_configuration.channel_code()
)

current_page_count += 1
Expand Down Expand Up @@ -828,6 +836,7 @@ def _handle_canvas_assignment_retrieval(
time_taken=duration_seconds,
status_code=resp.status_code,
response_body=resp.text,
channel_name=self.enterprise_configuration.channel_code()
)

try:
Expand Down Expand Up @@ -865,6 +874,7 @@ def _handle_canvas_assignment_submission(self, grade, course_id, assignment_id,
time_taken=duration_seconds,
status_code=submission_response.status_code,
response_body=submission_response.text,
channel_name=self.enterprise_configuration.channel_code()
)

if submission_response.status_code >= 400:
Expand Down Expand Up @@ -979,6 +989,7 @@ def _get_oauth_access_token(self):
time_taken=duration_seconds,
status_code=auth_response.status_code,
response_body=auth_response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if auth_response.status_code >= 400:
raise ClientError(auth_response.text, auth_response.status_code)
Expand Down
2 changes: 2 additions & 0 deletions integrated_channels/canvas/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def find_root_canvas_account(enterprise_configuration, session):
time_taken=duration_seconds,
status_code=resp.status_code,
response_body=resp.text,
channel_name=enterprise_configuration.channel_code()
)
all_accounts = resp.json()
root_account = None
Expand Down Expand Up @@ -97,6 +98,7 @@ def find_course_in_account(enterprise_configuration, session, canvas_account_id,
time_taken=duration_seconds,
status_code=resp.status_code,
response_body=resp.text,
channel_name=enterprise_configuration.channel_code()
)
all_courses_response = resp.json()

Expand Down
1 change: 1 addition & 0 deletions integrated_channels/cornerstone/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def create_course_completion(self, user_id, payload):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)
return response.status_code, response.text

Expand Down
3 changes: 2 additions & 1 deletion integrated_channels/cornerstone/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def get(self, request, *args, **kwargs):
payload=f"Request Headers: {headers_json}",
time_taken=duration_seconds,
status_code=200,
response_body=json.dumps(data)
response_body=json.dumps(data),
channel_name=enterprise_config.channel_code()
)
return Response(data)
5 changes: 5 additions & 0 deletions integrated_channels/degreed2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ def _get(self, url, scope):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if attempts <= self.MAX_RETRIES and response.status_code == 429:
sleep_seconds = self._calculate_backoff(attempts)
Expand Down Expand Up @@ -531,6 +532,7 @@ def _post(self, url, data, scope):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if attempts <= self.MAX_RETRIES and response.status_code == 429:
sleep_seconds = self._calculate_backoff(attempts)
Expand Down Expand Up @@ -575,6 +577,7 @@ def _patch(self, url, data, scope):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if attempts <= self.MAX_RETRIES and response.status_code == 429:
sleep_seconds = self._calculate_backoff(attempts)
Expand Down Expand Up @@ -619,6 +622,7 @@ def _delete(self, url, data, scope):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if attempts <= self.MAX_RETRIES and response.status_code == 429:
sleep_seconds = self._calculate_backoff(attempts)
Expand Down Expand Up @@ -682,6 +686,7 @@ def _get_oauth_access_token(self, scope):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)

try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.23 on 2024-02-16 07:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('integrated_channel', '0032_alter_integratedchannelapirequestlogs_endpoint'),
]

operations = [
migrations.AddField(
model_name='integratedchannelapirequestlogs',
name='channel_name',
field=models.TextField(blank=True, help_text='Name of the integrated channel associated with this API call log record.'),
),
]
7 changes: 7 additions & 0 deletions integrated_channels/integrated_channel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,10 @@ class IntegratedChannelAPIRequestLogs(TimeStampedModel):
response_body = models.TextField(
help_text="API call response body", blank=True, null=True
)
channel_name = models.TextField(
help_text="Name of the integrated channel associated with this API call log record.",
blank=True
)

class Meta:
app_label = "integrated_channel"
Expand Down Expand Up @@ -942,6 +946,7 @@ def store_api_call(
time_taken,
status_code,
response_body,
channel_name
):
"""
Creates new record in IntegratedChannelAPIRequestLogs table.
Expand All @@ -955,6 +960,7 @@ def store_api_call(
time_taken=time_taken,
status_code=status_code,
response_body=response_body,
channel_name=channel_name
)
record.save()
except Exception as e: # pylint: disable=broad-except
Expand All @@ -967,4 +973,5 @@ def store_api_call(
f"time_taken={time_taken}"
f"status_code={status_code}"
f"response_body={response_body}"
f"channel_name={channel_name}"
)
4 changes: 4 additions & 0 deletions integrated_channels/moodle/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def _post(self, additional_params):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)

return response
Expand Down Expand Up @@ -213,6 +214,7 @@ def _get_access_token(self):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)

try:
Expand Down Expand Up @@ -287,6 +289,7 @@ def _get_course_contents(self, course_id):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)
return response

Expand Down Expand Up @@ -347,6 +350,7 @@ def _get_courses(self, key):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)
return response

Expand Down
4 changes: 4 additions & 0 deletions integrated_channels/sap_success_factors/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def get_oauth_access_token(self, client_id, client_secret, company_id, user_id,
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)

try:
Expand Down Expand Up @@ -289,6 +290,7 @@ def _call_post_with_user_override(self, sap_user_id, url, payload):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)

if response.status_code >= 400:
Expand Down Expand Up @@ -320,6 +322,7 @@ def _call_post_with_session(self, url, payload):
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)
if response.status_code >= 400:
LOGGER.error(
Expand Down Expand Up @@ -401,6 +404,7 @@ def _call_search_students_recursively(self, sap_search_student_url, all_inactive
time_taken=duration_seconds,
status_code=response.status_code,
response_body=response.text,
channel_name=self.enterprise_configuration.channel_code()
)
sap_inactive_learners = response.json()
except ValueError as error:
Expand Down
6 changes: 5 additions & 1 deletion integrated_channels/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ def stringify_and_store_api_record(
data,
time_taken,
status_code,
response_body
response_body,
channel_name
):
"""
Stringify the given data and store the API record in the database.
Expand All @@ -537,6 +538,7 @@ def stringify_and_store_api_record(
f"stringify_and_store_api_record: Error occured during stringification: {e}"
f"enterprise_customer={enterprise_customer}"
f"enterprise_customer_configuration_id={enterprise_customer_configuration_id}"
f"channel name={channel_name}"
f"data={data}"
)
# Store stringified data in the database
Expand All @@ -549,12 +551,14 @@ def stringify_and_store_api_record(
time_taken=time_taken,
status_code=status_code,
response_body=response_body,
channel_name=channel_name
)
except Exception as e: # pylint: disable=broad-except
LOGGER.error(
f"stringify_and_store_api_record: Error occured while storing: {e}"
f"enterprise_customer={enterprise_customer}"
f"enterprise_customer_configuration_id={enterprise_customer_configuration_id}"
f"channel name={channel_name}"
f"data={data}"
)
return data
8 changes: 4 additions & 4 deletions tests/test_integrated_channels/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,26 +359,26 @@ def test_stringify_and_store_api_record(

# Test with dict input
stringified_data = utils.stringify_and_store_api_record(
"Customer", 123, "/endpoint", data, 1.23, 200, "response"
"Customer", 123, "/endpoint", data, 1.23, 200, "response", 'integrated_channel_name'
)
assert stringified_data == json.dumps(data)

# Test with int input
stringified_int = utils.stringify_and_store_api_record(
"Customer", 123, "/endpoint", 123, 1.23, 200, "response"
"Customer", 123, "/endpoint", 123, 1.23, 200, "response", 'integrated_channel_name'
)
assert stringified_int == "123"

# Test with tuple input
data_tuple = (1, 2, "hello")
stringified_tuple = utils.stringify_and_store_api_record(
"Customer", 123, "/endpoint", data_tuple, 1.23, 200, "response"
"Customer", 123, "/endpoint", data_tuple, 1.23, 200, "response", 'integrated_channel_name'
)
assert stringified_tuple == json.dumps(data_tuple)

# Test with list input
data_list = [1, 2, "world"]
stringified_list = utils.stringify_and_store_api_record(
"Customer", 123, "/endpoint", data_list, 1.23, 200, "response"
"Customer", 123, "/endpoint", data_list, 1.23, 200, "response", 'integrated_channel_name'
)
assert stringified_list == json.dumps(data_list)

0 comments on commit 844d9a6

Please sign in to comment.