Skip to content

Commit

Permalink
#5796 silence printing full config when config validation fails (#5879)
Browse files Browse the repository at this point in the history
* - #5796 silence printing full config when config validation fails

* fix unit tests after config validation check changes

Co-authored-by: Marcos Eliziario Santos <marcos@coremarcos.com>
  • Loading branch information
eliziario and eliziario authored Sep 14, 2021
1 parent 12b2dc9 commit 1314a6a
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 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.19
No longer prints full config files on validation error to prevent exposing secrets to log file: https://github.com/airbytehq/airbyte/pull/5879

## 0.1.18
Fix incremental stream not saved state when internal limit config set.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def check_config_against_spec_or_exit(config: Mapping[str, Any], spec: Connector
try:
validate(instance=config, schema=spec_schema)
except ValidationError as validation_error:
raise Exception("Config validation error: " + validation_error.message)
raise Exception("Config validation error: " + validation_error.message) from None


class InternalConfig(BaseModel):
Expand All @@ -159,7 +159,8 @@ def split_config(config: Mapping[str, Any]) -> Tuple[dict, InternalConfig]:
Break config map object into 2 instances: first is a dict with user defined
configuration and second is internal config that contains private keys for
acceptance test configuration.
:param config - Dict object that has been loaded from config file.
:param
config - Dict object that has been loaded from config file.
:return tuple of user defined config dict with filtered out internal
parameters and SAT internal config object.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,18 @@
import os
import shutil
import sys
import traceback
from collections.abc import Mapping
from pathlib import Path

from airbyte_cdk.sources.utils.schema_helpers import ResourceSchemaLoader
from airbyte_cdk.logger import AirbyteLogger
from airbyte_cdk.models.airbyte_protocol import ConnectorSpecification
from airbyte_cdk.sources.utils.schema_helpers import ResourceSchemaLoader, check_config_against_spec_or_exit
from pytest import fixture
from pytest import raises as pytest_raises

logger = AirbyteLogger()


MODULE = sys.modules[__name__]
MODULE_NAME = MODULE.__name__.split(".")[0]
Expand All @@ -53,6 +60,38 @@ def create_schema(name: str, content: Mapping):
f.write(json.dumps(content))


@fixture
def spec_object():
spec = {
"connectionSpecification": {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["api_token"],
"additionalProperties": False,
"properties": {
"api_token": {"title": "API Token", "type": "string"},
},
},
}
yield ConnectorSpecification.parse_obj(spec)


def test_check_config_against_spec_or_exit_does_not_print_schema(capsys, spec_object):
config = {"super_secret_token": "really_a_secret"}
with pytest_raises(Exception) as ex_info:
check_config_against_spec_or_exit(config, spec_object, logger)
exc = ex_info.value
traceback.print_exception(type(exc), exc, exc.__traceback__)
out, err = capsys.readouterr()
assert "really_a_secret" not in out + err


def test_should_not_fail_validation_for_valid_config(spec_object):
config = {"api_token": "something"}
check_config_against_spec_or_exit(config, spec_object, logger)
assert True, "should pass validation with valid config"


class TestResourceSchemaLoader:
# Test that a simple schema is loaded correctly
@staticmethod
Expand Down
3 changes: 1 addition & 2 deletions airbyte-cdk/python/unit_tests/test_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,8 @@ def test_config_validate(entrypoint: AirbyteEntrypoint, mocker, config_mock, sch
messages = list(entrypoint.run(parsed_args))
assert [_wrap_message(check_value)] == messages
else:
with pytest.raises(Exception) as ex_info:
with pytest.raises(Exception, match=r"(?i)Config Validation Error:.*"):
list(entrypoint.run(parsed_args))
assert "Config validation error:" in str(ex_info.value)


def test_run_check(entrypoint: AirbyteEntrypoint, mocker, spec_mock, config_mock):
Expand Down

0 comments on commit 1314a6a

Please sign in to comment.