From c744dedcdb4446035927065495693486e80f9915 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Wed, 19 Jul 2023 03:35:05 +0530 Subject: [PATCH 1/9] Initial implementation of logger --- src/firebase_functions/logger.py | 112 +++++++++++++++++++++++++++++++ tests/test_logger.py | 25 +++++++ 2 files changed, 137 insertions(+) create mode 100644 src/firebase_functions/logger.py create mode 100644 tests/test_logger.py diff --git a/src/firebase_functions/logger.py b/src/firebase_functions/logger.py new file mode 100644 index 0000000..e5e8e17 --- /dev/null +++ b/src/firebase_functions/logger.py @@ -0,0 +1,112 @@ +import enum as _enum +import json as _json +import sys as _sys +import typing as _typing +import typing_extensions as _typing_extensions + + +class LogSeverity(str, _enum.Enum): + """ + `LogSeverity` indicates the detailed severity of the log entry. See [LogSeverity](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity). + """ + + DEBUG = "DEBUG" + INFO = "INFO" + NOTICE = "NOTICE" + WARNING = "WARNING" + ERROR = "ERROR" + CRITICAL = "CRITICAL" + ALERT = "ALERT" + EMERGENCY = "EMERGENCY" + + +class LogEntry(_typing.TypedDict): + """ + `LogEntry` represents a log entry. + See [LogEntry](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry). + """ + + severity: _typing_extensions.Required[LogSeverity] + message: _typing_extensions.NotRequired[str] + + +def _entry_from_args(severity: LogSeverity, **kwargs) -> LogEntry: + """ + Creates a `LogEntry` from the given arguments. + """ + + message: str = " ".join( + # do we need to replace_circular here? + [ + value if isinstance(value, str) else _json.dumps( + _remove_circular(value)) for value in kwargs.values() + ]) + + return {"severity": severity, "message": message} + + +def _remove_circular(obj: _typing.Any, refs: _typing.Set[_typing.Any] = set()): + """ + Removes circular references from the given object and replaces them with "[CIRCULAR]". + """ + + if (id(obj) in refs): + return "[CIRCULAR]" + + if not isinstance(obj, (str, int, float, bool, type(None))): + refs.add(id(obj)) + + if isinstance(obj, dict): + return {key: _remove_circular(value, refs) for key, value in obj.items()} + elif isinstance(obj, list): + return [_remove_circular(value, refs) for _, value in enumerate(obj)] + elif isinstance(obj, tuple): + return tuple(_remove_circular(value, refs) for _, value in enumerate(obj)) + else: + return obj + + +def _get_write_file(severity: LogSeverity) -> _typing.TextIO: + if severity == LogSeverity.ERROR: + return _sys.stderr + return _sys.stdout + + +def write(entry: LogEntry) -> None: + write_file = _get_write_file(entry['severity']) + print(_json.dumps(_remove_circular(entry)), file=write_file) + + +def debug(**kwargs) -> None: + """ + Logs a debug message. + """ + write(_entry_from_args(LogSeverity.DEBUG, **kwargs)) + + +def log(**kwargs) -> None: + """ + Logs a log message. + """ + write(_entry_from_args(LogSeverity.NOTICE, **kwargs)) + + +def info(**kwargs) -> None: + """ + Logs an info message. + """ + write(_entry_from_args(LogSeverity.INFO, **kwargs)) + + +def warn(**kwargs) -> None: + """ + Logs a warning message. + """ + write(_entry_from_args(LogSeverity.WARNING, **kwargs)) + + +def error(**kwargs) -> None: + """ + Logs an error message. + """ + write(_entry_from_args(LogSeverity.ERROR, **kwargs)) diff --git a/tests/test_logger.py b/tests/test_logger.py new file mode 100644 index 0000000..de57d8f --- /dev/null +++ b/tests/test_logger.py @@ -0,0 +1,25 @@ +import pytest +import json +from firebase_functions import logger + + +class TestLogger: + def test_format_should_be_valid_json(self, capsys: pytest.CaptureFixture[str]): + logger.log(foo="bar") + raw_log_output = capsys.readouterr().out + try: + json.loads(raw_log_output) + except json.JSONDecodeError: + pytest.fail("Log output was not valid JSON.") + + def test_log_should_have_severity(self, capsys: pytest.CaptureFixture[str]): + logger.log(foo="bar") + raw_log_output = capsys.readouterr().out + log_output = json.loads(raw_log_output) + assert "severity" in log_output + + def test_log_should_have_message(self, capsys: pytest.CaptureFixture[str]): + logger.log(foo="bar") + raw_log_output = capsys.readouterr().out + log_output = json.loads(raw_log_output) + assert "message" in log_output From aaec1a639105bd87979f5c5dafdc908a41a8cdff Mon Sep 17 00:00:00 2001 From: exaby73 Date: Wed, 19 Jul 2023 03:45:43 +0530 Subject: [PATCH 2/9] format code --- src/firebase_functions/logger.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/firebase_functions/logger.py b/src/firebase_functions/logger.py index e5e8e17..fc56496 100644 --- a/src/firebase_functions/logger.py +++ b/src/firebase_functions/logger.py @@ -61,7 +61,8 @@ def _remove_circular(obj: _typing.Any, refs: _typing.Set[_typing.Any] = set()): elif isinstance(obj, list): return [_remove_circular(value, refs) for _, value in enumerate(obj)] elif isinstance(obj, tuple): - return tuple(_remove_circular(value, refs) for _, value in enumerate(obj)) + return tuple( + _remove_circular(value, refs) for _, value in enumerate(obj)) else: return obj From ef3a7650f48baa577cc3a22e9677f735c1cf0d39 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Wed, 19 Jul 2023 03:50:50 +0530 Subject: [PATCH 3/9] fix: lints --- src/firebase_functions/logger.py | 16 ++++++++++++---- tests/test_logger.py | 7 +++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/firebase_functions/logger.py b/src/firebase_functions/logger.py index fc56496..1756d53 100644 --- a/src/firebase_functions/logger.py +++ b/src/firebase_functions/logger.py @@ -1,3 +1,7 @@ +""" +Logger module for Firebase Functions. +""" + import enum as _enum import json as _json import sys as _sys @@ -7,7 +11,8 @@ class LogSeverity(str, _enum.Enum): """ - `LogSeverity` indicates the detailed severity of the log entry. See [LogSeverity](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity). + `LogSeverity` indicates the detailed severity of the log entry. See + [LogSeverity](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity). """ DEBUG = "DEBUG" @@ -45,12 +50,15 @@ def _entry_from_args(severity: LogSeverity, **kwargs) -> LogEntry: return {"severity": severity, "message": message} -def _remove_circular(obj: _typing.Any, refs: _typing.Set[_typing.Any] = set()): +def _remove_circular(obj: _typing.Any, refs: _typing.Set[_typing.Any] | None = None): """ Removes circular references from the given object and replaces them with "[CIRCULAR]". """ - if (id(obj) in refs): + if refs is None: + refs = set() + + if id(obj) in refs: return "[CIRCULAR]" if not isinstance(obj, (str, int, float, bool, type(None))): @@ -74,7 +82,7 @@ def _get_write_file(severity: LogSeverity) -> _typing.TextIO: def write(entry: LogEntry) -> None: - write_file = _get_write_file(entry['severity']) + write_file = _get_write_file(entry["severity"]) print(_json.dumps(_remove_circular(entry)), file=write_file) diff --git a/tests/test_logger.py b/tests/test_logger.py index de57d8f..e88edec 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -1,9 +1,16 @@ +""" +Logger module tests. +""" + import pytest import json from firebase_functions import logger class TestLogger: + """ + Tests for the logger module. + """ def test_format_should_be_valid_json(self, capsys: pytest.CaptureFixture[str]): logger.log(foo="bar") raw_log_output = capsys.readouterr().out From 89d7a4f84fd89fc332dcef82e1960cdc8697353b Mon Sep 17 00:00:00 2001 From: exaby73 Date: Wed, 19 Jul 2023 03:53:00 +0530 Subject: [PATCH 4/9] fix: format code --- src/firebase_functions/logger.py | 3 ++- tests/test_logger.py | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/firebase_functions/logger.py b/src/firebase_functions/logger.py index 1756d53..7bcd130 100644 --- a/src/firebase_functions/logger.py +++ b/src/firebase_functions/logger.py @@ -50,7 +50,8 @@ def _entry_from_args(severity: LogSeverity, **kwargs) -> LogEntry: return {"severity": severity, "message": message} -def _remove_circular(obj: _typing.Any, refs: _typing.Set[_typing.Any] | None = None): +def _remove_circular(obj: _typing.Any, + refs: _typing.Set[_typing.Any] | None = None): """ Removes circular references from the given object and replaces them with "[CIRCULAR]". """ diff --git a/tests/test_logger.py b/tests/test_logger.py index e88edec..c34e16f 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -11,7 +11,9 @@ class TestLogger: """ Tests for the logger module. """ - def test_format_should_be_valid_json(self, capsys: pytest.CaptureFixture[str]): + + def test_format_should_be_valid_json(self, + capsys: pytest.CaptureFixture[str]): logger.log(foo="bar") raw_log_output = capsys.readouterr().out try: From b416ba377e3fe1bbd7c122d8348c6f7841359bfb Mon Sep 17 00:00:00 2001 From: exaby73 Date: Wed, 19 Jul 2023 17:02:35 +0530 Subject: [PATCH 5/9] add: additional tests --- src/firebase_functions/logger.py | 11 ++++----- tests/test_logger.py | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/firebase_functions/logger.py b/src/firebase_functions/logger.py index 7bcd130..0a22a0e 100644 --- a/src/firebase_functions/logger.py +++ b/src/firebase_functions/logger.py @@ -40,12 +40,11 @@ def _entry_from_args(severity: LogSeverity, **kwargs) -> LogEntry: Creates a `LogEntry` from the given arguments. """ - message: str = " ".join( - # do we need to replace_circular here? - [ - value if isinstance(value, str) else _json.dumps( - _remove_circular(value)) for value in kwargs.values() - ]) + message: str = " ".join([ + value + if isinstance(value, str) else _json.dumps(_remove_circular(value)) + for value in kwargs.values() + ]) return {"severity": severity, "message": message} diff --git a/tests/test_logger.py b/tests/test_logger.py index c34e16f..145d33b 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -27,8 +27,48 @@ def test_log_should_have_severity(self, capsys: pytest.CaptureFixture[str]): log_output = json.loads(raw_log_output) assert "severity" in log_output + def test_severity_should_be_debug(self, capsys: pytest.CaptureFixture[str]): + logger.debug(foo="bar") + raw_log_output = capsys.readouterr().out + log_output = json.loads(raw_log_output) + assert log_output["severity"] == "DEBUG" + + def test_severity_should_be_notice(self, + capsys: pytest.CaptureFixture[str]): + logger.log(foo="bar") + raw_log_output = capsys.readouterr().out + log_output = json.loads(raw_log_output) + assert log_output["severity"] == "NOTICE" + + def test_severity_should_be_info(self, capsys: pytest.CaptureFixture[str]): + logger.info(foo="bar") + raw_log_output = capsys.readouterr().out + log_output = json.loads(raw_log_output) + assert log_output["severity"] == "INFO" + + def test_severity_should_be_warning(self, + capsys: pytest.CaptureFixture[str]): + logger.warn(foo="bar") + raw_log_output = capsys.readouterr().out + log_output = json.loads(raw_log_output) + assert log_output["severity"] == "WARNING" + + def test_severity_should_be_error(self, capsys: pytest.CaptureFixture[str]): + logger.error(foo="bar") + raw_log_output = capsys.readouterr().err + log_output = json.loads(raw_log_output) + assert log_output["severity"] == "ERROR" + def test_log_should_have_message(self, capsys: pytest.CaptureFixture[str]): logger.log(foo="bar") raw_log_output = capsys.readouterr().out log_output = json.loads(raw_log_output) assert "message" in log_output + + def test_message_should_be_space_separated( + self, capsys: pytest.CaptureFixture[str]): + logger.log(foo="bar", baz="qux") + expected_message = "bar qux" + raw_log_output = capsys.readouterr().out + log_output = json.loads(raw_log_output) + assert log_output["message"] == expected_message From 43f3bf5ee22448c3808e2c1e594b003d83ca07bf Mon Sep 17 00:00:00 2001 From: exaby73 Date: Thu, 19 Oct 2023 13:48:54 +0530 Subject: [PATCH 6/9] feat: add support for json data --- src/firebase_functions/logger.py | 39 ++++++++++++++++++++------------ tests/test_logger.py | 8 ++++++- 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/src/firebase_functions/logger.py b/src/firebase_functions/logger.py index 0a22a0e..57eaefb 100644 --- a/src/firebase_functions/logger.py +++ b/src/firebase_functions/logger.py @@ -11,7 +11,7 @@ class LogSeverity(str, _enum.Enum): """ - `LogSeverity` indicates the detailed severity of the log entry. See + `LogSeverity` indicates the detailed severity of the log entry. See [LogSeverity](https://cloud.google.com/logging/docs/reference/v2/rest/v2/LogEntry#logseverity). """ @@ -35,7 +35,7 @@ class LogEntry(_typing.TypedDict): message: _typing_extensions.NotRequired[str] -def _entry_from_args(severity: LogSeverity, **kwargs) -> LogEntry: +def _entry_from_args(severity: LogSeverity, *args, **kwargs) -> LogEntry: """ Creates a `LogEntry` from the given arguments. """ @@ -43,10 +43,18 @@ def _entry_from_args(severity: LogSeverity, **kwargs) -> LogEntry: message: str = " ".join([ value if isinstance(value, str) else _json.dumps(_remove_circular(value)) - for value in kwargs.values() + for value in args ]) - return {"severity": severity, "message": message} + object: _typing.Dict[str, _typing.Any] = { + key: value if isinstance(value, str) else _remove_circular(value) + for key, value in kwargs.items()} + + entry = {"severity": severity, **object} + if message: + entry["message"] = message + + return _typing.cast(LogEntry, entry) def _remove_circular(obj: _typing.Any, @@ -65,7 +73,8 @@ def _remove_circular(obj: _typing.Any, refs.add(id(obj)) if isinstance(obj, dict): - return {key: _remove_circular(value, refs) for key, value in obj.items()} + return { + key: _remove_circular(value, refs) for key, value in obj.items()} elif isinstance(obj, list): return [_remove_circular(value, refs) for _, value in enumerate(obj)] elif isinstance(obj, tuple): @@ -86,36 +95,36 @@ def write(entry: LogEntry) -> None: print(_json.dumps(_remove_circular(entry)), file=write_file) -def debug(**kwargs) -> None: +def debug(*args, **kwargs) -> None: """ Logs a debug message. """ - write(_entry_from_args(LogSeverity.DEBUG, **kwargs)) + write(_entry_from_args(LogSeverity.DEBUG, *args, **kwargs)) -def log(**kwargs) -> None: +def log(*args, **kwargs) -> None: """ Logs a log message. """ - write(_entry_from_args(LogSeverity.NOTICE, **kwargs)) + write(_entry_from_args(LogSeverity.NOTICE, *args, **kwargs)) -def info(**kwargs) -> None: +def info(*args, **kwargs) -> None: """ Logs an info message. """ - write(_entry_from_args(LogSeverity.INFO, **kwargs)) + write(_entry_from_args(LogSeverity.INFO, *args, **kwargs)) -def warn(**kwargs) -> None: +def warn(*args, **kwargs) -> None: """ Logs a warning message. """ - write(_entry_from_args(LogSeverity.WARNING, **kwargs)) + write(_entry_from_args(LogSeverity.WARNING, *args, **kwargs)) -def error(**kwargs) -> None: +def error(*args, **kwargs) -> None: """ Logs an error message. """ - write(_entry_from_args(LogSeverity.ERROR, **kwargs)) + write(_entry_from_args(LogSeverity.ERROR, *args, **kwargs)) diff --git a/tests/test_logger.py b/tests/test_logger.py index 145d33b..c5c934b 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -65,9 +65,15 @@ def test_log_should_have_message(self, capsys: pytest.CaptureFixture[str]): log_output = json.loads(raw_log_output) assert "message" in log_output + def test_log_should_have_other_keys(self, capsys: pytest.CaptureFixture[str]): + logger.log(foo="bar") + raw_log_output = capsys.readouterr().out + log_output = json.loads(raw_log_output) + assert "foo" in log_output + def test_message_should_be_space_separated( self, capsys: pytest.CaptureFixture[str]): - logger.log(foo="bar", baz="qux") + logger.log("bar", "qux") expected_message = "bar qux" raw_log_output = capsys.readouterr().out log_output = json.loads(raw_log_output) From 78fc22d382332a3af42221814da0bbf3cb8aeb9e Mon Sep 17 00:00:00 2001 From: exaby73 Date: Thu, 19 Oct 2023 14:06:33 +0530 Subject: [PATCH 7/9] fix: tests and lints --- src/firebase_functions/logger.py | 4 ++-- tests/test_logger.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/firebase_functions/logger.py b/src/firebase_functions/logger.py index 57eaefb..004fbb0 100644 --- a/src/firebase_functions/logger.py +++ b/src/firebase_functions/logger.py @@ -46,11 +46,11 @@ def _entry_from_args(severity: LogSeverity, *args, **kwargs) -> LogEntry: for value in args ]) - object: _typing.Dict[str, _typing.Any] = { + other: _typing.Dict[str, _typing.Any] = { key: value if isinstance(value, str) else _remove_circular(value) for key, value in kwargs.items()} - entry = {"severity": severity, **object} + entry: _typing.Dict[str, _typing.Any] = {"severity": severity, **other} if message: entry["message"] = message diff --git a/tests/test_logger.py b/tests/test_logger.py index c5c934b..721898a 100644 --- a/tests/test_logger.py +++ b/tests/test_logger.py @@ -60,12 +60,13 @@ def test_severity_should_be_error(self, capsys: pytest.CaptureFixture[str]): assert log_output["severity"] == "ERROR" def test_log_should_have_message(self, capsys: pytest.CaptureFixture[str]): - logger.log(foo="bar") + logger.log("bar") raw_log_output = capsys.readouterr().out log_output = json.loads(raw_log_output) assert "message" in log_output - def test_log_should_have_other_keys(self, capsys: pytest.CaptureFixture[str]): + def test_log_should_have_other_keys(self, + capsys: pytest.CaptureFixture[str]): logger.log(foo="bar") raw_log_output = capsys.readouterr().out log_output = json.loads(raw_log_output) From dbf8fc291d67a712aa217759f4ba39716af136d8 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Thu, 19 Oct 2023 14:49:41 +0530 Subject: [PATCH 8/9] fix: lints --- src/firebase_functions/private/_identity_fn.py | 11 +++++++---- src/firebase_functions/private/util.py | 5 ++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/firebase_functions/private/_identity_fn.py b/src/firebase_functions/private/_identity_fn.py index 918e302..d5c1e23 100644 --- a/src/firebase_functions/private/_identity_fn.py +++ b/src/firebase_functions/private/_identity_fn.py @@ -114,7 +114,7 @@ def _auth_user_record_from_token_data(token_data: dict[str, _typing.Any]): return AuthUserRecord( uid=token_data["uid"], email=token_data.get("email"), - email_verified=token_data.get("email_verified"), + email_verified=bool(token_data.get("email_verified")), display_name=token_data.get("display_name"), photo_url=token_data.get("photo_url"), phone_number=token_data.get("phone_number"), @@ -314,13 +314,16 @@ def before_operation_handler( try: if not _util.valid_on_call_request(request): _logging.error("Invalid request, unable to process.") - raise HttpsError(FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") + raise HttpsError( + FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") if request.json is None: _logging.error("Request is missing body.") - raise HttpsError(FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") + raise HttpsError( + FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") if request.json is None or "data" not in request.json: _logging.error("Request body is missing data.", request.json) - raise HttpsError(FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") + raise HttpsError( + FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") jwt_token = request.json["data"]["jwt"] decoded_token = _token_verifier.verify_auth_blocking_token(jwt_token) event = _auth_blocking_event_from_token_data(decoded_token) diff --git a/src/firebase_functions/private/util.py b/src/firebase_functions/private/util.py index 2533b1b..3a69cee 100644 --- a/src/firebase_functions/private/util.py +++ b/src/firebase_functions/private/util.py @@ -156,7 +156,8 @@ def _on_call_valid_content_type(request: _Request) -> bool: # Check that the Content-Type is JSON. if content_type.lower() != "application/json": - _logging.warning("Request has incorrect Content-Type: %s", content_type) + _logging.warning( + "Request has incorrect Content-Type: %s", content_type) return False return True @@ -387,6 +388,8 @@ def timestamp_conversion(time: str) -> _dt.datetime: elif precision_timestamp == PrecisionTimestamp.SECONDS: return second_timestamp_conversion(time) + raise ValueError("Invalid timestamp") + def microsecond_timestamp_conversion(time: str) -> _dt.datetime: """Converts a microsecond timestamp and returns a datetime object of the current time in UTC""" From 225ccd1588e315cc689850291aa4741e2418a876 Mon Sep 17 00:00:00 2001 From: exaby73 Date: Thu, 19 Oct 2023 14:53:13 +0530 Subject: [PATCH 9/9] fix: format --- src/firebase_functions/logger.py | 8 ++++---- src/firebase_functions/private/_identity_fn.py | 9 +++------ src/firebase_functions/private/util.py | 3 +-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/firebase_functions/logger.py b/src/firebase_functions/logger.py index 004fbb0..1b41a47 100644 --- a/src/firebase_functions/logger.py +++ b/src/firebase_functions/logger.py @@ -48,7 +48,8 @@ def _entry_from_args(severity: LogSeverity, *args, **kwargs) -> LogEntry: other: _typing.Dict[str, _typing.Any] = { key: value if isinstance(value, str) else _remove_circular(value) - for key, value in kwargs.items()} + for key, value in kwargs.items() + } entry: _typing.Dict[str, _typing.Any] = {"severity": severity, **other} if message: @@ -73,8 +74,7 @@ def _remove_circular(obj: _typing.Any, refs.add(id(obj)) if isinstance(obj, dict): - return { - key: _remove_circular(value, refs) for key, value in obj.items()} + return {key: _remove_circular(value, refs) for key, value in obj.items()} elif isinstance(obj, list): return [_remove_circular(value, refs) for _, value in enumerate(obj)] elif isinstance(obj, tuple): @@ -127,4 +127,4 @@ def error(*args, **kwargs) -> None: """ Logs an error message. """ - write(_entry_from_args(LogSeverity.ERROR, *args, **kwargs)) + write(_entry_from_args(LogSeverity.ERROR, *args, **kwargs)) diff --git a/src/firebase_functions/private/_identity_fn.py b/src/firebase_functions/private/_identity_fn.py index d5c1e23..b64b0c3 100644 --- a/src/firebase_functions/private/_identity_fn.py +++ b/src/firebase_functions/private/_identity_fn.py @@ -314,16 +314,13 @@ def before_operation_handler( try: if not _util.valid_on_call_request(request): _logging.error("Invalid request, unable to process.") - raise HttpsError( - FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") + raise HttpsError(FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") if request.json is None: _logging.error("Request is missing body.") - raise HttpsError( - FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") + raise HttpsError(FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") if request.json is None or "data" not in request.json: _logging.error("Request body is missing data.", request.json) - raise HttpsError( - FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") + raise HttpsError(FunctionsErrorCode.INVALID_ARGUMENT, "Bad Request") jwt_token = request.json["data"]["jwt"] decoded_token = _token_verifier.verify_auth_blocking_token(jwt_token) event = _auth_blocking_event_from_token_data(decoded_token) diff --git a/src/firebase_functions/private/util.py b/src/firebase_functions/private/util.py index 3a69cee..0997f8d 100644 --- a/src/firebase_functions/private/util.py +++ b/src/firebase_functions/private/util.py @@ -156,8 +156,7 @@ def _on_call_valid_content_type(request: _Request) -> bool: # Check that the Content-Type is JSON. if content_type.lower() != "application/json": - _logging.warning( - "Request has incorrect Content-Type: %s", content_type) + _logging.warning("Request has incorrect Content-Type: %s", content_type) return False return True