Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
cdfb316
Use new mutation names for getting pool resources (#465)
gmazoyer Jul 17, 2025
937eaae
Add protocols for Infrahub 1.4
ogenstad Aug 4, 2025
021a378
Merge pull request #488 from opsmill/pog-infrahub-develop-protocols
ogenstad Aug 4, 2025
760cf3a
Merge develop into infrahub-develop (#489)
gmazoyer Aug 7, 2025
f9be10d
Support infrahub.yml or infrahub.yaml configuration files
petercrocker Aug 10, 2025
06905fa
ruff
petercrocker Aug 10, 2025
c1d1bd4
Merge pull request #496 from opsmill/develop
ajtmccarty Aug 13, 2025
bf9571b
Merge pull request #492 from opsmill/pmc-yaml-2
dgarros Aug 24, 2025
5349382
Merge pull request #507 from opsmill/develop
ogenstad Aug 25, 2025
0a1d3eb
Merge pull request #530 from opsmill/develop
dgarros Sep 14, 2025
cb4c330
Merge branch 'develop' into 'infrahub-develop' with resolved conflicts
ogenstad Oct 7, 2025
2a0c092
Merge pull request #566 from opsmill/pog-infrahub-develop-merge-confl…
ogenstad Oct 7, 2025
f7b39f0
IHS-163 Add required change for IFC-1820 (display_label) (#556)
gmazoyer Oct 7, 2025
a9f9740
bump version to v1.15.0b0
wvandeun Oct 7, 2025
cea3266
Merge pull request #568 from opsmill/wvd-20251007-prep-release-1.15.0b0
wvandeun Oct 7, 2025
6610115
Merge pull request #570 from opsmill/develop
ogenstad Oct 8, 2025
f238ec6
Merge pull request #575 from opsmill/develop
dgarros Oct 11, 2025
0f3b29b
Merge pull request #576 from opsmill/develop
dgarros Oct 13, 2025
0f5a1df
Extend GeneratorDefinition with flags to control execution
dgarros Oct 14, 2025
a6c6ac6
Merge pull request #578 from opsmill/dga-20250909-generator-flags
dgarros Oct 14, 2025
7a7104c
bump version to 1.15.0b1
wvandeun Oct 20, 2025
2dcc1db
Merge pull request #584 from opsmill/wvd-20251020-prep-release-1.15.0b1
wvandeun Oct 20, 2025
7b7612d
Process schema deprecation warnings
ogenstad Oct 17, 2025
4c8134d
Merge pull request #582 from opsmill/pog-process-schema-deprecations
ogenstad Oct 24, 2025
c50ee21
Merge pull request #587 from opsmill/develop
ogenstad Oct 29, 2025
9f1a0f8
Replace strategy in object file with parameters section (#585)
dgarros Nov 3, 2025
115333e
Merge pull request #598 from opsmill/develop
ogenstad Nov 3, 2025
9fb8d3c
Add `graph_version` and `status` to branch (#600)
gmazoyer Nov 6, 2025
a151dc8
Merge pull request #607 from opsmill/develop
fatih-acar Nov 7, 2025
f43c73a
Merge pull request #612 from opsmill/develop
fatih-acar Nov 10, 2025
bb1acc1
fix: update infrahub-testcontainers to 1.5.0b2
fatih-acar Nov 10, 2025
8004be4
Merge pull request #613 from opsmill/infrahub-develop
ogenstad Nov 10, 2025
f2c71b1
Release 1.15.0
ogenstad Nov 10, 2025
88c7907
Merge pull request #615 from opsmill/pog-release-1.15.0
ogenstad Nov 10, 2025
3ff56e8
Configure vale to ignore toml files
ogenstad Nov 10, 2025
d9ead2d
Merge pull request #617 from opsmill/pog-vale-ignore-toml
ogenstad Nov 11, 2025
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 .vale.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,10 @@ BasedOnStyles = Infrahub
;(```.*?```\n) to ignore code block in .mdx
BlockIgnores = (?s) *((import.*?\n)|(```.*?```\n))

[*.toml]
# Ignore all rules for toml files, to prevent false positives
# in files like pyproject.toml
BasedOnStyles =

[*]
BasedOnStyles = Infrahub
35 changes: 35 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,41 @@ This project uses [*towncrier*](https://towncrier.readthedocs.io/) and the chang

<!-- towncrier release notes start -->

## [1.15.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.15.0) - 2025-11-10

### Added

- Add `create_diff` method to create a diff summary between two timestamps
Update `get_diff_summary` to accept optional time range parameters ([#529](https://github.com/opsmill/infrahub-sdk-python/issues/529))
- Add the ability to perform range expansions in object files. This feature allows users to define patterns in string fields that will be expanded into multiple objects, facilitating bulk object creation and management. The implementation includes validation to ensure that all expanded lists have the same length, preventing inconsistencies. Documentation has been updated to explain how to use this feature, including examples of valid and invalid configurations. ([#560](https://github.com/opsmill/infrahub-sdk-python/issues/560))
- Add `convert_object_type` method to allow converting an object to another type.
- Add `graph_version` and `status` properties to `Branch`
- Add `infrahubctl graphql` commands to export schema and generate Pydantic types from GraphQL queries
- Added deprecation warnings when loading or checking schemas

### Changed

- Deprecate the use of `raise_for_error=False` across several methods, using a try/except pattern is preferred. ([#493](https://github.com/opsmill/infrahub-sdk-python/issues/493))

### Fixed

- Respect default branch for client.query_gql_query() and client.set_context_properties() ([#236](https://github.com/opsmill/infrahub-sdk-python/issues/236))
- Fix branch creation with the sync client while setting `wait_until_completion=False` ([#374](https://github.com/opsmill/infrahub-sdk-python/issues/374))
- Replaced the `Sync` word in the protocol schema name so that the correct kind can be gotten from the cache ([#380](https://github.com/opsmill/infrahub-sdk-python/issues/380))
- Fix `infrahubctl info` command when run as an anonymous user ([#398](https://github.com/opsmill/infrahub-sdk-python/issues/398))
- JsonDecodeError now includes server response content in error message when JSON decoding fails, providing better debugging information for non-JSON server responses. ([#473](https://github.com/opsmill/infrahub-sdk-python/issues/473))
- Allow unsetting optional relationship of cardinality one by setting its value to `None` ([#479](https://github.com/opsmill/infrahub-sdk-python/issues/479))
- Bump docs dependencies ([#519](https://github.com/opsmill/infrahub-sdk-python/issues/519))
- Fix branch handling in `_run_transform` and `execute_graphql_query` functions in Infrahubctl to use environment variables for branch management. ([#535](https://github.com/opsmill/infrahub-sdk-python/issues/535))
- Allow the ability to clear optional attributes by setting them to None if they have been mutated by the user. ([#549](https://github.com/opsmill/infrahub-sdk-python/issues/549))
- Disable rich console print markup causing regex reformatting ([#565](https://github.com/opsmill/infrahub-sdk-python/issues/565))
- - Fixed issue with improperly escaped special characters in `hfid` fields and other string values in GraphQL mutations by implementing proper JSON-style string escaping

### Housekeeping

- Handle error gracefully when loading schema instead of failing with an exception ([#464](https://github.com/opsmill/infrahub-sdk-python/issues/464))
- Replace toml package with tomllib and tomli optionally for when Python version is less than 3.11 ([#528](https://github.com/opsmill/infrahub-sdk-python/issues/528))

## [1.14.0](https://github.com/opsmill/infrahub-sdk-python/tree/v1.14.0) - 2025-08-26

### Added
Expand Down
1 change: 0 additions & 1 deletion changelog/+convert-object-type.added.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog/+escape-hfid.fixed.md

This file was deleted.

1 change: 0 additions & 1 deletion changelog/+gql-command.added.md

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

1 change: 0 additions & 1 deletion changelog/464.housekeeping.md

This file was deleted.

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

This file was deleted.

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

This file was deleted.

1 change: 0 additions & 1 deletion changelog/493.changed.md

This file was deleted.

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

This file was deleted.

1 change: 0 additions & 1 deletion changelog/528.housekeeping.md

This file was deleted.

2 changes: 0 additions & 2 deletions changelog/529.added.md

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

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

This file was deleted.

30 changes: 17 additions & 13 deletions docs/docs/python-sdk/topics/object_file.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,23 @@ apiVersion: infrahub.app/v1
kind: Object
spec:
kind: <NamespaceName>
strategy: <normal|range_expand> # Optional, defaults to normal
parameters:
expand_range: <boolean> # Optional, defaults to false
data:
- [...]
```

> Multiple documents in a single YAML file are also supported, each document will be loaded separately. Documents are separated by `---`

### Data Processing Strategies
### Data Processing Parameters

The `strategy` field controls how the data in the object file is processed before loading into Infrahub:
The `parameters` field controls how the data in the object file is processed before loading into Infrahub:

| Strategy | Description | Default |
|----------|-------------|---------|
| `normal` | No data manipulation is performed. Objects are loaded as-is. | Yes |
| `range_expand` | Range patterns (e.g., `[1-5]`) in string fields are expanded into multiple objects. | No |
| Parameter | Description | Default |
|-----------|-------------|---------|
| `expand_range` | When set to `true`, range patterns (e.g., `[1-5]`) in string fields are expanded into multiple objects. | `false` |

When `strategy` is not specified, it defaults to `normal`.
When `expand_range` is not specified, it defaults to `false`.

### Relationship of cardinality one

Expand Down Expand Up @@ -210,15 +210,16 @@ Metadata support is planned for future releases. Currently, the Object file does

## Range Expansion in Object Files

The Infrahub Python SDK supports **range expansion** for string fields in object files when the `strategy` is set to `range_expand`. This feature allows you to specify a range pattern (e.g., `[1-5]`) in any string value, and the SDK will automatically expand it into multiple objects during validation and processing.
The Infrahub Python SDK supports **range expansion** for string fields in object files when the `parameters > expand_range` is set to `true`. This feature allows you to specify a range pattern (e.g., `[1-5]`) in any string value, and the SDK will automatically expand it into multiple objects during validation and processing.

```yaml
---
apiVersion: infrahub.app/v1
kind: Object
spec:
kind: BuiltinLocation
strategy: range_expand # Enable range expansion
parameters:
expand_range: true # Enable range expansion
data:
- name: AMS[1-3]
type: Country
Expand All @@ -237,7 +238,8 @@ spec:
```yaml
spec:
kind: BuiltinLocation
strategy: range_expand
parameters:
expand_range: true
data:
- name: AMS[1-3]
type: Country
Expand All @@ -259,7 +261,8 @@ This will expand to:
```yaml
spec:
kind: BuiltinLocation
strategy: range_expand
parameters:
expand_range: true
data:
- name: AMS[1-3]
description: Datacenter [A-C]
Expand Down Expand Up @@ -287,7 +290,8 @@ If you use ranges of different lengths in multiple fields:
```yaml
spec:
kind: BuiltinLocation
strategy: range_expand
parameters:
expand_range: true
data:
- name: AMS[1-3]
description: "Datacenter [10-15]"
Expand Down
12 changes: 12 additions & 0 deletions infrahub_sdk/branch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import warnings
from enum import Enum
from typing import TYPE_CHECKING, Any, Literal, overload
from urllib.parse import urlencode

Expand All @@ -14,13 +15,22 @@
from .client import InfrahubClient, InfrahubClientSync


class BranchStatus(str, Enum):
OPEN = "OPEN"
NEED_REBASE = "NEED_REBASE"
NEED_UPGRADE_REBASE = "NEED_UPGRADE_REBASE"
DELETING = "DELETING"


class BranchData(BaseModel):
id: str
name: str
description: str | None = None
sync_with_git: bool
is_default: bool
has_schema_changes: bool
graph_version: int | None = None
status: BranchStatus = BranchStatus.OPEN
origin_branch: str | None = None
branched_from: str

Expand All @@ -34,6 +44,8 @@ class BranchData(BaseModel):
"is_default": None,
"sync_with_git": None,
"has_schema_changes": None,
"graph_version": None,
"status": None,
}

BRANCH_DATA_FILTER = {"@filters": {"name": "$branch_name"}}
Expand Down
32 changes: 8 additions & 24 deletions infrahub_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,8 @@ def _build_ip_address_allocation_query(

return Mutation(
name="AllocateIPAddress",
mutation="IPAddressPoolGetResource",
query={
"ok": None,
"node": {
"id": None,
"kind": None,
"identifier": None,
"display_label": None,
},
},
mutation="InfrahubIPAddressPoolGetResource",
query={"ok": None, "node": {"id": None, "kind": None, "identifier": None, "display_label": None}},
input_data={"data": input_data},
)

Expand Down Expand Up @@ -318,16 +310,8 @@ def _build_ip_prefix_allocation_query(

return Mutation(
name="AllocateIPPrefix",
mutation="IPPrefixPoolGetResource",
query={
"ok": None,
"node": {
"id": None,
"kind": None,
"identifier": None,
"display_label": None,
},
},
mutation="InfrahubIPPrefixPoolGetResource",
query={"ok": None, "node": {"id": None, "kind": None, "identifier": None, "display_label": None}},
input_data={"data": input_data},
)

Expand Down Expand Up @@ -1421,7 +1405,7 @@ async def allocate_next_ip_address(
raise ValueError("resource_pool is not an IP address pool")

branch = branch or self.default_branch
mutation_name = "IPAddressPoolGetResource"
mutation_name = "InfrahubIPAddressPoolGetResource"

query = self._build_ip_address_allocation_query(
resource_pool_id=resource_pool.id,
Expand Down Expand Up @@ -1573,7 +1557,7 @@ async def allocate_next_ip_prefix(
raise ValueError("resource_pool is not an IP prefix pool")

branch = branch or self.default_branch
mutation_name = "IPPrefixPoolGetResource"
mutation_name = "InfrahubIPPrefixPoolGetResource"

query = self._build_ip_prefix_allocation_query(
resource_pool_id=resource_pool.id,
Expand Down Expand Up @@ -2659,7 +2643,7 @@ def allocate_next_ip_address(
raise ValueError("resource_pool is not an IP address pool")

branch = branch or self.default_branch
mutation_name = "IPAddressPoolGetResource"
mutation_name = "InfrahubIPAddressPoolGetResource"

query = self._build_ip_address_allocation_query(
resource_pool_id=resource_pool.id,
Expand Down Expand Up @@ -2811,7 +2795,7 @@ def allocate_next_ip_prefix(
raise ValueError("resource_pool is not an IP prefix pool")

branch = branch or self.default_branch
mutation_name = "IPPrefixPoolGetResource"
mutation_name = "InfrahubIPPrefixPoolGetResource"

query = self._build_ip_prefix_allocation_query(
resource_pool_id=resource_pool.id,
Expand Down
3 changes: 3 additions & 0 deletions infrahub_sdk/ctl/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ async def list_branch(_: str = CONFIG_PARAM) -> None:
table.add_column("Sync with Git")
table.add_column("Has Schema Changes")
table.add_column("Is Default")
table.add_column("Status")

# identify the default branch and always print it first
default_branch = [branch for branch in branches.values() if branch.is_default][0]
Expand All @@ -57,6 +58,7 @@ async def list_branch(_: str = CONFIG_PARAM) -> None:
"[green]True" if default_branch.sync_with_git else "[#FF7F50]False",
"[green]True" if default_branch.has_schema_changes else "[#FF7F50]False",
"[green]True" if default_branch.is_default else "[#FF7F50]False",
default_branch.status,
)

for branch in branches.values():
Expand All @@ -71,6 +73,7 @@ async def list_branch(_: str = CONFIG_PARAM) -> None:
"[green]True" if branch.sync_with_git else "[#FF7F50]False",
"[green]True" if default_branch.has_schema_changes else "[#FF7F50]False",
"[green]True" if branch.is_default else "[#FF7F50]False",
branch.status,
)

console.print(table)
Expand Down
5 changes: 2 additions & 3 deletions infrahub_sdk/ctl/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
from rich.console import Console
from rich.logging import RichHandler

from ..ctl import config
from ..ctl.client import initialize_client
from ..ctl.exceptions import QueryNotFoundError
from ..ctl.repository import get_repository_config
from ..ctl.repository import find_repository_config_file, get_repository_config
from ..ctl.utils import catch_exception, execute_graphql_query
from ..exceptions import ModuleImportError

Expand Down Expand Up @@ -59,7 +58,7 @@ def run(
FORMAT = "%(message)s"
logging.basicConfig(level=log_level, format=FORMAT, datefmt="[%X]", handlers=[RichHandler()])

repository_config = get_repository_config(Path(config.INFRAHUB_REPO_CONFIG_FILE))
repository_config = get_repository_config(find_repository_config_file())

if list_available:
list_checks(repository_config=repository_config)
Expand Down
9 changes: 4 additions & 5 deletions infrahub_sdk/ctl/cli_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

from .. import __version__ as sdk_version
from ..async_typer import AsyncTyper
from ..ctl import config
from ..ctl.branch import app as branch_app
from ..ctl.check import run as run_check
from ..ctl.client import initialize_client, initialize_client_sync
Expand All @@ -31,7 +30,7 @@
from ..ctl.object import app as object_app
from ..ctl.render import list_jinja2_transforms, print_template_errors
from ..ctl.repository import app as repository_app
from ..ctl.repository import get_repository_config
from ..ctl.repository import find_repository_config_file, get_repository_config
from ..ctl.schema import app as schema_app
from ..ctl.task import app as task_app
from ..ctl.transform import list_transforms
Expand Down Expand Up @@ -263,7 +262,7 @@ async def render(
"""Render a local Jinja2 Transform for debugging purpose."""

variables_dict = parse_cli_vars(variables)
repository_config = get_repository_config(Path(config.INFRAHUB_REPO_CONFIG_FILE))
repository_config = get_repository_config(find_repository_config_file())

if list_available or not transform_name:
list_jinja2_transforms(config=repository_config)
Expand All @@ -273,7 +272,7 @@ async def render(
try:
transform_config = repository_config.get_jinja2_transform(name=transform_name)
except KeyError as exc:
console.print(f'[red]Unable to find "{transform_name}" in {config.INFRAHUB_REPO_CONFIG_FILE}')
console.print(f'[red]Unable to find "{transform_name}" in repository config file')
list_jinja2_transforms(config=repository_config)
raise typer.Exit(1) from exc

Expand Down Expand Up @@ -313,7 +312,7 @@ def transform(
"""Render a local transform (TransformPython) for debugging purpose."""

variables_dict = parse_cli_vars(variables)
repository_config = get_repository_config(Path(config.INFRAHUB_REPO_CONFIG_FILE))
repository_config = get_repository_config(find_repository_config_file())

if list_available or not transform_name:
list_transforms(config=repository_config)
Expand Down
1 change: 1 addition & 0 deletions infrahub_sdk/ctl/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
DEFAULT_CONFIG_FILE = "infrahubctl.toml"
ENVVAR_CONFIG_FILE = "INFRAHUBCTL_CONFIG"
INFRAHUB_REPO_CONFIG_FILE = ".infrahub.yml"
INFRAHUB_REPO_CONFIG_FILE_ALT = ".infrahub.yaml"


class Settings(BaseSettings):
Expand Down
Loading