Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-add deprecated API settings for backwards compatibility #959

Merged
merged 7 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ The types of changes are:
* Added taxonomy page to UI [#902](https://github.com/ethyca/fides/pull/902)
* Added a nested accordion component for displaying taxonomy data [#910](https://github.com/ethyca/fides/pull/910)
* Add lru cache to get_config [927](https://github.com/ethyca/fides/pull/927)
* Add support for deprecated API config values [#959](https://github.com/ethyca/fides/pull/959)
* `fides` is now an alias for `fidesctl` as a CLI entrypoint [#926](https://github.com/ethyca/fides/pull/926)
* Add user auth routes [929](https://github.com/ethyca/fides/pull/929)
* Bump fideslib to 3.0.1 and remove patch code[931](https://github.com/ethyca/fides/pull/931)
Expand Down Expand Up @@ -59,14 +60,15 @@ The types of changes are:

### Docs


### Fixed

* Dataset field columns show all columns by default in the UI [#898](https://github.com/ethyca/fides/pull/898)
* Fixed the missing `.fides./` directory when locating the default config [#933](https://github.com/ethyca/fides/pull/933)

## [1.7.1](https://github.com/ethyca/fides/compare/1.7.0...1.7.1) - 2022-07-28

### Added

* Add datasets via YAML in the UI [#813](https://github.com/ethyca/fides/pull/813)
* Add datasets via database connection [#834](https://github.com/ethyca/fides/pull/834) [#889](https://github.com/ethyca/fides/pull/889)
* Add delete confirmation when deleting a field or collection from a dataset [#809](https://github.com/ethyca/fides/pull/809)
Expand All @@ -78,15 +80,19 @@ The types of changes are:
* Added OpenAPI TypeScript client generation for the UI app. See the [README](/clients/admin-ui/src/types/api/README.md) for more details.

### Changed

* Remove the `obscure` requirement from the `generate` endpoint [#819](https://github.com/ethyca/fides/pull/819)

### Developer Experience

* When releases are published, dispatch a repository webhook event to ethyca/fidesctl-plus [#938](https://github.com/ethyca/fides/pull/938)

### Docs

* recommend/replace pip installs with pipx [#874](https://github.com/ethyca/fides/pull/874)

### Fixed

* CustomSelect input tooltips appear next to selector instead of wrapping to a new row.
* Datasets without the `third_country_transfer` will not cause the editing dataset form to not render.
* Fixed a build issue causing an `unknown` version of `fidesctl` to be installed in published Docker images [#836](https://github.com/ethyca/fides/pull/836)
Expand All @@ -95,7 +101,6 @@ The types of changes are:
* Dataset field columns show all columns by default in the UI [#898](https://github.com/ethyca/fides/pull/898)
* Fixed the `tag` specific GitHub Action workflows for Docker and publishing docs. [#901](https://github.com/ethyca/fides/pull/901)


## [1.7.0](https://github.com/ethyca/fides/compare/1.6.1...1.7.0) - 2022-06-23

### Added
Expand Down
5 changes: 4 additions & 1 deletion src/fidesctl/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Contains reusable utils for the CLI commands."""

import json
import pprint
import sys
from datetime import datetime, timezone
from functools import update_wrapper
Expand Down Expand Up @@ -74,7 +75,9 @@ def pretty_echo(dict_object: Dict, color: str = "white") -> None:
"""
Given a dict-like object and a color, pretty click echo it.
"""
click.secho(json.dumps(dict_object, indent=2), fg=color)
click.secho(
pprint.pformat(dict_object, indent=2, width=80, compact=True, depth=2), fg=color
)


def handle_cli_response(
Expand Down
20 changes: 19 additions & 1 deletion src/fidesctl/ctl/core/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
config sections into a single config.
"""
from functools import lru_cache
from typing import Dict
from typing import Dict, MutableMapping

import toml
from fideslib.core.config import load_toml
Expand Down Expand Up @@ -32,6 +32,23 @@ class FidesctlConfig(BaseModel):
logging: FidesctlLoggingSettings = FidesctlLoggingSettings()


def handle_deprecated_fields(settings: MutableMapping) -> MutableMapping:
"""Custom logic for handling deprecated values."""

if settings.get("api") and not settings.get("database"):
api_settings = settings.pop("api")
database_settings = dict()
database_settings["user"] = api_settings.get("database_user")
database_settings["password"] = api_settings.get("database_password")
database_settings["server"] = api_settings.get("database_host")
database_settings["port"] = api_settings.get("database_port")
database_settings["db"] = api_settings.get("database_name")
database_settings["test_db"] = api_settings.get("test_database_name")
settings["database"] = database_settings

return settings


@lru_cache(maxsize=1)
def get_config(config_path_override: str = "") -> FidesctlConfig:
"""
Expand All @@ -51,6 +68,7 @@ def get_config(config_path_override: str = "") -> FidesctlConfig:

# credentials specific logic for populating environment variable configs.
# this is done to allow overrides without hard typed pydantic models
settings = handle_deprecated_fields(settings)
config_environment_dict = settings.get("credentials", dict())
settings["credentials"] = merge_credentials_environment(
credentials_dict=config_environment_dict
Expand Down
9 changes: 9 additions & 0 deletions tests/ctl/cli/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ def test_init(test_cli_runner: CliRunner) -> None:
assert result.exit_code == 0


@pytest.mark.unit
def test_view_config(test_cli_runner: CliRunner) -> None:
result = test_cli_runner.invoke(
cli, ["view", "config"], env={"FIDESCTL__USER__ANALYTICS_OPT_OUT": "true"}
)
print(result.output)
assert result.exit_code == 0


@pytest.mark.unit
def test_webserver() -> None:
"""
Expand Down
6 changes: 6 additions & 0 deletions tests/ctl/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,19 @@

TEST_CONFIG_PATH = "tests/ctl/test_config.toml"
TEST_INVALID_CONFIG_PATH = "tests/ctl/test_invalid_config.toml"
TEST_DEPRECATED_CONFIG_PATH = "tests/ctl/test_deprecated_config.toml"


@pytest.fixture(scope="session")
def test_config_path() -> Generator:
yield TEST_CONFIG_PATH


@pytest.fixture(scope="session")
def test_deprecated_config_path() -> Generator:
yield TEST_DEPRECATED_CONFIG_PATH


@pytest.fixture(scope="session")
def test_invalid_config_path() -> Generator:
"""
Expand Down
40 changes: 21 additions & 19 deletions tests/ctl/core/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,37 @@
clear=True,
)
@pytest.mark.unit
def test_get_config() -> None:
def test_get_config(test_config_path: str) -> None:
"""Test that the actual config matches what the function returns."""
config = get_config("tests/ctl/test_config.toml")
config = get_config(test_config_path)
assert config.user.user_id == "1"
assert config.user.api_key == "test_api_key"
assert config.database.user == "postgres"
assert config.cli.server_url == "http://fidesctl:8080"
assert (
config.credentials["postgres_1"]["connection_string"]
== "postgresql+psycopg2://postgres:fidesctl@fidesctl-db:5432/fidesctl_test"
)


@patch.dict(
os.environ,
{},
clear=True,
)
@pytest.mark.unit
def test_get_deprecated_api_config(test_deprecated_config_path: str) -> None:
"""
Test that the deprecated API config values get written as database values.
"""
config = get_config(test_deprecated_config_path)
assert config.database.user == "postgres_deprecated"
assert config.database.password == "fidesctl_deprecated"
assert config.database.port == "5431"
assert config.database.db == "fidesctl_deprecated"
assert config.database.test_db == "fidesctl_test_deprecated"


@patch.dict(
os.environ,
{"FIDESCTL_CONFIG_PATH": ""},
Expand Down Expand Up @@ -108,20 +127,3 @@ def test_database_url_test_mode_disabled() -> None:
database_settings.async_database_uri
== "postgresql+asyncpg://postgres:fidesctl@fidesctl-db:5432/database"
)


@pytest.mark.unit
def test_database_url_test_mode_enabled() -> None:
os.environ["FIDESCTL_TEST_MODE"] = "True"
database_settings = FidesctlDatabaseSettings(
user="postgres",
password="fidesctl",
server="fidesctl-db",
port="5432",
db="database",
test_db="test_database",
)
assert (
database_settings.async_database_uri
== "postgresql+asyncpg://postgres:fidesctl@fidesctl-db:5432/test_database"
)
8 changes: 8 additions & 0 deletions tests/ctl/test_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ port="5432"
db="fidesctl"
test_db="fidesctl_test"

[api]
database_user = "postgres_deprecated"
database_password = "fidesctl_deprecated"
database_host = "localhost_deprecated"
database_port = "5432_deprecated"
database_name = "fidesctl_deprecated"
test_database_name = "fidesctl_test_deprecated"

[logging]
level = "INFO"

Expand Down
7 changes: 7 additions & 0 deletions tests/ctl/test_deprecated_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[api]
database_user = "postgres_deprecated"
database_password = "fidesctl_deprecated"
database_host = "localhost_deprecated"
database_port = "5431"
database_name = "fidesctl_deprecated"
test_database_name = "fidesctl_test_deprecated"