@@ -130,6 +130,31 @@ GitHub Actions runs on all branches and PRs:
130130- Backend tests: ` pytest benchmesh-serial-service/tests `
131131- Frontend tests: ` npx vitest run --reporter=dot `
132132
133+ ## API Naming Convention & Security
134+
135+ The API implements a ** secure method resolution system** that prevents arbitrary method execution:
136+
137+ ### GET Requests (Query)
138+ Partial method names are ** strictly** resolved to ` query_* ` methods only:
139+ - ` GET /instruments/PSU/device-1/1/voltage ` → calls ` driver.query_voltage(1) `
140+ - ` GET /instruments/DMM/device-2/1/current ` → calls ` driver.query_current(1) `
141+
142+ ### POST Requests (Set)
143+ Partial method names are ** strictly** resolved to ` set_* ` methods only:
144+ - ` POST /instruments/PSU/device-1/1/current/2.5 ` → calls ` driver.set_current(1, 2.5) `
145+ - ` POST /instruments/ELL/device-3/1/mode/CURR ` → calls ` driver.set_mode(1, "CURR") `
146+
147+ ### Security Features
148+ 1 . ** No Arbitrary Method Execution** : Only methods with ` query_ ` or ` set_ ` prefixes can be called via API
149+ 2 . ** No Private Method Access** : Methods like ` _internal_method() ` or ` __init__() ` cannot be accessed
150+ 3 . ** HTTP Verb Enforcement** : GET only allows query methods, POST only allows set methods
151+ 4 . ** Protection Against Mistakes** : Cannot accidentally call setters with GET or queries with POST
152+
153+ ** Example of what is NOT allowed (security protection):**
154+ - ` GET /instruments/PSU/device-1/1/poll_status ` → ** Rejected** (no query_poll_status)
155+ - ` POST /instruments/PSU/device-1/1/_private_method/value ` → ** Rejected** (private method)
156+ - ` GET /instruments/PSU/device-1/1/set_voltage ` → ** Rejected** (setter on GET request)
157+
133158## Configuration System
134159
135160Devices are defined in ` config.yaml ` (YAML v1 schema):
@@ -160,12 +185,19 @@ Manifest aliases in `serial_manager.py` and `manifest_resolver.py` map legacy dr
1601852. Create `driver.py` with a class exposing :
161186 - ` query_identify()` → returns IDN string
162187 - ` poll_status()` → returns status dict
163- - Device-specific control methods
188+ - Device-specific control methods following naming convention :
189+ - Read methods : ` query_voltage()` , `query_current()`, `query_status()`, etc.
190+ - Write methods : ` set_voltage()` , `set_current()`, `set_mode()`, etc.
1641913. Create `manifest.json` defining models, classes, polling config, and EOL characters
1651924. Update `drivers/classes.json` if adding new 3-letter class codes
1661935. Add driver instantiation logic to `driver_factory.py` if needed
1671946. Create tests in `tests/` using pytest and mock serial communication
168195
196+ **Driver Naming Convention:**
197+ - **Query methods** (read): prefix with `query_` (e.g., `query_voltage`, `query_current`)
198+ - **Setter methods** (write): prefix with `set_` (e.g., `set_voltage`, `set_current`)
199+ - This enables the API's smart resolution : GET `/voltage` → `query_voltage()`, POST `/current/2.5` → `set_current()`
200+
169201Driver should accept `transport : SerialTransport` in constructor and use it for all communication.
170202
171203# # Key Modules
@@ -176,7 +208,9 @@ Driver should accept `transport: SerialTransport` in constructor and use it for
176208- `poll_worker.py` : DeviceWorker runs per-device polling loop in dedicated thread
177209- `registry.py` : DeviceRegistry thread-safe storage for device IDN and status
178210- `transport.py` : SerialTransport wraps pyserial with EOL handling
179- - `api.py` : FastAPI app with endpoints `/status`, `/instruments`, `/api/call`, and WebSocket `/ws`
211+ - `api.py` : FastAPI app with endpoints `/status`, `/instruments`, instrument control endpoints, and WebSocket `/ws`
212+ - Implements **secure** method resolution : GET requests resolve `voltage` → `query_voltage`, POST requests resolve `current` → `set_current`
213+ - Prevents arbitrary method execution - only `query_*` and `set_*` methods can be called via API
180214- `connection.py` : DeviceConnection tracks connection state per device
181215- `reconnect.py` : ReconnectPolicy implements backoff strategy
182216
0 commit comments