Commit 634fa94
authored
fix & impr (core + hql + cli): gateway permissions checking, cli rendering issues, default values for edges and vecs, custom return structures (#692)
## Description
<!-- Provide a brief description of the changes in this PR -->
## Related Issues
<!-- Link to any related issues using #issue_number -->
Closes #
## Checklist when merging to main
<!-- Mark items with "x" when completed -->
- [ ] No compiler warnings (if applicable)
- [ ] Code is formatted with `rustfmt`
- [ ] No useless or dead code (if applicable)
- [ ] Code is easy to understand
- [ ] Doc comments are used for all functions, enums, structs, and
fields (where appropriate)
- [ ] All tests pass
- [ ] Performance has not regressed (assuming change was not to fix a
bug)
- [ ] Version number has been updated in `helix-cli/Cargo.toml` and
`helixdb/Cargo.toml`
## Additional Notes
<!-- Add any additional information that would be helpful for reviewers
-->
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR merges the `dev` branch into `main`, introducing API key
verification, vector database enhancements, query generator
improvements, and various bug fixes.
## Major Changes
- **API Key Authentication**: Added optional API key verification using
SHA-256 hashing and constant-time comparison (feature-gated with
`api-key` flag)
- **Vector Core Enhancements**: Implemented `get_all_vectors` method
with level filtering and improved error messages
- **Query Generator**: Enhanced object literal construction, nested
struct handling, and closure variable resolution for complex query
patterns
- **Builtin Handlers**: Updated to use arena allocators for improved
memory management
- **Test Coverage**: Added comprehensive integration tests for API key
verification
## Issues Found
- **Critical**: `gateway.rs:178` uses `.unwrap()` on `api_key_hash`
which could panic if the field is unexpectedly None (though this should
be prevented by request validation when the feature is enabled)
<details><summary><h3>Important Files Changed</h3></summary>
File Analysis
| Filename | Score | Overview |
|----------|-------|----------|
| helix-db/src/helix_gateway/key_verification.rs | 4/5 | New API key
verification module with constant-time comparison using `subtle` crate,
comprehensive test coverage |
| helix-db/src/helix_gateway/gateway.rs | 3/5 | Added API key
verification to `post_handler`, uses `.unwrap()` which could panic,
follows OnceLock const block rule correctly |
| helix-db/src/protocol/request.rs | 5/5 | Added `api_key_hash` field to
Request struct, hashes incoming x-api-key header with SHA-256,
comprehensive tests added |
| helix-db/src/protocol/error.rs | 5/5 | Added `InvalidApiKey` error
variant with 403 HTTP status code, proper error handling and tests |
| helix-db/src/helix_engine/vector_core/vector_core.rs | 5/5 | Added
`get_all_vectors` method with optional level filtering, improved error
messages with uuid_str utility |
| helix-db/src/helixc/generator/queries.rs | 4/5 | Enhanced query
generator with object literal construction, nested struct handling, and
improved closure variable resolution |
</details>
</details>
<details><summary><h3>Sequence Diagram</h3></summary>
```mermaid
sequenceDiagram
participant Client
participant Gateway as Helix Gateway<br/>(post_handler)
participant Request as Request Extractor<br/>(from_request)
participant KeyVerify as key_verification<br/>(verify_key)
participant WorkerPool as Worker Pool
participant Response as HTTP Response
Client->>Gateway: POST /{query_name}<br/>Header: x-api-key
Gateway->>Request: Extract request
alt api-key feature enabled
Request->>Request: SHA-256 hash x-api-key header
Request->>Request: Store hash in api_key_hash field
else api-key feature disabled
Request->>Request: Set api_key_hash = None
end
Request->>Gateway: Return Request object
alt api-key feature enabled
Gateway->>Gateway: unwrap() api_key_hash
Gateway->>KeyVerify: verify_key(hash)
KeyVerify->>KeyVerify: Constant-time comparison<br/>with stored hash
alt Invalid key
KeyVerify->>Gateway: Err(InvalidApiKey)
Gateway->>Gateway: Log metrics event
Gateway->>Response: 403 Forbidden
Response->>Client: Error response
else Valid key
KeyVerify->>Gateway: Ok()
end
end
Gateway->>WorkerPool: process(request)
WorkerPool->>WorkerPool: Execute query
WorkerPool->>Gateway: Result
alt Success
Gateway->>Gateway: Log success metrics
Gateway->>Response: 200 OK with data
else Error
Gateway->>Gateway: Log error metrics
Gateway->>Response: Error status code
end
Response->>Client: HTTP Response
```
</details>
<!-- greptile_other_comments_section -->
**Context used:**
- Rule from `dashboard` - When using OnceLock::new() in Rust code, wrap
it in a `const { ... }` block to satisfy clippy lints....
([source](https://app.greptile.com/review/custom-context?memory=7f3c5d9b-5a5e-41cd-9e7e-1992245f637c))
<!-- /greptile_comment -->File tree
64 files changed
+3817
-474
lines changed- .github/workflows
- helix-cli
- src
- commands
- helix-container/src
- helix-db
- src
- helix_engine
- storage_core
- tests
- concurrency_tests
- traversal_tests
- traversal_core
- ops/source
- vector_core
- helix_gateway
- builtin
- tests
- helixc
- analyzer/methods
- generator
- protocol
- custom_serde
- utils
- hql-tests
- src
- tests
- cognee
- user_test_1
- where_filter
- metrics/src
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
64 files changed
+3817
-474
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
33 | 35 | | |
34 | 36 | | |
35 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
329 | 329 | | |
330 | 330 | | |
331 | 331 | | |
332 | | - | |
| 332 | + | |
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
| |||
371 | 371 | | |
372 | 372 | | |
373 | 373 | | |
374 | | - | |
| 374 | + | |
375 | 375 | | |
376 | 376 | | |
377 | 377 | | |
| |||
384 | 384 | | |
385 | 385 | | |
386 | 386 | | |
387 | | - | |
| 387 | + | |
| 388 | + | |
388 | 389 | | |
389 | 390 | | |
390 | 391 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
| 4 | + | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
9 | 24 | | |
10 | 25 | | |
11 | 26 | | |
| |||
233 | 248 | | |
234 | 249 | | |
235 | 250 | | |
236 | | - | |
237 | | - | |
| 251 | + | |
238 | 252 | | |
239 | 253 | | |
240 | 254 | | |
| |||
302 | 316 | | |
303 | 317 | | |
304 | 318 | | |
305 | | - | |
| 319 | + | |
306 | 320 | | |
307 | 321 | | |
308 | 322 | | |
309 | 323 | | |
310 | 324 | | |
311 | | - | |
| 325 | + | |
| 326 | + | |
312 | 327 | | |
313 | 328 | | |
314 | 329 | | |
| |||
323 | 338 | | |
324 | 339 | | |
325 | 340 | | |
| 341 | + | |
326 | 342 | | |
327 | 343 | | |
328 | 344 | | |
| |||
332 | 348 | | |
333 | 349 | | |
334 | 350 | | |
335 | | - | |
| 351 | + | |
| 352 | + | |
336 | 353 | | |
337 | 354 | | |
338 | 355 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
7 | | - | |
| 6 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
| 61 | + | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| |||
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
76 | | - | |
| 78 | + | |
77 | 79 | | |
78 | 80 | | |
79 | 81 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 87 | + | |
0 commit comments