-
Notifications
You must be signed in to change notification settings - Fork 19
feat: support tenant.metadata #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@claude review please |
|
Claude finished @alexluong's task —— View job Code Review Progress
Review SummaryI've reviewed the metadata implementation for the Tenant API. The implementation is solid and comprehensive, with excellent test coverage. Below are my findings organized by category: a. Code Quality & Best PracticesThe implementation demonstrates good Go practices:
b. Implementation Details1. Redis Persistence (internal/models/entity.go:159-167) The implementation correctly handles metadata storage:
2. Deserialization (internal/models/tenant.go:33-39) The parsing logic properly handles missing metadata:
3. Handler Logic (internal/services/api/tenant_handlers.go:40-47) The handler gracefully handles invalid JSON by continuing with nil metadata, which is reasonable for optional fields. However, there's a subtle issue here (see Potential Issues section). c. Test CoverageExcellent test coverage across multiple layers:
The E2E tests are particularly thorough and clearly document the expected behavior with descriptive test names and comments. d. Potential Issues1. Silent Error Swallowing in Handler (internal/services/api/tenant_handlers.go:44-47) if err := c.ShouldBindJSON(&input); err != nil {
// If body is empty or invalid, that's OK - metadata is optional
// Continue with nil metadata
}This silently ignores all JSON binding errors, including:
Concern: If a client sends Recommendation: Distinguish between "no body" (acceptable) and "invalid body" (should error): var input struct {
Metadata models.Metadata `json:"metadata,omitempty"`
}
if c.Request.ContentLength > 0 {
if err := c.ShouldBindJSON(&input); err != nil {
AbortWithError(c, http.StatusBadRequest, NewErrInvalidJSON(err))
return
}
}2. PUT Replacement Semantics Not Validated (internal/services/api/tenant_handlers.go:56-58) The handler performs full replacement of metadata on PUT (line 58), which is correct for PUT semantics. However, there's no validation that clients understand this behavior. Observation: The E2E tests correctly verify this behavior (lines 319-342), showing that 3. Missing Input Validation There's no validation on:
Recommendation: Consider adding reasonable limits to prevent abuse: if len(input.Metadata) > 50 {
// error: too many metadata entries
}
for k, v := range input.Metadata {
if len(k) > 255 || len(v) > 1024 {
// error: key or value too long
}
}e. Security ConsiderationsNo major security concerns, but worth noting:
f. Performance ConsiderationsNo performance concerns:
g. DocumentationOpenAPI Spec (docs/apis/openapi.yaml):
Suggestion: Add a note about PUT replacement semantics in the operation description: description: |
Idempotently creates or updates a tenant. Required before associating destinations.
Note: PUT replaces the entire metadata object if provided. To preserve existing
metadata, retrieve the tenant first and merge metadata client-side.RecommendationOverall: Approve with minor suggestions. The implementation is well-tested and follows established patterns. The main improvement would be to handle invalid JSON more explicitly in the handler to provide better feedback to API clients. Priority:
|
No description provided.