diff --git a/safety/cli.py b/safety/cli.py index 14ec46ae..70f38f02 100644 --- a/safety/cli.py +++ b/safety/cli.py @@ -129,6 +129,7 @@ def preprocess_args(f): + """Decorator to sanitize debug flag from unneeded values for example: debug true = debug""" if "--debug" in sys.argv: index = sys.argv.index("--debug") if len(sys.argv) > index + 1: @@ -139,6 +140,7 @@ def preprocess_args(f): def configure_logger(ctx, param, debug): + """Function that configures logging level and configures inital debug""" level = logging.CRITICAL if debug: @@ -814,11 +816,11 @@ def license(ctx, db, output, cache, files): def generate(ctx, name, path, minimum_cvss_severity): """Create a boilerplate Safety CLI policy file - NAME is the name of the file type to generate. Valid values are: policy_file + NAME is the name of the file type to generate. Valid values are: policy_file, installation_policy """ if name != "policy_file" and name != "installation_policy": click.secho( - f'This Safety version only supports "policy_file" generation. "{name}" is not supported.', + f'This Safety version only supports "policy_file" or "installation_policy" generation. "{name}" is not supported.', fg="red", file=sys.stderr, ) @@ -835,6 +837,7 @@ def generate(ctx, name, path, minimum_cvss_severity): def generate_installation_policy( ctx: "SafetyCustomContext", name, path, minimum_cvss_severity ): + """Generates installation policy for function generate""" all_severities = [severity.name.lower() for severity in VulnerabilitySeverityLabels] policy_severities = all_severities[ all_severities.index(minimum_cvss_severity.lower()) : @@ -923,6 +926,7 @@ def generate_installation_policy( def generate_policy_file(name, path): + """Generates and handles errors that could happen with creation of policy file""" path = Path(path) if not path.exists(): click.secho(f'The path "{path}" does not exist.', fg="red", file=sys.stderr) @@ -984,6 +988,7 @@ def validate(ctx, name, version, path): sys.exit(EXIT_CODE_FAILURE) def fail_validation(e): + """prints error to console and then exit the program""" click.secho(str(e).lstrip(), fg="red", file=sys.stderr) sys.exit(EXIT_CODE_FAILURE) @@ -1215,6 +1220,7 @@ def configure( def print_check_updates_header(console): + """Prints safety version to console""" VERSION = get_version() console.print( f"Safety {VERSION} checking for Safety version and configuration updates:" diff --git a/safety/cli_util.py b/safety/cli_util.py index 9ac8cbfb..4ed639cc 100644 --- a/safety/cli_util.py +++ b/safety/cli_util.py @@ -623,33 +623,38 @@ def process_auth_status_not_ready( login_command = get_command_for(name="login", typer_instance=auth_app) ctx.invoke(login_command) else: - console.print(MSG_NO_AUTHD_DEV_STG) - console.print() - choices = ["L", "R", "l", "r"] - next_command = Prompt.ask( - MSG_NO_AUTHD_DEV_STG_PROMPT, - default=None, - choices=choices, - show_choices=False, - console=console, - ) + if sys.stdin.isatty(): + console.print(MSG_NO_AUTHD_DEV_STG) + console.print() + choices = ["L", "R", "l", "r"] + next_command = Prompt.ask( + MSG_NO_AUTHD_DEV_STG_PROMPT, + default=None, + choices=choices, + show_choices=False, + console=console, + ) - from safety.auth.cli import auth_app + from safety.auth.cli import auth_app - login_command = get_command_for(name="login", typer_instance=auth_app) - register_command = get_command_for( - name="register", typer_instance=auth_app - ) - if next_command is None or next_command.lower() not in choices: - sys.exit(0) + login_command = get_command_for(name="login", typer_instance=auth_app) + register_command = get_command_for( + name="register", typer_instance=auth_app + ) + if next_command is None or next_command.lower() not in choices: + sys.exit(0) - console.print() - if next_command.lower() == "r": - ctx.invoke(register_command) - else: - ctx.invoke(login_command) + console.print() + if next_command.lower() == "r": + ctx.invoke(register_command) + else: + ctx.invoke(login_command) - if not auth.email_verified: + if not auth.email_verified: + sys.exit(1) + else: + console.print("non_interactble_terminal detected") + console.print("Currently working on solution, sorry for your inconvinience") sys.exit(1) else: if not auth.org: @@ -808,6 +813,10 @@ def add_command(self, cmd, name=None) -> None: self.all_commands[name] = cmd def parse_args(self, ctx: click.Context, args: List[str]) -> List[str]: + """ + Function that normalizes different versions of pip + For example: pip, pip3 = pip + """ ctx = cast(CustomContext, ctx) if len(args) >= 1: @@ -870,6 +879,7 @@ def parse_legacy_args( return proxy, key def get_filtered_commands(self, ctx: click.Context) -> Dict[str, click.Command]: + """Function that returns filtered commands from constants""" from safety.auth.utils import initialize initialize(ctx, refresh=False) diff --git a/safety/constants.py b/safety/constants.py index 6166ad3d..b13fe948 100644 --- a/safety/constants.py +++ b/safety/constants.py @@ -159,6 +159,12 @@ def get_config_setting(name: str, default=None) -> Optional[str]: def get_required_config_setting(name: str) -> str: + """Checks config for required settings + Args: + name: name of setting that it needs to check + Raises: + MissingConfigError: if value "name" not found + """ value = get_config_setting(name) if not value: raise MissingConfigError(f"Missing required config setting: {name}")