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

GRIF-130: Fix middleware CLI usage #274

Merged
merged 8 commits into from
Dec 13, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
service products-contain-component
* OSIDB_API_URL environment variable changed to OSIDB_SERVER_URL
* CORGI_API_URL environment variable changed to CORGI_SERVER_URL
* COMMUNITY_COMPONENTS_API_URL environment variable changed to
COMMUNITY_COMPONENTS_SERVER_URL
* Migrated from setup.py to pyproject.toml

### Added
Expand All @@ -24,6 +26,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
* standardized progress bar accross whole Griffon which fixes
no_progress_bar functionality
* fixed tab autocompletion for mutually exclusive and one of
option/argument groups
* data obtained from middleware CLI are now correctly filtered

## [0.3.8] - 2023-10-18
### Added
Expand Down
2 changes: 1 addition & 1 deletion docs/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export CORGI_SERVER_URL="https://<INSERT COMPONENT REGISTRY API URL>"

and the following is set to enable searching community components:
```commandline
export COMMUNITY_COMPONENTS_API_URL="https://component-registry.fedoraproject.org"
export COMMUNITY_COMPONENTS_SERVER_URL="https://component-registry.fedoraproject.org"
```

Your system must be properly authorised to access all these systems.
Expand Down
77 changes: 48 additions & 29 deletions griffon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,19 @@
__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", "")
OSIDB_PASSWORD = os.getenv("OSIDB_PASSWORD", "")
OSIDB_AUTH_METHOD = os.getenv("OSIDB_AUTH_METHOD", "kerberos")

# TODO: Deprecate COMMUNITY_COMPONENTS_API_URL completely in the next version or two
# required to enable --search-community
COMMUNITY_COMPONENTS_API_URL = os.getenv(
"COMMUNITY_COMPONENTS_API_URL", "https://component-registry.fedoraproject.org"
COMMUNITY_COMPONENTS_SERVER_URL = os.getenv(
"COMMUNITY_COMPONENTS_SERVER_URL",
os.getenv("COMMUNITY_COMPONENTS_API_URL", "https://component-registry.fedoraproject.org"),
)

# TODO: temporary hack required to enable searching of middleware
Expand All @@ -70,6 +48,47 @@
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 COMMUNITY_COMPONENTS_API_URL completely in the next version or two
if "COMMUNITY_COMPONENTS_API_URL" in os.environ:
print(
(
f"{Style.BOLD}{Color.YELLOW}WARNING: COMMUNITY_COMPONENTS_API_URL "
"will be deprecated in the next version of Griffon in favour of "
"COMMUNITY_COMPONENTS_SERVER_URL, please switch to the new environment "
f"variable.{Style.RESET}"
)
)

# 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 Expand Up @@ -287,10 +306,10 @@ def create_session():
"""init corgi session"""
try:
return component_registry_bindings.new_session(
component_registry_server_uri=COMMUNITY_COMPONENTS_API_URL,
component_registry_server_uri=COMMUNITY_COMPONENTS_SERVER_URL,
)
except: # noqa
console.log(f"{COMMUNITY_COMPONENTS_API_URL} is not accessible.")
console.log(f"{COMMUNITY_COMPONENTS_SERVER_URL } is not accessible.")
exit(1)

@staticmethod
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
49 changes: 26 additions & 23 deletions griffon/commands/custom_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,33 @@ class BaseGroupParameter:
"""

def handle_parse_result(self, ctx, opts, args):
if self.mutually_exclusive_group:
if opts.get(self.name) is None:
pass # skip check for not supplied click.Arguments
elif self.name in opts and any(
opt in opts for opt in self.mutually_exclusive_group if opts.get(opt) is not None
):
raise GriffonUsageError(
(
f"{Style.BOLD}{self.name} cannot be used with "
f"{', '.join(self.mutually_exclusive_group)}.{Style.RESET}"
),
ctx=ctx,
)

if self.required_group:
group_set = set(
opt for opt in opts if opt in self.required_group and opts.get(opt) is not None
)
if not any(group_set):
raise GriffonUsageError(
f"{Style.BOLD}At least one of {', '.join(self.required_group)} "
f"is required.{Style.RESET}",
ctx=ctx,
if not ctx.resilient_parsing:
if self.mutually_exclusive_group:
if opts.get(self.name) is None:
pass # skip check for not supplied click.Arguments
elif self.name in opts and any(
opt in opts
for opt in self.mutually_exclusive_group
if opts.get(opt) is not None
):
raise GriffonUsageError(
(
f"{Style.BOLD}{self.name} cannot be used with "
f"{', '.join(self.mutually_exclusive_group)}.{Style.RESET}"
),
ctx=ctx,
)

if self.required_group:
group_set = set(
opt for opt in opts if opt in self.required_group and opts.get(opt) is not None
)
if not any(group_set):
raise GriffonUsageError(
f"{Style.BOLD}At least one of {', '.join(self.required_group)} "
f"is required.{Style.RESET}",
ctx=ctx,
)

return super().handle_parse_result(ctx, opts, args)

Expand Down
4 changes: 2 additions & 2 deletions griffon/commands/entities/community_component_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
)

from griffon import (
COMMUNITY_COMPONENTS_API_URL,
COMMUNITY_COMPONENTS_SERVER_URL,
CORGI_SERVER_URL,
CommunityComponentService,
progress_bar,
Expand Down Expand Up @@ -65,7 +65,7 @@ def commmunity_components_grp(ctx):
# COMPONENTS


@commmunity_components_grp.group(help=f"{COMMUNITY_COMPONENTS_API_URL}/api/v1/components")
@commmunity_components_grp.group(help=f"{COMMUNITY_COMPONENTS_SERVER_URL}/api/v1/components")
@click.pass_context
def components(ctx):
"""Corgi Components."""
Expand Down
78 changes: 44 additions & 34 deletions griffon/commands/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,17 @@ def get_product_contain_component(
# TODO: interim hack for middleware
if component_name and MIDDLEWARE_CLI and not no_middleware:
operation_status.update("searching deptopia middleware.")
mw_command = [MIDDLEWARE_CLI, component_name, "-e", "maven", "--json"]

# Use split for users who runs middleware via python
mw_command = [
*MIDDLEWARE_CLI.split(),
component_name,
"-e",
"maven",
"-b",
"maven",
"--json",
]
if strict_name_search:
mw_command.append("-s")
proc = subprocess.run(
Expand All @@ -419,39 +429,39 @@ def get_product_contain_component(
# if search_all:
# mw_components.extend(mw_json["deps"])
for build in mw_components:
if build["build_type"] == "maven":
component = {
"product_versions": [{"name": build["ps_module"]}],
"product_streams": [
{
"name": build["ps_update_stream"],
"product_versions": [{"name": build["ps_module"]}],
}
],
"product_active": True,
"type": build["build_type"],
"name": build["build_name"],
"nvr": build["build_nvr"],
"upstreams": [],
"sources": [],
"software_build": {
"build_id": build["build_id"],
"source": build["build_repo"],
},
}
if "sources" in build:
for deps in build["sources"]:
for dep in deps["dependencies"]:
components = []
components.append(
{
"name": dep.get("name"),
"nvr": dep.get("nvr"),
"type": dep.get("type"),
}
)
component["sources"] = components
q.append(component)
component = {
"product_versions": [{"name": build["ps_module"]}],
"product_streams": [
{
"name": build["ps_update_stream"],
"product_versions": [{"name": build["ps_module"]}],
"active": True, # assume all product streams as active
}
],
"product_active": True,
"type": build["build_type"],
"name": build["build_name"],
"nvr": build["build_nvr"],
"upstreams": [],
"sources": [],
"software_build": {
"build_id": build["build_id"],
"source": build["build_repo"],
},
}
if "sources" in build:
for deps in build["sources"]:
for dep in deps["dependencies"]:
components = []
components.append(
{
"name": dep.get("name"),
"nvr": dep.get("nvr"),
"type": dep.get("type"),
}
)
component["sources"] = components
q.append(component)
except Exception:
logger.warning("problem accessing deptopia.")

Expand Down
Loading