Repository navigation
feat: data source connector_id GET - #15265
whitepicker wants to merge 5 commits into
Conversation
|
Caution Review failedFailed to post review comments Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThis PR adds connector GET and PATCH endpoint implementations to the Go API server, updates build infrastructure to recognize PCRE2 shared libraries, and fixes error formatting in LLM service. ChangesPCRE2 Dependency Management
Connector API implementation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
build.sh (1)
41-42:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winUpdate PCRE2 diagnostics to match accepted shared-library checks.
The script now accepts
libpcre2-8.so.0, but warning/error text still says onlylibpcre2-8.ais missing. Please update the messages so troubleshooting guidance matches actual detection logic.Also applies to: 101-102
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@build.sh` around lines 41 - 42, Update the user-facing messages that currently reference "libpcre2-8.a" to reflect the script's actual detection of the shared library (libpcre2-8.so.0); locate the echo lines that print the warning and installation hint (the two echo statements showing "${YELLOW}Warning: libpcre2-8.a not found..." and " sudo apt-get install libpcre2-dev") and similar messages around the other occurrences (lines near 101-102), and change the text to mention the shared library (e.g., "Warning: libpcre2 shared library (libpcre2-8.so.0) not found; you may need to install libpcre2-dev") so the troubleshooting guidance matches the detection logic.
🧹 Nitpick comments (2)
internal/handler/connector.go (1)
41-45: ⚡ Quick winAlign constructor with the new interface type.
ConnectorHandlernow depends onconnectorService, butNewConnectorHandlerstill requires*service.ConnectorService. Accepting the interface here keeps DI consistent and removes the need to bypass the constructor in tests.Proposed refactor
-func NewConnectorHandler(connectorService *service.ConnectorService, userService *service.UserService) *ConnectorHandler { +func NewConnectorHandler(connectorService connectorService, userService *service.UserService) *ConnectorHandler { return &ConnectorHandler{ connectorService: connectorService, userService: userService, } }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/handler/connector.go` around lines 41 - 45, Change NewConnectorHandler to accept the connector service interface instead of a concrete pointer: update the constructor signature from NewConnectorHandler(connectorService *service.ConnectorService, userService *service.UserService) to NewConnectorHandler(connectorService service.ConnectorService, userService *service.UserService) and pass that interface value into the ConnectorHandler.connectorService field so dependency injection and tests can provide mocks without bypassing the constructor.internal/handler/connector_test.go (1)
43-85: ⚡ Quick winAdd error-path tests for unauthorized and not-found.
This test only verifies success. Please add cases for
"No authorization."and"Can't find this Connector!"to lock the endpoint contract and prevent regressions in service branching.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/handler/connector_test.go` around lines 43 - 85, Extend TestGetConnector to include two additional subtests (or separate tests) covering the unauthorized and not-found paths: (1) "No authorization.": call the handler without setting the "user" in the gin context (remove c.Set("user", ...)) and assert the HTTP status is 401 and resp.Code equals the expected unauthorized common.ErrorCode; (2) "Can't find this Connector!": configure the fakeConnectorService to simulate a not-found error (have its GetConnector method return an appropriate error/flag) then call h.GetConnector and assert the HTTP status is 404 and resp.Code equals the not-found common.ErrorCode and the response body contains the not-found message. Use the existing TestGetConnector setup (ConnectorHandler, fakeConnectorService, route "/api/v1/connectors/:connector_id", httptest.NewRequest/Recorder) and reuse the same response unmarshal logic to validate error codes and messages.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/binding/rag_analyzer.go`:
- Line 21: The cgo LDFLAGS line currently hardcodes Linux PCRE2 path/SONAME
("-L/usr/lib/x86_64-linux-gnu -l:libpcre2-8.so.0") which is brittle; update the
cgo directive in rag_analyzer.go to remove the explicit -L and
-l:libpcre2-8.so.0 and instead link PCRE2 portably (for example use "-lpcre2-8",
or mirror the CMake approach by referencing "libpcre2-8.a" without a directory,
or use pkg-config to obtain linker flags) so the build works across
distros/architectures.
In `@internal/handler/connector.go`:
- Around line 54-55: GetConnector returns an envelope with fields (code, data,
message) but the Swagger `@Success` currently documents entity.Connector directly;
update the annotation to reference the actual wrapper/envelope schema used by
responses (the type that has code, data, message) and indicate its data field is
entity.Connector so the docs reflect the wrapped JSON format (e.g., change the
`@Success` 200 {object} entity.Connector to the response envelope type that wraps
entity.Connector).
In `@internal/service/connector.go`:
- Around line 81-88: The code checks authorization via s.accessible(connectorID,
userID) before confirming the connector exists, causing missing IDs to surface
as "No authorization."; change GetConnector to first call
s.connectorDAO.GetByID(connectorID) and if err return (nil,
common.CodeDataError, errors.New("Can't find this Connector!")), then call
s.accessible(connectorID, userID) and return (nil,
common.CodeAuthenticationError, errors.New("No authorization.")) if
inaccessible; apply the same reorder/fix for the other occurrence referenced
(lines 92-101) so existence is always validated before authorization.
---
Outside diff comments:
In `@build.sh`:
- Around line 41-42: Update the user-facing messages that currently reference
"libpcre2-8.a" to reflect the script's actual detection of the shared library
(libpcre2-8.so.0); locate the echo lines that print the warning and installation
hint (the two echo statements showing "${YELLOW}Warning: libpcre2-8.a not
found..." and " sudo apt-get install libpcre2-dev") and similar messages around
the other occurrences (lines near 101-102), and change the text to mention the
shared library (e.g., "Warning: libpcre2 shared library (libpcre2-8.so.0) not
found; you may need to install libpcre2-dev") so the troubleshooting guidance
matches the detection logic.
---
Nitpick comments:
In `@internal/handler/connector_test.go`:
- Around line 43-85: Extend TestGetConnector to include two additional subtests
(or separate tests) covering the unauthorized and not-found paths: (1) "No
authorization.": call the handler without setting the "user" in the gin context
(remove c.Set("user", ...)) and assert the HTTP status is 401 and resp.Code
equals the expected unauthorized common.ErrorCode; (2) "Can't find this
Connector!": configure the fakeConnectorService to simulate a not-found error
(have its GetConnector method return an appropriate error/flag) then call
h.GetConnector and assert the HTTP status is 404 and resp.Code equals the
not-found common.ErrorCode and the response body contains the not-found message.
Use the existing TestGetConnector setup (ConnectorHandler, fakeConnectorService,
route "/api/v1/connectors/:connector_id", httptest.NewRequest/Recorder) and
reuse the same response unmarshal logic to validate error codes and messages.
In `@internal/handler/connector.go`:
- Around line 41-45: Change NewConnectorHandler to accept the connector service
interface instead of a concrete pointer: update the constructor signature from
NewConnectorHandler(connectorService *service.ConnectorService, userService
*service.UserService) to NewConnectorHandler(connectorService
service.ConnectorService, userService *service.UserService) and pass that
interface value into the ConnectorHandler.connectorService field so dependency
injection and tests can provide mocks without bypassing the constructor.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c0d320be-8bde-42a3-b176-d445dc794887
📒 Files selected for processing (7)
build.shinternal/binding/rag_analyzer.gointernal/handler/connector.gointernal/handler/connector_test.gointernal/router/router.gointernal/service/connector.gointernal/service/llm.go
|
Hi @jakearmstrong59 your PR is conflicted with #15259 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/service/connector.go`:
- Around line 143-145: The code returns the raw DAO error from
s.connectorDAO.UpdateByID(connectorID, updates); replace this with a sanitized
error message for the client and log the original internal error instead. Change
the return to something like: log the original err (e.g.,
s.logger.Errorf("UpdateByID failed for connector %s: %v", connectorID, err) if
logger exists), then return nil, common.CodeServerError, errors.New("failed to
update connector") (or a package-level sanitized error) so internal DB details
from UpdateByID are not leaked.
- Around line 106-113: In UpdateConnector, the authorization check is performed
before verifying the connector exists which can return "No authorization." for
missing connectors; change the order to first call
s.connectorDAO.GetByID(connectorID) and return the data-not-found error
(common.CodeDataError) if it fails, then call s.accessible(connectorID, userID)
to enforce authorization and only return authentication errors after the
existence check; update the error returns around connectorDAO.GetByID and
accessible() accordingly.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d87effac-201d-4519-82af-54cb6788fb56
📒 Files selected for processing (4)
internal/handler/connector.gointernal/handler/connector_test.gointernal/router/router.gointernal/service/connector.go
## Summary - Add Go REST support for `GET /api/v1/system/healthz`. - Return Python-compatible `ok`/`nok` dependency fields for DB, Redis, document engine, and storage. - Return HTTP 200 only when all checks pass; otherwise return HTTP 500 with `_meta` failure details. - Add focused service coverage for the unhealthy dependency response when Go dependencies are not initialized. ## Scope This is a small, isolated slice of #15240. It avoids current open connector PRs (#15274, #15300, #15265, #15264), tenant/member PRs (#15295, #15301, #15276), MCP PRs (#15281, #15253, #15254, #15260, #15261, #15262), and the memory-message PR (#15256). Refs #15240
|
The main baseline have already implemented this PR. |
Summary
Implemented the Go API endpoint:
GET /api/v1/connectors/:connector_idThis ports the Python behavior from
api/apps/restful_apis/connector_api.py::get_connectorinto the Go server.Related Issue
Closes: #15240
Change Type
Real Behavior Proof
The Go API now supports:
Expected success response:
{ "code": 0, "data": { "id": "conn123", "tenant_id": "tenant123", "name": "REST source", "source": "rest_api", "input_type": "poll", "config": { "url": "https://example.com/feed" }, "refresh_freq": 5, "prune_freq": 5, "timeout_secs": 1740, "status": "0" }, "message": "success" }Expected behavior:
No authorization.if the connector is not accessible.Can't find this Connector!if the connector does not exist.Checklist
GET /api/v1/connectors/:connector_idalready existed in Go.connector_api.py.--help.