Skip to content

Commit

Permalink
flake8 fix 3764 obfuscate secrets logging (airbytehq#8583)
Browse files Browse the repository at this point in the history
* Secure logger implementation minus still broken new tests

* Secure logger implementation and unit tests

* code review changes

* filter text on uncaught exceptions

* auto-formatting

* Mistaken change left in code

* filter text on uncaught exceptions

* Simplify code, remove LoggingFilter and move obfuscation functionality to Formatter

* Update airbyte-cdk/python/airbyte_cdk/entrypoint.py

Co-authored-by: Eugene Kulak <widowmakerreborn@gmail.com>

* Obfuscate Secrets in Logging, code review changes

* Obfuscate Secrets in Logging, code review changes, unit test fixes

* CHANGELOG.md

* Format and flake8

* Fix build error/bump version/format

* Add airbyte prefix on test logger

Co-authored-by: Eugene Kulak <widowmakerreborn@gmail.com>
  • Loading branch information
eliziario and keu authored Dec 7, 2021
1 parent a7061dd commit 34ff075
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 8 deletions.
3 changes: 3 additions & 0 deletions airbyte-cdk/python/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

## 0.1.41
Fix build error

## 0.1.40
Filter airbyte_secrets values at logger and other logging refactorings.

Expand Down
1 change: 1 addition & 0 deletions airbyte-cdk/python/airbyte_cdk/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def init_unhandled_exception_output_filtering(logger: logging.Logger) -> None:
Make sure unhandled exceptions are not printed to the console without passing through the Airbyte logger and having
secrets removed.
"""

def hook_fn(_logger, exception_type, exception_value, traceback_):
# For developer ergonomics, we want to see the stack trace in the logs when we do a ctrl-c
if issubclass(exception_type, KeyboardInterrupt):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,4 @@ def get_secrets(source: Source, config: Mapping[str, Any], logger: logging.Logge
secret_key_names = [
".".join(key.split(".")[:1]) for key, value in flattened_key_values.items() if value and key.endswith("airbyte_secret")
]
return [
str(get_value_by_dot_notation(config, key))
for key in secret_key_names
if config.get(key)
]
return [str(get_value_by_dot_notation(config, key)) for key in secret_key_names if config.get(key)]
2 changes: 1 addition & 1 deletion airbyte-cdk/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name="airbyte-cdk",
version="0.1.40",
version="0.1.41",
description="A framework for writing Airbyte Connectors.",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
4 changes: 2 additions & 2 deletions airbyte-cdk/python/unit_tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
from typing import Dict

import pytest
from airbyte_cdk.logger import AirbyteLogFormatter, init_logger
from airbyte_cdk.logger import AirbyteLogFormatter


@pytest.fixture(scope="session")
def logger():
logger = logging.getLogger("Test logger")
logger = logging.getLogger("airbyte.Testlogger")
return logger


Expand Down
3 changes: 3 additions & 0 deletions airbyte-cdk/python/unit_tests/test_secure_logger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#
# Copyright (c) 2021 Airbyte, Inc., all rights reserved.
#

import logging
import sys
from argparse import Namespace
Expand Down Expand Up @@ -147,6 +148,7 @@ def test_airbyte_secret_is_masked_on_logger_output(source_spec, mocker, config,
def test_airbyte_secrets_are_masked_on_uncaught_exceptions(mocker, caplog):
caplog.set_level(logging.DEBUG, logger="airbyte.test")
caplog.handler.setFormatter(AirbyteLogFormatter())

class BrokenSource(MockSource):
def read(
self,
Expand Down Expand Up @@ -192,6 +194,7 @@ def read(
def test_non_airbyte_secrets_are_not_masked_on_uncaught_exceptions(mocker, caplog):
caplog.set_level(logging.DEBUG, logger="airbyte.test")
caplog.handler.setFormatter(AirbyteLogFormatter())

class BrokenSource(MockSource):
def read(
self,
Expand Down

0 comments on commit 34ff075

Please sign in to comment.