Skip to content
This repository has been archived by the owner on Feb 15, 2024. It is now read-only.

Commit

Permalink
Move envvar checks from __init__.py to CLI
Browse files Browse the repository at this point in the history
In __ini__.py zsh/bash autocompletion eval has problems with the
direct print statements and tries to evaluate the text which is printed
  • Loading branch information
JakubFrejlach committed Nov 28, 2023
1 parent 7345c8e commit 84baa9f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 25 deletions.
57 changes: 32 additions & 25 deletions griffon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,8 @@
__version__ = "0.3.8"

# TODO: Deprecate CORGI_API_URL completely in the next version or two
if "CORGI_API_URL" in os.environ:
print(
(
f"{Style.BOLD}{Color.YELLOW}WARNING: CORGI_API_URL will be deprecated "
"in the next version of Griffon in favour of CORGI_SERVER_URL, please "
f"switch to the new environment variable.{Style.RESET}"
)
)

if "CORGI_SERVER_URL" not in os.environ and "CORGI_API_URL" not in os.environ:
print("Must set CORGI_SERVER_URL environment variable.")
exit(1)
CORGI_SERVER_URL = os.getenv("CORGI_SERVER_URL", os.getenv("CORGI_API_URL"))

# TODO: Deprecate CORGI_API_URL completely in the next version or two
if "OSIDB_API_URL" in os.environ:
print(
(
f"{Style.BOLD}{Color.YELLOW}WARNING: OSIDB_API_URL will be deprecated "
"in the next version of Griffon in favour of OSIDB_SERVER_URL, please "
f"switch to the new environment variable.{Style.RESET}"
)
)
if "OSIDB_SERVER_URL" not in os.environ and "OSIDB_API_URL" not in os.environ:
print("Must set OSIDB_SERVER_URL environment variable.")
exit(1)
# TODO: Deprecate OSIDB_API_URL completely in the next version or two
OSIDB_SERVER_URL = os.getenv("OSIDB_SERVER_URL", os.getenv("OSIDB_API_URL"))

OSIDB_USERNAME = os.getenv("OSIDB_USERNAME", "")
Expand All @@ -70,6 +46,37 @@
RELATED_MODELS_MAPPING = {Flaw: {"affects": Affect}, Affect: {"trackers": Tracker}}


def check_envvars():
"""Check that all necessary envvars are set"""

# TODO: Deprecate CORGI_API_URL completely in the next version or two
if "CORGI_API_URL" in os.environ:
print(
(
f"{Style.BOLD}{Color.YELLOW}WARNING: CORGI_API_URL will be deprecated "
"in the next version of Griffon in favour of CORGI_SERVER_URL, please "
f"switch to the new environment variable.{Style.RESET}"
)
)

if "CORGI_SERVER_URL" not in os.environ and "CORGI_API_URL" not in os.environ:
print("Must set CORGI_SERVER_URL environment variable.")
exit(1)

# TODO: Deprecate OSIDB_API_URL completely in the next version or two
if "OSIDB_API_URL" in os.environ:
print(
(
f"{Style.BOLD}{Color.YELLOW}WARNING: OSIDB_API_URL will be deprecated "
"in the next version of Griffon in favour of OSIDB_SERVER_URL, please "
f"switch to the new environment variable.{Style.RESET}"
)
)
if "OSIDB_SERVER_URL" not in os.environ and "OSIDB_API_URL" not in os.environ:
print("Must set OSIDB_SERVER_URL environment variable.")
exit(1)


def config_logging(level="INFO"):
# if set to 'DEBUG' then we want all the http conversation
if level == "DEBUG":
Expand Down
3 changes: 3 additions & 0 deletions griffon/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import click_completion

from griffon import (
check_envvars,
config_logging,
get_config_option,
list_config_sections,
Expand Down Expand Up @@ -134,6 +135,8 @@ def cli(
):
"""Red Hat product security CLI"""

check_envvars()

if ctx.invoked_subcommand is None:
click.echo(ctx.parent.get_help())

Expand Down

0 comments on commit 84baa9f

Please sign in to comment.