Skip to content

Commit fe1d21e

Browse files
authored
Merge pull request #35 from Enapter/rnovatorov/http-api-rule-management
HTTP API: Rule Engine Client
2 parents 73de402 + 174be10 commit fe1d21e

40 files changed

Lines changed: 1228 additions & 57 deletions

conductor/tracks/rule_engine_management_20260302/index.md renamed to conductor/archive/rule_engine_management_20260302/index.md

File renamed without changes.

conductor/tracks/rule_engine_management_20260302/metadata.json renamed to conductor/archive/rule_engine_management_20260302/metadata.json

File renamed without changes.

conductor/tracks/rule_engine_management_20260302/plan.md renamed to conductor/archive/rule_engine_management_20260302/plan.md

File renamed without changes.

conductor/tracks/rule_engine_management_20260302/spec.md renamed to conductor/archive/rule_engine_management_20260302/spec.md

File renamed without changes.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Track rule_management_20260311 Context
2+
3+
- [Specification](./spec.md)
4+
- [Implementation Plan](./plan.md)
5+
- [Metadata](./metadata.json)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"track_id": "rule_management_20260311",
3+
"type": "feature",
4+
"status": "new",
5+
"created_at": "2026-03-11T12:00:00Z",
6+
"updated_at": "2026-03-11T12:00:00Z",
7+
"description": "Implement automation rule management using Enapter HTTP API for Rule Engine (Create, List, Get, Update, Enable, Disable, Delete)."
8+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Implementation Plan: Rule Management
2+
3+
This plan outlines the implementation of Rule management (create, list, get, update, enable/disable, delete) in the Enapter HTTP API Rule Engine client.
4+
5+
## Phase 1: Models and Foundation [checkpoint: c888a5d]
6+
7+
- [x] Task: Define `Rule`, `RuleScript`, and `RuntimeVersion`, and `RuleState` data models
8+
- [x] Create `src/enapter/http/api/rule_engine/rule.py`, `src/enapter/http/api/rule_engine/rule_script.py`, `src/enapter/http/api/rule_engine/runtime_version.py`, and `src/enapter/http/api/rule_engine/rule_state.py`
9+
- [x] Implement `Rule` and `RuleScript` dataclasses and `RuntimeVersion` and `RuleState` enums
10+
- [x] Implement `from_dto` and `to_dto` methods for all models
11+
- [x] Add unit tests for models in `tests/unit/test_http/test_api/test_rule_engine/test_rule.py`
12+
- [x] Task: Export models in `src/enapter/http/api/rule_engine/__init__.py`
13+
- [x] Task: Conductor - User Manual Verification 'Phase 1: Models and Foundation' (Protocol in workflow.md)
14+
15+
## Phase 2: Rule Management Implementation (Read Operations) [checkpoint: 6745120]
16+
17+
- [x] Task: Implement `List Rules` method
18+
- [x] Add `list_rules` method to `src/enapter/http/api/rule_engine/client.py`
19+
- [x] Write failing tests in `tests/unit/test_http/test_api/test_rule_engine/test_client.py`
20+
- [x] Implement method to pass tests
21+
- [x] Task: Implement `Get Rule` method
22+
- [x] Add `get_rule` method to `src/enapter/http/api/rule_engine/client.py`
23+
- [x] Write failing tests
24+
- [x] Implement method to pass tests
25+
- [x] Task: Conductor - User Manual Verification 'Phase 2: Rule Management Implementation (Read Operations)' (Protocol in workflow.md)
26+
27+
## Phase 3: Rule Management Implementation (Write Operations) [checkpoint: 15e657c]
28+
29+
- [x] Task: Implement `Create Rule` method
30+
- [x] Add `create_rule` method to `src/enapter/http/api/rule_engine/client.py`
31+
- [x] Write failing tests (including base64 encoding check)
32+
- [x] Implement method to pass tests
33+
- [x] Task: Implement `Update Rule` (slug) method
34+
- [x] Add `update_rule` method to `src/enapter/http/api/rule_engine/client.py`
35+
- [x] Write failing tests
36+
- [x] Implement method to pass tests
37+
- [x] Task: Implement `Update Rule Script` method
38+
- [x] Add `update_rule_script` method to `src/enapter/http/api/rule_engine/client.py`
39+
- [x] Write failing tests
40+
- [x] Implement method to pass tests
41+
- [x] Task: Implement `Delete Rule` method
42+
- [x] Add `delete_rule` method to `src/enapter/http/api/rule_engine/client.py`
43+
- [x] Write failing tests
44+
- [x] Implement method to pass tests
45+
- [x] Task: Conductor - User Manual Verification 'Phase 3: Rule Management Implementation (Write Operations)' (Protocol in workflow.md)
46+
47+
## Phase 4: Rule State Management [checkpoint: 43df5d0]
48+
49+
- [x] Task: Implement `Enable Rule` and `Disable Rule` methods
50+
- [x] Add `enable_rule` and `disable_rule` methods to `src/enapter/http/api/rule_engine/client.py`
51+
- [x] Write failing tests
52+
- [x] Implement methods to pass tests
53+
- [x] Task: Conductor - User Manual Verification 'Phase 4: Rule State Management' (Protocol in workflow.md)
54+
55+
## Phase 5: Integration and Finalization [checkpoint: 90987b4]
56+
57+
- [x] Task: Add integration tests for all new Rule management methods
58+
- [x] Create `tests/integration/test_rule_engine_management.py` (or similar)
59+
- [x] Verify full flows against a mock or real environment if possible
60+
- [x] Task: Final code quality check (linting, coverage)
61+
- [x] Task: Conductor - User Manual Verification 'Phase 5: Integration and Finalization' (Protocol in workflow.md)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Specification: Rule Management
2+
3+
## Overview
4+
This track implements comprehensive rule management within the Enapter HTTP API Rule Engine client. This includes creating, listing, retrieving, updating, enabling/disabling, and deleting rules via the Enapter Cloud HTTP API.
5+
6+
## Functional Requirements
7+
The `enapter.http.api.rule_engine.Client` will be extended with methods to:
8+
1. **Create Rule**: `POST` a new rule with a `slug`, `script` (code and runtime version), and optional `disabled` flag.
9+
2. **List Rules**: `GET` all rules for a specific site or the default site.
10+
3. **Get Rule**: `GET` a specific rule by its ID.
11+
4. **Update Rule**: `PATCH` an existing rule's `slug`.
12+
5. **Update Rule Script**: `POST` a new `script` (code and runtime version) for an existing rule.
13+
6. **Enable Rule**: `POST` to enable a rule.
14+
7. **Disable Rule**: `POST` to disable a rule.
15+
8. **Delete Rule**: `DELETE` a rule by its ID.
16+
17+
## Data Model: Rule
18+
A `Rule` model will be introduced in `src/enapter/http/api/rule_engine/rule.py`, including:
19+
- `id`: Unique identifier for the rule.
20+
- `slug`: Human-readable identifier.
21+
- `disabled`: Boolean indicating if the rule is disabled.
22+
- `state`: Execution state (e.g., `STARTED`, `STOPPED`).
23+
- `script`: An object containing:
24+
- `code`: The rule's script code (base64 encoded string).
25+
- `runtime_version`: The runtime environment version (`V1` or `V3`).
26+
27+
## Technical Requirements
28+
- **Integration**: Methods will be added to `enapter.http.api.rule_engine.Client`.
29+
- **Async Strategy**: All API calls will be asynchronous using `httpx.AsyncClient`.
30+
- **Error Handling**: Use the existing `enapter.http.api.check_error` mechanism which raises generic HTTP client exceptions for failed requests.
31+
- **Base64 Encoding**: The client should handle base64 encoding/decoding of the rule script code for ease of use.
32+
- **Modern Python**: Adhere to Python 3.11+ patterns and typing.
33+
34+
## Acceptance Criteria
35+
- [ ] Users can create a rule by providing a slug and script code.
36+
- [ ] Users can list all rules for a site.
37+
- [ ] Users can retrieve a specific rule by ID.
38+
- [ ] Users can update a rule's slug.
39+
- [ ] Users can update a rule's script code and runtime version.
40+
- [ ] Users can enable and disable a rule.
41+
- [ ] Users can delete a rule.
42+
- [ ] All new methods are fully tested with unit and integration tests.
43+
44+
## Out of Scope
45+
- Management of Rule Engine itself (suspend/resume/get state) is already implemented and remains unchanged.
46+
- Frontend/CLI integration for these new methods.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Track rule_management_cli_20260317 Context
2+
3+
- [Specification](./spec.md)
4+
- [Implementation Plan](./plan.md)
5+
- [Metadata](./metadata.json)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"track_id": "rule_management_cli_20260317",
3+
"type": "feature",
4+
"status": "new",
5+
"created_at": "2026-03-17T12:00:00Z",
6+
"updated_at": "2026-03-17T12:00:00Z",
7+
"description": "rule management cli"
8+
}

0 commit comments

Comments
 (0)