Skip to content

Commit

Permalink
PROD-2663: specify dataset on fides pull (#5260)
Browse files Browse the repository at this point in the history
  • Loading branch information
thingscouldbeworse committed Sep 12, 2024
1 parent ccfef3a commit a1ce570
Show file tree
Hide file tree
Showing 9 changed files with 284 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ The types of changes are:
- Adding erasure support for Microsoft Advertising [#5197](https://github.com/ethyca/fides/pull/5197)
- Implements fuzzy search for identities in Admin-UI Request Manager [#5232](https://github.com/ethyca/fides/pull/5232)
- New purpose header field for TCF banner [#5246](https://github.com/ethyca/fides/pull/5246)
- `fides` subcommand `pull` has resource name subcommands that take a `fides_key` argument allowing you to pull only one resource by name and type [#5260](https://github.com/ethyca/fides/pull/5260)

### Changed
- Removed unused `username` parameter from the Delighted integration configuration [#5220](https://github.com/ethyca/fides/pull/5220)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module = [
"cassandra.*",
"celery.*",
"citext.*",
"click_default_group.*",
"dask.*",
"deepdiff.*",
"defusedxml.ElementTree.*",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ APScheduler==3.9.1.post1
asyncpg==0.27.0
boto3==1.26.1
celery[pytest]==5.2.7
click_default_group==1.2.2
cloud-sql-python-connector==1.9.2
colorama>=0.4.3
cryptography==42.0.0
Expand Down
2 changes: 1 addition & 1 deletion src/fides/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from .commands.db import database
from .commands.deploy import deploy
from .commands.generate import generate
from .commands.pull import pull
from .commands.scan import scan
from .commands.ungrouped import (
delete,
Expand All @@ -31,7 +32,6 @@
init,
list_resources,
parse,
pull,
push,
status,
webserver,
Expand Down
178 changes: 178 additions & 0 deletions src/fides/cli/commands/pull.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
from typing import Optional

import rich_click as click
from click_default_group import DefaultGroup

from fides.cli.options import fides_key_argument, manifests_dir_argument
from fides.cli.utils import with_analytics, with_server_health_check
from fides.common.utils import echo_red
from fides.core import parse as _parse
from fides.core import pull as _pull
from fides.core.utils import git_is_dirty


@click.group(cls=DefaultGroup, default="all", default_if_no_args=True) # type: ignore
@click.pass_context
def pull(ctx: click.Context) -> None:
"""
Update local resource files based on the state of the objects on the server.
"""


@pull.command(name="all") # type: ignore
@click.pass_context
@manifests_dir_argument
@click.option(
"--all-resources",
"-a",
default=None,
help="Pulls all locally missing resources from the server into this file.",
)
@with_analytics
@with_server_health_check
def pull_all(
ctx: click.Context,
manifests_dir: str,
all_resources: Optional[str],
) -> None:
"""
Retrieve all resources from the server and update the local manifest files.
"""

# Make the resources that are pulled configurable
config = ctx.obj["CONFIG"]
# Do this to validate the manifests since they won't get parsed during the pull process
_parse.parse(manifests_dir)
if git_is_dirty(manifests_dir):
echo_red(

Check warning on line 47 in src/fides/cli/commands/pull.py

View check run for this annotation

Codecov / codecov/patch

src/fides/cli/commands/pull.py#L47

Added line #L47 was not covered by tests
f"There are unstaged changes in your manifest directory: '{manifests_dir}' \nAborting pull!"
)
raise SystemExit(1)

Check warning on line 50 in src/fides/cli/commands/pull.py

View check run for this annotation

Codecov / codecov/patch

src/fides/cli/commands/pull.py#L50

Added line #L50 was not covered by tests
_pull.pull(
url=config.cli.server_url,
manifests_dir=manifests_dir,
headers=config.user.auth_header,
all_resources_file=all_resources,
fides_key=None,
resource_type=None,
)


@pull.command(name="dataset") # type: ignore
@click.pass_context
@fides_key_argument
@manifests_dir_argument
def dataset(
ctx: click.Context,
fides_key: str,
manifests_dir: str,
) -> None:
"""
Retrieve a specific dataset from the server and update the local manifest files.
"""

config = ctx.obj["CONFIG"]
_pull.pull(

Check warning on line 75 in src/fides/cli/commands/pull.py

View check run for this annotation

Codecov / codecov/patch

src/fides/cli/commands/pull.py#L74-L75

Added lines #L74 - L75 were not covered by tests
url=config.cli.server_url,
manifests_dir=manifests_dir,
headers=config.user.auth_header,
fides_key=fides_key,
resource_type="dataset",
all_resources_file=None,
)


@pull.command(name="system") # type: ignore
@click.pass_context
@fides_key_argument
@manifests_dir_argument
def system(
ctx: click.Context,
fides_key: str,
manifests_dir: str,
) -> None:
"""
Retrieve a specific system from the server and update the local manifest files.
"""

config = ctx.obj["CONFIG"]
_pull.pull(

Check warning on line 99 in src/fides/cli/commands/pull.py

View check run for this annotation

Codecov / codecov/patch

src/fides/cli/commands/pull.py#L98-L99

Added lines #L98 - L99 were not covered by tests
url=config.cli.server_url,
manifests_dir=manifests_dir,
headers=config.user.auth_header,
fides_key=fides_key,
resource_type="system",
all_resources_file=None,
)


@pull.command(name="data_category") # type: ignore
@click.pass_context
@fides_key_argument
@manifests_dir_argument
def data_category(
ctx: click.Context,
fides_key: str,
manifests_dir: str,
) -> None:
"""
Retrieve a specific data_category from the server and update the local manifest files.
"""

config = ctx.obj["CONFIG"]
_pull.pull(
url=config.cli.server_url,
manifests_dir=manifests_dir,
headers=config.user.auth_header,
fides_key=fides_key,
resource_type="data_category",
all_resources_file=None,
)


@pull.command(name="data_use") # type: ignore
@click.pass_context
@fides_key_argument
@manifests_dir_argument
def data_use(
ctx: click.Context,
fides_key: str,
manifests_dir: str,
) -> None:
"""
Retrieve a specific data_use from the server and update the local manifest files.
"""

config = ctx.obj["CONFIG"]
_pull.pull(

Check warning on line 147 in src/fides/cli/commands/pull.py

View check run for this annotation

Codecov / codecov/patch

src/fides/cli/commands/pull.py#L146-L147

Added lines #L146 - L147 were not covered by tests
url=config.cli.server_url,
manifests_dir=manifests_dir,
headers=config.user.auth_header,
fides_key=fides_key,
resource_type="data_use",
all_resources_file=None,
)


@pull.command(name="data_subject") # type: ignore
@click.pass_context
@fides_key_argument
@manifests_dir_argument
def data_subject(
ctx: click.Context,
fides_key: str,
manifests_dir: str,
) -> None:
"""
Retrieve a specific data_subject from the server and update the local manifest files.
"""

config = ctx.obj["CONFIG"]
_pull.pull(

Check warning on line 171 in src/fides/cli/commands/pull.py

View check run for this annotation

Codecov / codecov/patch

src/fides/cli/commands/pull.py#L170-L171

Added lines #L170 - L171 were not covered by tests
url=config.cli.server_url,
manifests_dir=manifests_dir,
headers=config.user.auth_header,
fides_key=fides_key,
resource_type="data_subject",
all_resources_file=None,
)
36 changes: 0 additions & 36 deletions src/fides/cli/commands/ungrouped.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Contains all of the ungrouped CLI commands for fides."""

from datetime import datetime, timezone
from typing import Optional

import rich_click as click
import yaml
Expand Down Expand Up @@ -33,10 +32,8 @@
from fides.core import audit as _audit
from fides.core import evaluate as _evaluate
from fides.core import parse as _parse
from fides.core import pull as _pull
from fides.core import push as _push
from fides.core.api_helpers import get_server_resource, list_server_resources
from fides.core.utils import git_is_dirty


@click.command() # type: ignore
Expand Down Expand Up @@ -311,36 +308,3 @@ def parse(ctx: click.Context, manifests_dir: str, verbose: bool = False) -> None
taxonomy = _parse.parse(manifests_dir=manifests_dir)
if verbose:
pretty_echo(taxonomy.model_dump(mode="json"), color="green")


@click.command() # type: ignore
@click.pass_context
@manifests_dir_argument
@click.option(
"--all-resources",
"-a",
default=None,
help="Pulls all locally missing resources from the server into this file.",
)
@with_analytics
@with_server_health_check
def pull(ctx: click.Context, manifests_dir: str, all_resources: Optional[str]) -> None:
"""
Update local resource files based on the state of the objects on the server.
"""

# Make the resources that are pulled configurable
config = ctx.obj["CONFIG"]
# Do this to validate the manifests since they won't get parsed during the pull process
_parse.parse(manifests_dir)
if git_is_dirty(manifests_dir):
echo_red(
f"There are unstaged changes in your manifest directory: '{manifests_dir}' \nAborting pull!"
)
raise SystemExit(1)
_pull.pull(
url=config.cli.server_url,
manifests_dir=manifests_dir,
headers=config.user.auth_header,
all_resources_file=all_resources,
)
26 changes: 25 additions & 1 deletion src/fides/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@
# If/when that issue is resolved, they can be removed.


def diff_flag(command: Callable) -> Callable:
"""Print any diffs between the local & server objects"""
command = click.option(

Check warning on line 18 in src/fides/cli/options.py

View check run for this annotation

Codecov / codecov/patch

src/fides/cli/options.py#L18

Added line #L18 was not covered by tests
"--diff",
is_flag=True,
help="Print any diffs between the local & server objects",
)(
command
) # type: ignore
return command

Check warning on line 25 in src/fides/cli/options.py

View check run for this annotation

Codecov / codecov/patch

src/fides/cli/options.py#L25

Added line #L25 was not covered by tests


def coverage_threshold_option(command: Callable) -> Callable:
"""An option decorator that sets a required coverage percentage."""
command = click.option(
Expand All @@ -28,7 +40,7 @@ def coverage_threshold_option(command: Callable) -> Callable:


def resource_type_argument(command: Callable) -> Callable:
"Add the resource_type option."
"Add the resource_type argument."
command = click.argument(
"resource_type",
type=click.Choice(model_list, case_sensitive=False),
Expand All @@ -38,6 +50,18 @@ def resource_type_argument(command: Callable) -> Callable:
return command


def resource_type_option(command: Callable) -> Callable:
"Add the resource_type option."
command = click.option(

Check warning on line 55 in src/fides/cli/options.py

View check run for this annotation

Codecov / codecov/patch

src/fides/cli/options.py#L55

Added line #L55 was not covered by tests
"--resource-type",
default="",
help=f"Choose from {str(model_list)}",
)(
command
) # type: ignore
return command

Check warning on line 62 in src/fides/cli/options.py

View check run for this annotation

Codecov / codecov/patch

src/fides/cli/options.py#L62

Added line #L62 was not covered by tests


def fides_key_argument(command: Callable) -> Callable:
"Add the fides_key argument."
command = click.argument(
Expand Down
Loading

0 comments on commit a1ce570

Please sign in to comment.