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

Do not always create a fides.toml by default #2023

Merged
merged 4 commits into from
Dec 13, 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
26 changes: 10 additions & 16 deletions src/fides/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from fides.cli.utils import (
check_and_update_analytics_config,
check_server,
create_config_file,
)
from fides.ctl.core.config import get_config

Expand Down Expand Up @@ -45,7 +44,6 @@
SERVER_CHECK_COMMAND_NAMES = [
command.name for command in API_COMMANDS if command.name not in ["status", "worker"]
]
WITHOUT_ANALYTICS_COMMANDS = ["init", "deploy", "webserver"]
VERSION = fides.__version__
APP = fides.__name__
PACKAGE = "ethyca-fides"
Expand Down Expand Up @@ -96,21 +94,17 @@ def cli(ctx: click.Context, config_path: str, local: bool) -> None:
check_server(VERSION, str(config.cli.server_url), quiet=True)

ctx.obj["CONFIG"] = config
create_config_file(ctx)

# init also handles this workflow
if ctx.invoked_subcommand not in WITHOUT_ANALYTICS_COMMANDS:
check_and_update_analytics_config(ctx, config_path)

# Analytics requires explicit opt-in
if config.user.analytics_opt_out is False:
ctx.meta["ANALYTICS_CLIENT"] = AnalyticsClient(
client_id=config.cli.analytics_id,
developer_mode=config.test_mode,
os=system(),
product_name=APP + "-cli",
production_version=version(PACKAGE),
)
# Analytics requires explicit opt-in
no_analytics = config.user.analytics_opt_out
if not no_analytics:
ctx.meta["ANALYTICS_CLIENT"] = AnalyticsClient(
client_id=config.cli.analytics_id,
developer_mode=config.test_mode,
os=system(),
product_name=APP + "-cli",
production_version=version(PACKAGE),
)


# Add all commands here before dynamically checking them in the CLI
Expand Down
2 changes: 0 additions & 2 deletions src/fides/cli/commands/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def init(ctx: click.Context, fides_directory_location: str) -> None:

click.echo(FIDES_ASCII_ART)
click.echo("Initializing fides...")
print_divider()

# create the config file as needed
config_path = create_config_file(
Expand All @@ -52,7 +51,6 @@ def init(ctx: click.Context, fides_directory_location: str) -> None:

# request explicit consent for analytics collection
check_and_update_analytics_config(ctx=ctx, config_path=config_path)
print_divider()

send_init_analytics(config.user.analytics_opt_out, config_path, executed_at)
echo_green("fides initialization complete.")
Expand Down
39 changes: 21 additions & 18 deletions src/fides/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
)
from requests import get, put

from fides import __name__ as app_name
import fides
from fides.api.ops.api.v1.urn_registry import REGISTRATION, V1_URL_PREFIX
from fides.ctl.connectors.models import (
AWSConfig,
Expand All @@ -47,6 +47,8 @@
from fides.ctl.core.config.utils import get_config_from_file, update_config_file
from fides.ctl.core.utils import check_response, echo_green, echo_red

APP = fides.__name__
PACKAGE = "ethyca-fides"
FIDES_ASCII_ART = """
███████╗██╗██████╗ ███████╗███████╗
██╔════╝██║██╔══██╗██╔════╝██╔════╝
Expand All @@ -57,16 +59,17 @@
"""


def check_server_health(server_url: str) -> requests.Response:
def check_server_health(server_url: str, verbose: bool = True) -> requests.Response:
"""Hit the '/health' endpoint and verify the server is available."""

healthcheck_url = server_url + "/health"
try:
health_response = check_response(_api.ping(healthcheck_url))
except requests.exceptions.ConnectionError:
echo_red(
f"Connection failed, webserver is unreachable at URL:\n{healthcheck_url}."
)
if verbose:
echo_red(
f"Connection failed, webserver is unreachable at URL:\n{healthcheck_url}."
)
raise SystemExit(1)
return health_response

Expand Down Expand Up @@ -197,18 +200,18 @@ def register_user(ctx: click.Context, email: str, organization: str) -> None:

def check_and_update_analytics_config(ctx: click.Context, config_path: str) -> None:
"""
Ensure the analytics-related config is present. If not,
prompt the user to opt-in to analytics and/or update the
config file with their preferences.
Verify that the analytics opt-out value is populated. If not,
prompt the user to opt-in to analytics and update the config
file with their preferences if needed.

NOTE: This doesn't handle the case where we've collected consent for this
CLI instance, but are connected to a server for the first time that is
unregistered. This *should* be something we can detect and then
"re-prompt" the user for their email/org information, but right
now a lot of our test automation runs headless and this kind of
prompt can't be skipped otherwise.
"""

# Prompt for user prompt if we've not collected explicit opt-out or opt-in
#
# NOTE: this doesn't handle the case where we've collected consent for this CLI,
# but are connected to a server for the first time that is unregistered.
# This *should* be something we can detect and then "re-prompt" the user for
# their email/org information, but right now a lot of our test automation
# runs headless and this kind of prompt can't be skipped otherwsie
config_updates: Dict[str, Dict] = {}
if ctx.obj["CONFIG"].user.analytics_opt_out is None:
click.echo(OPT_OUT_COPY)
Expand All @@ -225,7 +228,7 @@ def check_and_update_analytics_config(ctx: click.Context, config_path: str) -> N
if ctx.obj["CONFIG"].user.analytics_opt_out is False:
server_url = ctx.obj["CONFIG"].cli.server_url
try:
check_server_health(server_url)
check_server_health(server_url, verbose=False)
should_attempt_registration = not is_user_registered(ctx)
except SystemExit:
should_attempt_registration = False
Expand Down Expand Up @@ -277,8 +280,8 @@ def send_init_analytics(opt_out: bool, config_path: str, executed_at: datetime)
client_id=analytics_id or generate_client_id(FIDESCTL_CLI),
developer_mode=bool(getenv("FIDES_TEST_MODE") == "True"),
os=system(),
product_name=app_name + "-cli",
production_version=version(app_name),
product_name=APP + "-cli",
production_version=version(PACKAGE),
)

event = AnalyticsEvent(
Expand Down