diff --git a/CHANGELOG.md b/CHANGELOG.md index eb3f435c..efff92be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,24 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang +## [1.0.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.0.0) - 2024-10-31 + +### Removed + +- Breaking change: Removed all exports from infrahub_sdk/__init__.py except InfrahubClient, InfrahubClientSync and Config. If you previously imported other classes such as InfrahubNode from the root level these need to change to instead be an absolute path. + +### Added + +- Add support for specific timeout per request on InfrahubClient and InfrahubNode function calls. ([#25](https://github.com/opsmill/infrahub-sdk-python/issues/25)) +- Added `infrahubctl menu` command to load menu definitions into Infrahub + +### Fixed + +- Fix SDK playback hash generation to read the correct filename ([#64](https://github.com/opsmill/infrahub-sdk-python/issues/64)) +- CTL: Return friendly error on encoding violations when reading files. ([#102](https://github.com/opsmill/infrahub-sdk-python/issues/102)) +- Changed the default connection timeout in the SDK to 60s. +- Fixes an issue where InfrahubClient was not properly URL encoding URL parameters. + ## [0.14.1](https://github.com/opsmill/infrahub-sdk-python/tree/v0.14.1) - 2024-10-22 ### Fixed @@ -22,7 +40,7 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang ### Removed -- Removed depreceted methods InfrahubClient.init and InfrahubClientSync.init ([#33](https://github.com/opsmill/infrahub-sdk-python/issues/33)) +- Removed deprecated methods InfrahubClient.init and InfrahubClientSync.init ([#33](https://github.com/opsmill/infrahub-sdk-python/issues/33)) ### Changed diff --git a/changelog/+8dff6891.removed.md b/changelog/+8dff6891.removed.md deleted file mode 100644 index a34332fb..00000000 --- a/changelog/+8dff6891.removed.md +++ /dev/null @@ -1 +0,0 @@ -Breaking change: Removed all exports from infrahub_sdk/__init__.py except InfrahubClient, InfrahubClientSync and Config. If you previously imported other classes such as InfrahubNode from the root level these need to change to instead be an absolute path. diff --git a/changelog/+connection-timeout.fixed.md b/changelog/+connection-timeout.fixed.md deleted file mode 100644 index a3a47ea4..00000000 --- a/changelog/+connection-timeout.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Changed the default connection timeout in the SDK to 60s. diff --git a/changelog/102.fixed.md b/changelog/102.fixed.md deleted file mode 100644 index bc4325fd..00000000 --- a/changelog/102.fixed.md +++ /dev/null @@ -1 +0,0 @@ -CTL: Return friendly error on encoding violations when reading files. diff --git a/changelog/25.added.md b/changelog/25.added.md deleted file mode 100644 index 5ea6dad6..00000000 --- a/changelog/25.added.md +++ /dev/null @@ -1 +0,0 @@ -Add support for specific timeout per request on InfrahubClient and InfrahubNode function calls. diff --git a/changelog/64.fixed.md b/changelog/64.fixed.md deleted file mode 100644 index 06a070c6..00000000 --- a/changelog/64.fixed.md +++ /dev/null @@ -1 +0,0 @@ -Fix SDK playback hash generation to read the correct filename diff --git a/infrahub_sdk/branch.py b/infrahub_sdk/branch.py index f23bc8e2..713c0063 100644 --- a/infrahub_sdk/branch.py +++ b/infrahub_sdk/branch.py @@ -1,6 +1,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any, Optional, Union +from urllib.parse import urlencode from pydantic import BaseModel @@ -55,14 +56,16 @@ def generate_diff_data_url( time_to: Optional[str] = None, ) -> str: """Generate the URL for the diff_data function.""" - url = f"{client.address}/api/diff/data?branch={branch_name}" - url += f"&branch_only={str(branch_only).lower()}" + url = f"{client.address}/api/diff/data" + url_params = {} + url_params["branch"] = branch_name + url_params["branch_only"] = str(branch_only).lower() if time_from: - url += f"&time_from={time_from}" + url_params["time_from"] = time_from if time_to: - url += f"&time_to={time_to}" + url_params["time_to"] = time_to - return url + return url + urlencode(url_params) class InfrahubBranchManager(InfraHubBranchManagerBase): diff --git a/infrahub_sdk/client.py b/infrahub_sdk/client.py index 9d7dbeb2..fba3ce82 100644 --- a/infrahub_sdk/client.py +++ b/infrahub_sdk/client.py @@ -18,6 +18,7 @@ Union, overload, ) +from urllib.parse import urlencode import httpx import ujson @@ -200,7 +201,7 @@ def _graphql_url( if at: at = Timestamp(at) url_params["at"] = at.to_string() - url += "?" + "&".join([f"{key}={value}" for key, value in url_params.items()]) + url += "?" + urlencode(url_params) return url @@ -982,14 +983,19 @@ async def query_gql_query( if url_params: url_params_str = [] + url_params_dict = {} for key, value in url_params.items(): if isinstance(value, (list)): for item in value: - url_params_str.append(f"{key}={item}") + url_params_str.append((key, item)) else: - url_params_str.append(f"{key}={value}") + url_params_dict[key] = value - url += "?" + "&".join(url_params_str) + url += "?" + if url_params_dict: + url += urlencode(url_params_dict) + "&" + if url_params_str: + url += urlencode(url_params_str) payload = {} if variables: @@ -1988,14 +1994,19 @@ def query_gql_query( if url_params: url_params_str = [] + url_params_dict = {} for key, value in url_params.items(): if isinstance(value, (list)): for item in value: - url_params_str.append(f"{key}={item}") + url_params_str.append((key, item)) else: - url_params_str.append(f"{key}={value}") + url_params_dict[key] = value - url += "?" + "&".join(url_params_str) + url += "?" + if url_params_dict: + url += urlencode(url_params_dict) + "&" + if url_params_str: + url += urlencode(url_params_str) payload = {} if variables: diff --git a/infrahub_sdk/store.py b/infrahub_sdk/store.py index aace0a69..4bf5e0cb 100644 --- a/infrahub_sdk/store.py +++ b/infrahub_sdk/store.py @@ -24,7 +24,7 @@ class NodeStoreBase: """Internal Store for InfrahubNode objects. Often while creating a lot of new objects, - we need to save them in order to reuse them laterto associate them with another node for example. + we need to save them in order to reuse them later to associate them with another node for example. """ def __init__(self) -> None: diff --git a/pyproject.toml b/pyproject.toml index 3395cbb1..46aad3ab 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "infrahub-sdk" -version = "0.15.0a0" +version = "1.0.0" description = "Python Client to interact with Infrahub" authors = ["OpsMill "] readme = "README.md"