Skip to content
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
20 changes: 19 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang

<!-- towncrier release notes start -->

## [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
Expand All @@ -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

Expand Down
1 change: 0 additions & 1 deletion changelog/+8dff6891.removed.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog/+connection-timeout.fixed.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog/102.fixed.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog/25.added.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog/64.fixed.md

This file was deleted.

13 changes: 8 additions & 5 deletions infrahub_sdk/branch.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -55,14 +56,16 @@
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()

Check warning on line 62 in infrahub_sdk/branch.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/branch.py#L59-L62

Added lines #L59 - L62 were not covered by tests
if time_from:
url += f"&time_from={time_from}"
url_params["time_from"] = time_from

Check warning on line 64 in infrahub_sdk/branch.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/branch.py#L64

Added line #L64 was not covered by tests
if time_to:
url += f"&time_to={time_to}"
url_params["time_to"] = time_to

Check warning on line 66 in infrahub_sdk/branch.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/branch.py#L66

Added line #L66 was not covered by tests

return url
return url + urlencode(url_params)

Check warning on line 68 in infrahub_sdk/branch.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/branch.py#L68

Added line #L68 was not covered by tests


class InfrahubBranchManager(InfraHubBranchManagerBase):
Expand Down
25 changes: 18 additions & 7 deletions infrahub_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Union,
overload,
)
from urllib.parse import urlencode

import httpx
import ujson
Expand Down Expand Up @@ -200,7 +201,7 @@
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)

Check warning on line 204 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L204

Added line #L204 was not covered by tests

return url

Expand Down Expand Up @@ -515,7 +516,7 @@
nodes.append(node)

if prefetch_relationships:
await node._process_relationships(

Check warning on line 519 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L519

Added line #L519 was not covered by tests
node_data=item, branch=branch, related_nodes=related_nodes, timeout=timeout
)

Expand Down Expand Up @@ -982,14 +983,19 @@

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))

Check warning on line 990 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L990

Added line #L990 was not covered by tests
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)

Check warning on line 998 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L998

Added line #L998 was not covered by tests

payload = {}
if variables:
Expand Down Expand Up @@ -1435,7 +1441,7 @@
**kwargs: Any,
) -> Union[InfrahubNodeSync, SchemaTypeSync]:
branch = branch or self.default_branch
schema = self.schema.get(kind=kind, branch=branch, timeout=timeout)

Check warning on line 1444 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L1444

Added line #L1444 was not covered by tests

if not data and not kwargs:
raise ValueError("Either data or a list of keywords but be provided")
Expand Down Expand Up @@ -1644,7 +1650,7 @@
nodes.append(node)

if prefetch_relationships:
node._process_relationships(node_data=item, branch=branch, related_nodes=related_nodes, timeout=timeout)

Check warning on line 1653 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L1653

Added line #L1653 was not covered by tests

return ProcessRelationsNodeSync(nodes=nodes, related_nodes=related_nodes)

Expand Down Expand Up @@ -1988,14 +1994,19 @@

if url_params:
url_params_str = []
url_params_dict = {}

Check warning on line 1997 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L1997

Added line #L1997 was not covered by tests
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))

Check warning on line 2001 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L2001

Added line #L2001 was not covered by tests
else:
url_params_str.append(f"{key}={value}")
url_params_dict[key] = value

Check warning on line 2003 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L2003

Added line #L2003 was not covered by tests

url += "?" + "&".join(url_params_str)
url += "?"

Check warning on line 2005 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L2005

Added line #L2005 was not covered by tests
if url_params_dict:
url += urlencode(url_params_dict) + "&"

Check warning on line 2007 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L2007

Added line #L2007 was not covered by tests
if url_params_str:
url += urlencode(url_params_str)

Check warning on line 2009 in infrahub_sdk/client.py

View check run for this annotation

Codecov / codecov/patch

infrahub_sdk/client.py#L2009

Added line #L2009 was not covered by tests

payload = {}
if variables:
Expand Down
2 changes: 1 addition & 1 deletion infrahub_sdk/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
readme = "README.md"
Expand Down
Loading