Metadata-Version: 2.4
Name: netherframe.backends.consul
Version: 0.3.0
Summary: Consul backend implementations for Netherframe
Author: Sourabh Cheedella
Author-email: Sourabh Cheedella <cheedella.sourabh@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Systems Administration
Requires-Dist: netherframe-core>=0.12.0,<1.0.0
Requires-Dist: py-consul>=1.8.0
Requires-Dist: pytest>=9.2.0 ; extra == 'dev'
Requires-Python: >=3.14
Project-URL: Homepage, https://netherframe.arsenal.sh
Project-URL: Repository, https://github.com/arsenal-sh/netherframe
Provides-Extra: dev
Description-Content-Type: text/markdown

# nf.backends.consul

Consul backend implementations for Netherframe Infrastructure as Code framework.

## Installation

```bash
pip install netherframe.backends.consul
```

The backend uses `py-consul`. If upgrading an environment that has `python-consul`
installed, remove the old distribution first: both packages install the `consul`
Python module. Reinstalling the backend restores any shared files removed with it:

```bash
python -m pip uninstall python-consul
python -m pip install --upgrade --force-reinstall netherframe.backends.consul
```

In this workspace, `uv sync` removes the old distribution and installs the replacement
from the updated lock file.

## Usage

```python
from nf.backends.consul import ConsulBackend, ConsulStateBackend

# For Terraform synthesis mode
backend = ConsulBackend(nf_scope=stack, address="consul.example.com:8500", path="terraform/myapp/state", scheme="https")

# For native execution mode
state_backend = ConsulStateBackend(address="consul.example.com:8500", path="terraform/myapp/state", access_token="your-consul-token")
```

## Features

- Consul KV-based state storage
- Compatible with Terraform's consul backend
- Support for ACL tokens
- State locking using Consul sessions
- Automatic session renewal and TTL management, and force-unlock by lock ID (`nf state force-unlock`)
- Conditional writes: a write replaces only the state version its run read (check-and-set on the ModifyIndex)
- Pre-apply checkpoints kept beside the state (`<path>.checkpoints/`)

## Real-server tests

The integration contract tests use a unique KV prefix per test and remove it afterward.
Point them at a test Consul server with KV and session permissions:

```bash
uv run pytest backends/netherframe.backends.consul/tests/test_consul_real_integration.py -n 0 \
  --nf-consul-test-address 127.0.0.1:8500
```

For an ACL-protected HTTPS endpoint, also give `--nf-consul-test-scheme https` and
`--nf-consul-test-token-file` (a file containing the ACL token), and set
`REQUESTS_CA_BUNDLE` to the trusted CA certificate file. The migration was validated
against Consul 1.22 over HTTP and HTTPS with ACL enforcement.
