opsmill / infrahub-sdk-python

Python SDK to interact with Infrahub
https://www.opsmill.com
Apache License 2.0
3 stars 2 forks source link

bug: Infrahubctl protocols command requires explicit branch #104

Open BaptisteGi opened 1 month ago

BaptisteGi commented 1 month ago

Component

infrahubctl

Infrahub SDK version

0.14.1

Current Behavior

> infrahubctl protocols
HTTP communication failure: Client error '400 Bad Request' for url 'http://localhost:8000/api/schema?branch=None'
For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400 on GET to http://localhost:8000/api/schema?branch=None

Expected Behavior

I would expect the command to get the default branch from my environment.

The same way I could do infrahubctl schema load schema.yml without having to specify the branch

Steps to Reproduce

Doesn't work:

infrahubctl protocols

Works:

infrahubctl protocols --branch main

Additional Information

No response

ogenstad commented 1 month ago

Looking at this I'd argue that it's also incorrect for infrahubctl schema load schema.yml with regards to the branch being hardcoded to main. Something like this would be more correct. We can perhaps add it for the protocols for now and then review the other commands for the next release.

diff --git a/infrahub_sdk/ctl/cli_commands.py b/infrahub_sdk/ctl/cli_commands.py
index fde4b16..3e4059b 100644
--- a/infrahub_sdk/ctl/cli_commands.py
+++ b/infrahub_sdk/ctl/cli_commands.py
@@ -366,9 +366,9 @@ def transform(

 @app.command(name="protocols")
 @catch_exception(console=console)
-def protocols(  # noqa: PLR0915
+def protocols(
     schemas: list[Path] = typer.Option(None, help="List of schemas or directory to load."),
-    branch: str = typer.Option(None, help="Branch of schema to export Python protocols for."),
+    branch: Optional[str] = typer.Option(None, help="Branch of schema to export Python protocols for."),
     sync: bool = typer.Option(False, help="Generate for sync or async."),
     _: str = CONFIG_PARAM,
     out: str = typer.Option("schema_protocols.py", help="Path to a file to save the result."),
@@ -388,6 +388,7 @@ def protocols(  # noqa: PLR0915

     else:
         client = initialize_client_sync()
+        branch = branch or client.default_branch