Skip to content

Go: implement connector get API - #15259

Merged
JinHai-CN merged 2 commits into
infiniflow:mainfrom
tmimmanuel:go/connector-get-api
May 27, 2026
Merged

JinHai-CN merged 2 commits into
infiniflow:mainfrom
tmimmanuel:go/connector-get-api

Conversation

@tmimmanuel

Copy link
Copy Markdown
Contributor

Summary

  • Add Go REST support for GET /api/v1/connectors/:connector_id.
  • Reuse the Python API behavior by returning the connector only when the current user can access its tenant.
  • Add focused handler coverage for success and unauthorized responses.

Scope

This is a small, isolated slice of #15240. It avoids the open system API PR (#15256), the open MCP endpoint PRs (#15253, #15254), and the current Python data-source connector feature PRs.

Refs #15240

Tests

go test -vet=off ./internal/handler -run TestConnectorHandlerGetConnector -count=1
go test -vet=off -run '^$' ./internal/handler ./internal/service ./internal/router\ngit diff --check\n```

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label May 26, 2026
@coderabbitai

coderabbitai Bot commented May 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0a257618-110c-4296-84fa-ddb0038ddb7f

📥 Commits

Reviewing files that changed from the base of the PR and between 8f0632c and 9cc8be7.

📒 Files selected for processing (4)
  • internal/handler/connector.go
  • internal/handler/connector_test.go
  • internal/router/router.go
  • internal/service/connector.go

📝 Walkthrough

Walkthrough

This PR adds a single-connector retrieval endpoint to the API. The service layer validates the connector ID and enforces tenant-based authorization, checking both direct tenant ownership and user-tenant associations. The handler abstracts the service behind an interface, retrieves the authenticated user, invokes the service, and returns connector details or error codes as JSON. Tests cover success and authorization-failure scenarios.

Changes

Connector Retrieval Endpoint

Layer / File(s) Summary
Service connector retrieval with tenant authorization
internal/service/connector.go
Imports errors package and adds GetConnector method that validates connector ID, fetches the connector via DAO, maps GORM RecordNotFound errors, and enforces tenant-based access control using both direct TenantID match and user-tenant DAO membership checks.
Handler interface abstraction and GetConnector endpoint
internal/handler/connector.go, internal/handler/connector_test.go
Introduces connectorService interface, refactors ConnectorHandler to depend on the interface, adds GetConnector handler that retrieves the user context, calls the service method, and returns JSON with success code and connector data or error details. Test suite includes a fake connector service and validates both successful retrieval and unauthorized access scenarios.
Route registration
internal/router/router.go
Registers protected GET route /api/v1/connectors/:connector_id mapped to the handler's GetConnector method.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A rabbit hopped into the handler's door,
With interfaces neat, less concrete before,
The GetConnector sings a tenant's true song,
Each user their connectors, rights all along! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description provides clear context and purpose but does not follow the required template structure with 'What problem does this PR solve?' and 'Type of change' sections. Reformat the description to match the repository template by adding 'What problem does this PR solve?' and 'Type of change' sections with appropriate checkboxes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: implementing a connector get API in Go, which is the primary focus of the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Haruko386
Haruko386 self-requested a review May 27, 2026 02:18
Haruko386

This comment was marked as outdated.

@Haruko386 Haruko386 added the ci Continue Integration label May 27, 2026

@Haruko386 Haruko386 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.16%. Comparing base (187dc8a) to head (0f70dc6).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #15259   +/-   ##
=======================================
  Coverage   93.16%   93.16%           
=======================================
  Files          10       10           
  Lines         717      717           
  Branches      118      118           
=======================================
  Hits          668      668           
  Misses         29       29           
  Partials       20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants