diff --git a/CHANGELOG.md b/CHANGELOG.md index a651c86..4ac7e65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Fixed +* fixed wrong progress bar usage accross several commands +* fixed error in raw json transform for single entities + ## [0.4.0] - 2023-12-22 ### Changed diff --git a/griffon/__init__.py b/griffon/__init__.py index 58e87a7..78113f1 100644 --- a/griffon/__init__.py +++ b/griffon/__init__.py @@ -361,7 +361,7 @@ def get_fields(model, prefix=""): @contextmanager -def console_status(no_progress_bar): +def console_status(no_progress_bar, initial_status=None): """updatable console status progress bar""" class DisabledStatusObject: @@ -389,16 +389,50 @@ def update(self, status, *args, **kwargs): status=f"[magenta b]griffoning:[/magenta b] [bold]{status}[/bold]", *args, **kwargs ) + def start(self): + self.status.start() + + def stop(self): + self.status.stop() + if no_progress_bar: yield DisabledStatusObject() else: + status = f": {initial_status}" if initial_status else "" + with console.status( - "[magenta b]griffoning[/magenta b]", spinner="line" + f"[magenta b]griffoning[/magenta b]{status}", spinner="line" ) as operation_status: yield StatusObject(operation_status) -def progress_bar( +def progress_bar(is_updatable=False, initial_status=None): + """ + progress bar decorator + + :param updatable: allows/disallows updatable progress bar status, if set to `True` + decorated function needs to have `operation_status` parameter + """ + + def decorator(func=None): + if not func: + return partial(decorator) + + @wraps(func) + def wrapper(*args, **kwargs): + obj: dict = args[0].obj + with console_status(obj.get("NO_PROGRESS_BAR"), initial_status) as operation_status: + if is_updatable: + func(*args, operation_status=operation_status, **kwargs) + else: + func(*args, **kwargs) + + return wrapper + + return decorator + + +def progress_bar2( func=None, ): """progress bar decorator""" diff --git a/griffon/commands/entities/community_component_registry.py b/griffon/commands/entities/community_component_registry.py index e60178c..9596428 100644 --- a/griffon/commands/entities/community_component_registry.py +++ b/griffon/commands/entities/community_component_registry.py @@ -88,7 +88,7 @@ def components(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_components(ctx, strict_name_search, component_name, **params): is_params_empty = [False for v in params.values() if v] if not component_name and not is_params_empty: @@ -121,7 +121,7 @@ def list_components(ctx, strict_name_search, component_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_component(ctx, component_id, purl, **params): is_params_empty = [False for v in params.values() if v] if not component_id and not purl and not is_params_empty: @@ -169,7 +169,7 @@ def get_component(ctx, component_id, purl, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_component_summary(ctx, component_name, strict_name_search, **params): """Get Component summary.""" is_params_empty = [False for v in params.values() if v] @@ -231,7 +231,7 @@ def get_component_summary(ctx, component_name, strict_name_search, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_component_provides(ctx, component_uuid, purl, **params): """Retrieve all Components provided by a Component.""" is_params_empty = [False for v in params.values() if v] @@ -271,7 +271,7 @@ def get_component_provides(ctx, component_uuid, purl, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_component_sources(ctx, component_uuid, purl, **params): """Retrieve all Components that contain Component.""" is_params_empty = [False for v in params.values() if v] @@ -310,7 +310,7 @@ def get_component_sources(ctx, component_uuid, purl, **params): help="Generate spdx manifest (json).", ) @click.pass_context -@progress_bar +@progress_bar() def get_component_manifest(ctx, component_uuid, purl, spdx_json_format): """Retrieve Component manifest.""" if not component_uuid and not purl: @@ -391,7 +391,7 @@ def list_product_streams(ctx, product_stream_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_product_stream(ctx, product_stream_name, inactive, ofuri, **params): """Retrieve Product Stream.""" is_params_empty = [False for v in params.values() if v] @@ -423,7 +423,8 @@ def get_product_stream(ctx, product_stream_name, inactive, ofuri, **params): }, ) @click.pass_context -def get_product_stream_components(ctx, product_stream_name, ofuri, **params): +@progress_bar(is_updatable=True) +def get_product_stream_components(ctx, product_stream_name, ofuri, operation_status, **params): """Retrieve Product Stream latest Components.""" if not ofuri and not product_stream_name: click.echo(ctx.get_help()) @@ -439,6 +440,8 @@ def get_product_stream_components(ctx, product_stream_name, ofuri, **params): params["ofuri"] = ps["ofuri"] if ofuri: params["ofuri"] = ofuri + + operation_status.stop() ctx.invoke(list_components, **params) @@ -458,7 +461,7 @@ def get_product_stream_components(ctx, product_stream_name, ofuri, **params): help="Generate spdx manifest (json).", ) @click.pass_context -@progress_bar +@progress_bar() def get_product_stream_manifest(ctx, product_stream_name, ofuri, spdx_json_format): """Retrieve Product Stream manifest.""" if not ofuri and not product_stream_name: @@ -527,7 +530,7 @@ def list_software_builds(ctx, software_build_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_software_build(ctx, software_build_name, **params): """Retrieve SoftwareBuild.""" is_params_empty = [False for v in params.values() if v] @@ -560,7 +563,7 @@ def products(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_products(ctx, product_name, **params): """Retrieve a list of Software Builds.""" session = CommunityComponentService.create_session() @@ -587,7 +590,7 @@ def list_products(ctx, product_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_product(ctx, product_name, ofuri, **params): """Retrieve Product.""" is_params_empty = [False for v in params.values() if v] @@ -622,7 +625,7 @@ def product_versions(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_product_versions(ctx, product_version_name, **params): """Retrieve a list of Product Versions.""" session = CommunityComponentService.create_session() @@ -652,7 +655,7 @@ def list_product_versions(ctx, product_version_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_product_version(ctx, product_version_name, ofuri, **params): """Retrieve ProductVersion.""" is_params_empty = [False for v in params.values() if v] @@ -687,7 +690,7 @@ def product_variants(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_product_variants(ctx, product_variant_name, **params): """Retrieve a list of Product Variants.""" session = CommunityComponentService.create_session() @@ -717,7 +720,7 @@ def list_product_variants(ctx, product_variant_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_product_variant(ctx, product_variant_name, ofuri, **params): """Retrieve ProductVariant.""" is_params_empty = [False for v in params.values() if v] @@ -750,7 +753,7 @@ def channels(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_channels(ctx, channel_name, **params): """Retrieve a list of Channels.""" session = CommunityComponentService.create_session() @@ -777,7 +780,7 @@ def list_channels(ctx, channel_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_channel(ctx, channel_name, ofuri, **params): """Retrieve ProductVariant.""" is_params_empty = [False for v in params.values() if v] diff --git a/griffon/commands/entities/corgi.py b/griffon/commands/entities/corgi.py index b49e3f6..206d398 100644 --- a/griffon/commands/entities/corgi.py +++ b/griffon/commands/entities/corgi.py @@ -83,7 +83,7 @@ def components(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_components(ctx, strict_name_search, component_name, **params): is_params_empty = [False for v in params.values() if v] if not component_name and not is_params_empty: @@ -117,7 +117,7 @@ def list_components(ctx, strict_name_search, component_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_component(ctx, component_id, purl, **params): is_params_empty = [False for v in params.values() if v] if not component_id and not purl and not is_params_empty: @@ -165,7 +165,7 @@ def get_component(ctx, component_id, purl, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_component_summary(ctx, component_name, strict_name_search, **params): """Get Component summary.""" is_params_empty = [False for v in params.values() if v] @@ -226,7 +226,7 @@ def get_component_summary(ctx, component_name, strict_name_search, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_component_provides(ctx, component_uuid, purl, **params): """Retrieve all Components provided by a Component.""" is_params_empty = [False for v in params.values() if v] @@ -264,7 +264,7 @@ def get_component_provides(ctx, component_uuid, purl, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_component_sources(ctx, component_uuid, purl, **params): """Retrieve all Components that contain Component.""" is_params_empty = [False for v in params.values() if v] @@ -304,7 +304,7 @@ def get_component_sources(ctx, component_uuid, purl, **params): help="Generate spdx manifest (json).", ) @click.pass_context -@progress_bar +@progress_bar() def get_component_manifest(ctx, component_uuid, purl, spdx_json_format): """Retrieve Component manifest.""" if not component_uuid and not purl: @@ -336,7 +336,7 @@ def get_component_manifest(ctx, component_uuid, purl, spdx_json_format): help="Display purl.", ) @click.pass_context -@progress_bar +@progress_bar() def get_component_tree(ctx, component_uuid, nvr, purl, show_purl): """Retrieve Component dependency tree.""" if not component_uuid and not purl and not nvr: @@ -381,7 +381,7 @@ def product_streams(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_product_streams(ctx, product_stream_name, **params): """Retrieve a list of Product Streams.""" is_params_empty = [False for v in params.values() if v] @@ -418,7 +418,7 @@ def list_product_streams(ctx, product_stream_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_product_stream(ctx, product_stream_name, inactive, ofuri, **params): """Retrieve Product Stream.""" is_params_empty = [False for v in params.values() if v] @@ -450,7 +450,8 @@ def get_product_stream(ctx, product_stream_name, inactive, ofuri, **params): }, ) @click.pass_context -def get_product_stream_components(ctx, product_stream_name, ofuri, **params): +@progress_bar(is_updatable=True) +def get_product_stream_components(ctx, product_stream_name, ofuri, operation_status, **params): """Retrieve Product Stream latest Components.""" if not ofuri and not product_stream_name: click.echo(ctx.get_help()) @@ -466,6 +467,8 @@ def get_product_stream_components(ctx, product_stream_name, ofuri, **params): params["ofuri"] = ps["ofuri"] if ofuri: params["ofuri"] = ofuri + + operation_status.stop() ctx.invoke(list_components, **params) @@ -485,7 +488,7 @@ def get_product_stream_components(ctx, product_stream_name, ofuri, **params): help="Generate spdx manifest (json).", ) @click.pass_context -@progress_bar +@progress_bar() def get_product_stream_manifest(ctx, product_stream_name, ofuri, spdx_json_format): """Retrieve Product Stream manifest.""" if not ofuri and not product_stream_name: @@ -529,7 +532,7 @@ def builds(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_software_builds(ctx, software_build_name, **params): """Retrieve a list of Software Builds.""" session = CorgiService.create_session() @@ -556,7 +559,7 @@ def list_software_builds(ctx, software_build_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_software_build(ctx, software_build_name, **params): """Retrieve SoftwareBuild.""" is_params_empty = [False for v in params.values() if v] @@ -589,7 +592,7 @@ def products(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_products(ctx, product_name, **params): """Retrieve a list of Software Builds.""" session = CorgiService.create_session() @@ -617,7 +620,7 @@ def list_products(ctx, product_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_product(ctx, product_name, ofuri, **params): """Retrieve Product.""" is_params_empty = [False for v in params.values() if v] @@ -650,7 +653,7 @@ def product_versions(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_product_versions(ctx, product_version_name, **params): """Retrieve a list of Product Versions.""" session = CorgiService.create_session() @@ -679,7 +682,7 @@ def list_product_versions(ctx, product_version_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_product_version(ctx, product_version_name, ofuri, **params): """Retrieve ProductVersion.""" is_params_empty = [False for v in params.values() if v] @@ -712,7 +715,7 @@ def product_variants(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_product_variants(ctx, product_variant_name, **params): """Retrieve a list of Product Variants.""" session = CorgiService.create_session() @@ -741,7 +744,7 @@ def list_product_variants(ctx, product_variant_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_product_variant(ctx, product_variant_name, ofuri, **params): """Retrieve ProductVariant.""" is_params_empty = [False for v in params.values() if v] @@ -774,7 +777,7 @@ def channels(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_channels(ctx, channel_name, **params): """Retrieve a list of Channels.""" session = CorgiService.create_session() @@ -802,7 +805,7 @@ def list_channels(ctx, channel_name, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_channel(ctx, channel_name, ofuri, **params): """Retrieve ProductVariant.""" is_params_empty = [False for v in params.values() if v] @@ -836,7 +839,7 @@ def corgi_status(ctx): @manage_grp.command(name="health") @click.pass_context -@progress_bar +@progress_bar() def corgi_health(ctx): try: session = CorgiService.create_session() diff --git a/griffon/commands/entities/osidb/affects/__init__.py b/griffon/commands/entities/osidb/affects/__init__.py index 5e124df..f0ef736 100644 --- a/griffon/commands/entities/osidb/affects/__init__.py +++ b/griffon/commands/entities/osidb/affects/__init__.py @@ -48,7 +48,7 @@ def affects(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_affects(ctx, **params): # TODO: handle pagination # TODO: handle output @@ -72,7 +72,7 @@ def list_affects(ctx, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_affect(ctx, affect_uuid, **params): """ For parameter reference see: @@ -89,6 +89,7 @@ def get_affect(ctx, affect_uuid, **params): @click.option("--uuid", "affect_uuid", help="Affect UUID.", required=True) @request_body_options(endpoint_module=osidb_api_v1_affects_update, exclude=["uuid"]) @click.pass_context +@progress_bar() def update_affect(ctx, affect_uuid, **params): request_body_type = getattr(osidb_api_v1_affects_update, "REQUEST_BODY_TYPE", None) if request_body_type is None: @@ -141,6 +142,7 @@ def update_affect(ctx, affect_uuid, **params): exclude=["uuid", "created_dt", "updated_dt"], ) @click.pass_context +@progress_bar() def create_affect(ctx, **params): request_body_type = getattr(osidb_api_v1_affects_create, "REQUEST_BODY_TYPE", None) if request_body_type is None: @@ -189,6 +191,7 @@ def create_affect(ctx, **params): prompt="Are you sure you delete affect?", ) @click.pass_context +@progress_bar() def delete_affect(ctx, affect_uuid, **params): session = OSIDBService.create_session() try: diff --git a/griffon/commands/entities/osidb/affects/cvss.py b/griffon/commands/entities/osidb/affects/cvss.py index bcfcd04..74c4912 100644 --- a/griffon/commands/entities/osidb/affects/cvss.py +++ b/griffon/commands/entities/osidb/affects/cvss.py @@ -55,7 +55,7 @@ def affect_cvss(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_affect_cvss(ctx, affect_id, cvss_uuid, **params): params = multivalue_params_to_csv(params) @@ -81,7 +81,7 @@ def get_affect_cvss(ctx, affect_id, cvss_uuid, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_affect_cvss(ctx, affect_id, **params): # TODO: handle pagination # TODO: handle output @@ -104,6 +104,7 @@ def list_affect_cvss(ctx, affect_id, **params): exclude=["uuid", "created_dt"], ) @click.pass_context +@progress_bar() def create_affect_cvss(ctx, affect_id, **params): request_body_type = getattr(osidb_api_v1_affects_cvss_scores_create, "REQUEST_BODY_TYPE", None) if request_body_type is None: @@ -152,6 +153,7 @@ def create_affect_cvss(ctx, affect_id, **params): @click.option("--uuid", "cvss_uuid", help="CVSS UUID.", required=True) @request_body_options(endpoint_module=osidb_api_v1_affects_cvss_scores_update, exclude=["uuid"]) @click.pass_context +@progress_bar() def update_affect_cvss(ctx, affect_id, cvss_uuid, **params): request_body_type = getattr(osidb_api_v1_affects_cvss_scores_update, "REQUEST_BODY_TYPE", None) if request_body_type is None: @@ -216,6 +218,7 @@ def update_affect_cvss(ctx, affect_id, cvss_uuid, **params): prompt="Are you sure you want to delete affect CVSS?", ) @click.pass_context +@progress_bar() def delete_affect_cvss(ctx, affect_id, cvss_uuid, **params): session = OSIDBService.create_session() try: diff --git a/griffon/commands/entities/osidb/flaws/__init__.py b/griffon/commands/entities/osidb/flaws/__init__.py index 9ff5033..2133f90 100644 --- a/griffon/commands/entities/osidb/flaws/__init__.py +++ b/griffon/commands/entities/osidb/flaws/__init__.py @@ -52,7 +52,7 @@ def flaws(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_flaws(ctx, **params): # TODO: handle output session = OSIDBService.create_session() @@ -80,7 +80,7 @@ def list_flaws(ctx, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_flaw(ctx, flaw_id, **params): params = multivalue_params_to_csv(params) @@ -154,6 +154,7 @@ def update_flaw(ctx, flaw_id, **params): exclude=["uuid", "trackers", "created_dt", "updated_dt"], ) @click.pass_context +@progress_bar() def create_flaw(ctx, **params): request_body_type = getattr(osidb_api_v1_flaws_create, "REQUEST_BODY_TYPE", None) if request_body_type is None: diff --git a/griffon/commands/entities/osidb/flaws/acknowledgments.py b/griffon/commands/entities/osidb/flaws/acknowledgments.py index 624c407..aa58b0e 100644 --- a/griffon/commands/entities/osidb/flaws/acknowledgments.py +++ b/griffon/commands/entities/osidb/flaws/acknowledgments.py @@ -61,7 +61,7 @@ def flaw_acknowledgments(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_flaw_acknowledgment(ctx, flaw_id, acknowledgment_uuid, **params): params = multivalue_params_to_csv(params) @@ -89,7 +89,7 @@ def get_flaw_acknowledgment(ctx, flaw_id, acknowledgment_uuid, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_flaw_acknowledgments(ctx, flaw_id, **params): # TODO: handle pagination # TODO: handle output @@ -112,6 +112,7 @@ def list_flaw_acknowledgments(ctx, flaw_id, **params): exclude=["uuid", "created_dt"], ) @click.pass_context +@progress_bar() def create_flaw_acknowledgment(ctx, flaw_id, **params): request_body_type = getattr( osidb_api_v1_flaws_acknowledgments_create, "REQUEST_BODY_TYPE", None @@ -162,6 +163,7 @@ def create_flaw_acknowledgment(ctx, flaw_id, **params): @click.option("--uuid", "acknowledgment_uuid", help="Acknowledgment UUID.", required=True) @request_body_options(endpoint_module=osidb_api_v1_flaws_acknowledgments_update, exclude=["uuid"]) @click.pass_context +@progress_bar() def update_flaw_acknowledgment(ctx, flaw_id, acknowledgment_uuid, **params): request_body_type = getattr( osidb_api_v1_flaws_acknowledgments_update, "REQUEST_BODY_TYPE", None @@ -229,6 +231,7 @@ def update_flaw_acknowledgment(ctx, flaw_id, acknowledgment_uuid, **params): prompt="Are you sure you want to delete Flaw Acknowledgment?", ) @click.pass_context +@progress_bar() def delete_flaw_acknowledgments(ctx, flaw_id, acknowledgment_uuid, **params): session = OSIDBService.create_session() try: diff --git a/griffon/commands/entities/osidb/flaws/comments.py b/griffon/commands/entities/osidb/flaws/comments.py index 71a56ca..4919470 100644 --- a/griffon/commands/entities/osidb/flaws/comments.py +++ b/griffon/commands/entities/osidb/flaws/comments.py @@ -53,7 +53,7 @@ def flaw_comments(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_flaw_comment(ctx, flaw_id, comment_uuid, **params): params = multivalue_params_to_csv(params) @@ -79,7 +79,7 @@ def get_flaw_comment(ctx, flaw_id, comment_uuid, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_flaw_comments(ctx, flaw_id, **params): # TODO: handle pagination # TODO: handle output @@ -102,6 +102,7 @@ def list_flaw_comments(ctx, flaw_id, **params): exclude=["uuid", "created_dt"], ) @click.pass_context +@progress_bar() def create_flaw_comment(ctx, flaw_id, **params): request_body_type = getattr(osidb_api_v1_flaws_comments_create, "REQUEST_BODY_TYPE", None) if request_body_type is None: diff --git a/griffon/commands/entities/osidb/flaws/cvss.py b/griffon/commands/entities/osidb/flaws/cvss.py index 543f5e0..dfac595 100644 --- a/griffon/commands/entities/osidb/flaws/cvss.py +++ b/griffon/commands/entities/osidb/flaws/cvss.py @@ -55,7 +55,7 @@ def flaw_cvss(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_flaw_cvss(ctx, flaw_id, cvss_uuid, **params): params = multivalue_params_to_csv(params) @@ -81,7 +81,7 @@ def get_flaw_cvss(ctx, flaw_id, cvss_uuid, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_flaw_cvss(ctx, flaw_id, **params): # TODO: handle pagination # TODO: handle output @@ -104,6 +104,7 @@ def list_flaw_cvss(ctx, flaw_id, **params): exclude=["uuid", "created_dt"], ) @click.pass_context +@progress_bar() def create_flaw_cvss(ctx, flaw_id, **params): request_body_type = getattr(osidb_api_v1_flaws_cvss_scores_create, "REQUEST_BODY_TYPE", None) if request_body_type is None: @@ -152,6 +153,7 @@ def create_flaw_cvss(ctx, flaw_id, **params): @click.option("--uuid", "cvss_uuid", help="CVSS UUID.", required=True) @request_body_options(endpoint_module=osidb_api_v1_flaws_cvss_scores_update, exclude=["uuid"]) @click.pass_context +@progress_bar() def update_flaw_cvss(ctx, flaw_id, cvss_uuid, **params): request_body_type = getattr(osidb_api_v1_flaws_cvss_scores_update, "REQUEST_BODY_TYPE", None) if request_body_type is None: @@ -216,6 +218,7 @@ def update_flaw_cvss(ctx, flaw_id, cvss_uuid, **params): prompt="Are you sure you want to delete Flaw CVSS?", ) @click.pass_context +@progress_bar() def delete_flaw_cvss(ctx, flaw_id, cvss_uuid, **params): session = OSIDBService.create_session() try: diff --git a/griffon/commands/entities/osidb/flaws/package_versions.py b/griffon/commands/entities/osidb/flaws/package_versions.py index 22ee0ef..1d2ace2 100644 --- a/griffon/commands/entities/osidb/flaws/package_versions.py +++ b/griffon/commands/entities/osidb/flaws/package_versions.py @@ -59,7 +59,7 @@ def flaw_package_versions(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_flaw_package_version(ctx, flaw_id, package_version_uuid, **params): params = multivalue_params_to_csv(params) @@ -87,7 +87,7 @@ def get_flaw_package_version(ctx, flaw_id, package_version_uuid, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_flaw_package_versions(ctx, flaw_id, **params): # TODO: handle pagination # TODO: handle output @@ -110,6 +110,7 @@ def list_flaw_package_versions(ctx, flaw_id, **params): exclude=["uuid", "created_dt"], ) @click.pass_context +@progress_bar() def create_flaw_package_version(ctx, flaw_id, **params): request_body_type = getattr( osidb_api_v1_flaws_package_versions_create, "REQUEST_BODY_TYPE", None @@ -160,6 +161,7 @@ def create_flaw_package_version(ctx, flaw_id, **params): @click.option("--uuid", "package_version_uuid", help="Package Version UUID.", required=True) @request_body_options(endpoint_module=osidb_api_v1_flaws_package_versions_update, exclude=["uuid"]) @click.pass_context +@progress_bar() def update_flaw_package_version(ctx, flaw_id, package_version_uuid, **params): request_body_type = getattr( osidb_api_v1_flaws_package_versions_update, "REQUEST_BODY_TYPE", None @@ -227,6 +229,7 @@ def update_flaw_package_version(ctx, flaw_id, package_version_uuid, **params): prompt="Are you sure you want to delete Flaw Package Version?", ) @click.pass_context +@progress_bar() def delete_flaw_package_version(ctx, flaw_id, package_versions_uuid, **params): session = OSIDBService.create_session() try: diff --git a/griffon/commands/entities/osidb/flaws/references.py b/griffon/commands/entities/osidb/flaws/references.py index a33d412..46fdf46 100644 --- a/griffon/commands/entities/osidb/flaws/references.py +++ b/griffon/commands/entities/osidb/flaws/references.py @@ -57,7 +57,7 @@ def flaw_references(ctx): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_flaw_reference(ctx, flaw_id, reference_uuid, **params): params = multivalue_params_to_csv(params) @@ -85,7 +85,7 @@ def get_flaw_reference(ctx, flaw_id, reference_uuid, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def list_flaw_references(ctx, flaw_id, **params): # TODO: handle pagination # TODO: handle output @@ -108,6 +108,7 @@ def list_flaw_references(ctx, flaw_id, **params): exclude=["uuid", "created_dt"], ) @click.pass_context +@progress_bar() def create_flaw_reference(ctx, flaw_id, **params): request_body_type = getattr(osidb_api_v1_flaws_references_create, "REQUEST_BODY_TYPE", None) if request_body_type is None: @@ -156,6 +157,7 @@ def create_flaw_reference(ctx, flaw_id, **params): @click.option("--uuid", "reference_uuid", help="Reference UUID.", required=True) @request_body_options(endpoint_module=osidb_api_v1_flaws_references_update, exclude=["uuid"]) @click.pass_context +@progress_bar() def update_flaw_reference(ctx, flaw_id, reference_uuid, **params): request_body_type = getattr(osidb_api_v1_flaws_references_update, "REQUEST_BODY_TYPE", None) if request_body_type is None: @@ -220,6 +222,7 @@ def update_flaw_reference(ctx, flaw_id, reference_uuid, **params): prompt="Are you sure you want to delete Flaw Reference?", ) @click.pass_context +@progress_bar() def delete_flaw_reference(ctx, flaw_id, reference_uuid, **params): session = OSIDBService.create_session() try: diff --git a/griffon/commands/entities/osidb/trackers.py b/griffon/commands/entities/osidb/trackers.py index a5f2e5c..856e347 100644 --- a/griffon/commands/entities/osidb/trackers.py +++ b/griffon/commands/entities/osidb/trackers.py @@ -62,7 +62,7 @@ def list_trackers(ctx, **params): }, ) @click.pass_context -@progress_bar +@progress_bar() def get_tracker(ctx, tracker_uuid, **params): params = multivalue_params_to_csv(params) diff --git a/griffon/commands/process.py b/griffon/commands/process.py index 95e707e..7514cb7 100644 --- a/griffon/commands/process.py +++ b/griffon/commands/process.py @@ -31,8 +31,8 @@ @click.option("--cve_id") @catch_exception(handle=(HTTPError)) @click.pass_context -@progress_bar -def generate_affects_for_component_process(ctx, purl, cve_id, operation_status): +@progress_bar() +def generate_affects_for_component_process(ctx, purl, cve_id): """Generate affects for specific component.""" if not purl and not cve_id: click.echo(ctx.get_help()) diff --git a/griffon/commands/queries.py b/griffon/commands/queries.py index 724c708..c054ba6 100644 --- a/griffon/commands/queries.py +++ b/griffon/commands/queries.py @@ -123,9 +123,9 @@ def queries_grp(ctx): mutually_exclusive_group=["strict_name_search"], ) @click.pass_context -@progress_bar +@progress_bar() def get_product_summary( - ctx, product_stream_name, strict_name_search, all, verbose, regex_name_search, operation_status + ctx, product_stream_name, strict_name_search, all, verbose, regex_name_search ): """get product stream.""" if verbose: @@ -155,7 +155,8 @@ def get_product_summary( help="Strict search, exact match of name.", ) @click.pass_context -def retrieve_component_summary(ctx, component_name, strict_name_search): +@progress_bar() +def retrieve_component_summary(ctx, component_name, strict_name_search, operation_status): """Get Component summary.""" if not component_name: click.echo(ctx.get_help()) @@ -163,6 +164,8 @@ def retrieve_component_summary(ctx, component_name, strict_name_search): cond = {} if component_name: cond["component_name"] = component_name + + operation_status.stop() ctx.invoke(get_component_summary, **cond) @@ -361,7 +364,7 @@ def retrieve_component_summary(ctx, component_name, strict_name_search): mutually_exclusive_group=["strict_name_search"], ) @click.pass_context -@progress_bar +@progress_bar(is_updatable=True) def get_product_contain_component( ctx, component_name, @@ -680,7 +683,7 @@ def get_product_contain_component( mutually_exclusive_group=["strict_name_search"], ) @click.pass_context -@progress_bar +@progress_bar() def get_component_contain_component( ctx, component_name, @@ -691,7 +694,6 @@ def get_component_contain_component( namespace, strict_name_search, verbose, - operation_status, regex_name_search, ): """List components that contain component.""" @@ -736,7 +738,7 @@ def get_component_contain_component( help="Generate spdx manifest (json).", ) @click.pass_context -@progress_bar +@progress_bar(is_updatable=True) def get_product_manifest_query(ctx, product_stream_name, ofuri, spdx_json_format, operation_status): """List components of a specific product version.""" if spdx_json_format: @@ -748,6 +750,8 @@ def get_product_manifest_query(ctx, product_stream_name, ofuri, spdx_json_format cond["ofuri"] = ofuri if product_stream_name: cond["product_stream_name"] = product_stream_name + + operation_status.stop() ctx.invoke(get_product_stream_manifest, **cond) @@ -787,7 +791,7 @@ def get_product_manifest_query(ctx, product_stream_name, ofuri, spdx_json_format help="Verbose output, more detailed search results, can be used multiple times (e.g. -vvv).", ) # noqa @click.pass_context -@progress_bar +@progress_bar(is_updatable=True) def get_product_latest_components_query( ctx, product_stream_name, ofuri, verbose, operation_status, **params ): @@ -805,6 +809,8 @@ def get_product_latest_components_query( ) params["ofuri"] = ps["ofuri"] params["include_fields"] = "name,nvr,related_url,purl,version,release,type,software_build" + + operation_status.stop() ctx.invoke(list_components, **params) @@ -834,7 +840,7 @@ def get_product_latest_components_query( help="Generate spdx manifest (json).", ) @click.pass_context -@progress_bar +@progress_bar(is_updatable=True) def retrieve_component_manifest(ctx, component_uuid, purl, spdx_json_format, operation_status): """Retrieve Component manifest.""" if spdx_json_format: @@ -845,6 +851,8 @@ def retrieve_component_manifest(ctx, component_uuid, purl, spdx_json_format, ope cond["uuid"] = component_uuid if purl: cond["purl"] = purl + + operation_status.stop() ctx.invoke(get_component_manifest, **cond) @@ -882,7 +890,7 @@ def retrieve_component_manifest(ctx, component_uuid, purl, spdx_json_format, ope help="filter by Component namespace.", ) @click.pass_context -@progress_bar +@progress_bar() def components_affected_by_specific_cve_query( ctx, cve_id, @@ -891,7 +899,6 @@ def components_affected_by_specific_cve_query( affect_impact, component_type, namespace, - operation_status, ): """List components affected by specific CVE.""" q = query_service.invoke(core_queries.components_affected_by_specific_cve_query, ctx.params) @@ -904,8 +911,8 @@ def components_affected_by_specific_cve_query( ) @click.argument("cve_id", required=True, type=click.STRING, shell_complete=get_cve_ids) @click.pass_context -@progress_bar -def product_versions_affected_by_cve_query(ctx, cve_id, operation_status): +@progress_bar() +def product_versions_affected_by_cve_query(ctx, cve_id): """List Products affected by a CVE.""" q = query_service.invoke( core_queries.products_versions_affected_by_specific_cve_query, ctx.params @@ -964,7 +971,7 @@ def product_versions_affected_by_cve_query(ctx, cve_id, operation_status): help="Strict search, exact match of component name.", ) @click.pass_context -@progress_bar +@progress_bar() def cves_for_specific_component_query( ctx, component_name, @@ -975,7 +982,6 @@ def cves_for_specific_component_query( affect_resolution, affect_impact, strict_name_search, - operation_status, ): """List flaws of a specific component.""" q = query_service.invoke(core_queries.cves_for_specific_component_query, ctx.params) @@ -1038,7 +1044,7 @@ def cves_for_specific_component_query( help="Strict search, exact match of component name.", ) @click.pass_context -@progress_bar +@progress_bar() def cves_for_specific_product_query( ctx, product_version_name, @@ -1049,7 +1055,6 @@ def cves_for_specific_product_query( affect_impact, affect_resolution, strict_name_search, - operation_status, ): """List flaws of a specific product.""" q = query_service.invoke(core_queries.cves_for_specific_product_query, ctx.params) diff --git a/griffon/commands/reports.py b/griffon/commands/reports.py index 4832f8a..5f3f06a 100644 --- a/griffon/commands/reports.py +++ b/griffon/commands/reports.py @@ -40,7 +40,7 @@ def reports_grp(ctx): @click.option("--product-name", shell_complete=get_product_stream_names) @click.option("--ofuri", shell_complete=get_product_stream_ofuris) @click.pass_context -@progress_bar +@progress_bar() def generate_affects_report( ctx, product_version_name, @@ -51,7 +51,6 @@ def generate_affects_report( name, product_name, ofuri, - operation_status, ): """A report operation""" if not all and not product_version_name: @@ -63,8 +62,8 @@ def generate_affects_report( @reports_grp.command(name="report-entities", help="Generate Entity report (with counts).") @click.option("--all", is_flag=True, default=True, help="Show summary report on all entities.") @click.pass_context -@progress_bar -def generate_entity_report(ctx, all, operation_status): +@progress_bar() +def generate_entity_report(ctx, all): """A report operation""" if not all: click.echo(ctx.get_help()) @@ -84,8 +83,8 @@ def generate_entity_report(ctx, all, operation_status): "--exclude_children", is_flag=True, default=False, help="Exclude children Component licenses." ) @click.pass_context -@progress_bar -def generate_license_report(ctx, product_stream_name, purl, exclude_children, operation_status): +@progress_bar() +def generate_license_report(ctx, product_stream_name, purl, exclude_children): """A report operation""" if not product_stream_name and not purl: click.echo(ctx.get_help()) diff --git a/griffon/output.py b/griffon/output.py index 524ea20..51303ae 100644 --- a/griffon/output.py +++ b/griffon/output.py @@ -61,9 +61,9 @@ def raw_json_transform(data, show_count: bool) -> dict: if show_count: output["count"] = len(results) # type: ignore else: - transformed = data if type(data) is dict else data.to_dict() + output = data if type(data) is dict else data.to_dict() for related_data in ("upstreams", "sources"): - transformed[related_data] = raw_json_transform_related(transformed, related_data) + output[related_data] = raw_json_transform_related(output, related_data) return output