[PlatformAPI] Add global policies support for LLM providers and proxies#2245
[PlatformAPI] Add global policies support for LLM providers and proxies#2245ashera96 wants to merge 3 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (7)
📝 WalkthroughSchema Extension: Global and Operation-Scoped PoliciesThe PR introduces Artifact Version AdaptationA new Centralized API VersioningThe PR establishes Database-Driven Gateway Version ResolutionA bug fix ensures gateway version is resolved from the database during deployment YAML generation, correcting version checks that previously always fell back to the legacy code path regardless of the target gateway's actual version. The Policy Migration for Backward CompatibilityLLM provider and proxy services now support the new policy structure while maintaining backward compatibility. Legacy Code Quality ImprovementsThe constants file consolidates gateway artifact versioning: WalkthroughThis PR upgrades the platform-api from A new split policy model is introduced: Suggested Reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies" 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: 4
🤖 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 `@platform-api/src/internal/handler/api.go`:
- Line 570: The comment on the ImportAPIProject function documents an incorrect
API route path. Update the comment from `/api/v1alpha2/import/api-project` to
match the actual registered route path `/api/v1alpha2/api-projects/import`
(which is registered at lines 994-997). This ensures the function documentation
accurately reflects the actual HTTP endpoint being used.
In `@platform-api/src/internal/handler/deployment.go`:
- Line 47: Update the handler comments in the deployment.go file to align with
the actual registered routes. The comments for DeployAPI and other handlers (at
lines 47, 259, 308, and 353) currently reference the path
`/api/v1alpha2/apis/:apiId` but should be updated to
`/api/v1alpha2/rest-apis/:apiId` to match what is actually registered in
RegisterRoutes. Replace the old API path with the correct rest-apis path in all
handler comment strings while keeping the handler function names and HTTP
methods unchanged.
In `@platform-api/src/internal/service/llm.go`:
- Around line 1171-1194: The appendLegacyOperationPath function's matching logic
is incomplete. The function comment states it should merge paths into an
OperationPolicy with the same name AND version, but the condition at line
1183-1184 only checks if the Name matches. This causes incorrect behavior when
multiple policies with the same name but different versions exist. Update the
matching condition in the loop to check both (*policies)[i].Name equals the name
parameter AND (*policies)[i].Version equals the version parameter before
appending the path to that policy entry.
In `@platform-api/src/resources/openapi.yaml`:
- Around line 9870-9874: The OperationPolicyPath.methods field in the
openapi.yaml file has a description documenting the accepted HTTP methods but
lacks an enum constraint to enforce them at the API contract boundary. Add an
enum constraint to the OperationPolicyPath.methods field that includes the valid
values (GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD, and *) by referencing the
same enum pattern already used in LLMPolicyPath.methods. This will ensure
invalid method values are rejected during API validation rather than only
documented in the description.
🪄 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: 3fb34bd5-fca1-4e7c-8551-c4c02ccc6662
📒 Files selected for processing (52)
platform-api/src/api/generated.goplatform-api/src/internal/constants/constants.goplatform-api/src/internal/deploymenttransform/policies.goplatform-api/src/internal/deploymenttransform/registry.goplatform-api/src/internal/deploymenttransform/transform_test.goplatform-api/src/internal/deploymenttransform/version.goplatform-api/src/internal/dto/llm_deployment.goplatform-api/src/internal/handler/api.goplatform-api/src/internal/handler/api_key.goplatform-api/src/internal/handler/apikey_user.goplatform-api/src/internal/handler/application.goplatform-api/src/internal/handler/deployment.goplatform-api/src/internal/handler/devportal.goplatform-api/src/internal/handler/gateway.goplatform-api/src/internal/handler/git.goplatform-api/src/internal/handler/llm.goplatform-api/src/internal/handler/llm_apikey.goplatform-api/src/internal/handler/llm_deployment.goplatform-api/src/internal/handler/llm_proxy_apikey.goplatform-api/src/internal/handler/mcp.goplatform-api/src/internal/handler/mcp_deployment.goplatform-api/src/internal/handler/organization.goplatform-api/src/internal/handler/project.goplatform-api/src/internal/handler/subscription_handler.goplatform-api/src/internal/handler/subscription_plan_handler.goplatform-api/src/internal/handler/webbroker_api.goplatform-api/src/internal/handler/webbroker_api_deployment.goplatform-api/src/internal/handler/webbroker_apikey.goplatform-api/src/internal/handler/websub_api.goplatform-api/src/internal/handler/websub_api_deployment.goplatform-api/src/internal/handler/websub_apikey.goplatform-api/src/internal/middleware/openapi_scope_registry_test.goplatform-api/src/internal/model/llm.goplatform-api/src/internal/repository/gateway.goplatform-api/src/internal/repository/interfaces.goplatform-api/src/internal/service/deployment_test.goplatform-api/src/internal/service/gateway.goplatform-api/src/internal/service/llm.goplatform-api/src/internal/service/llm_deployment.goplatform-api/src/internal/service/llm_deployment_test.goplatform-api/src/internal/service/llm_policy_migration_test.goplatform-api/src/internal/service/llm_test.goplatform-api/src/internal/utils/api.goplatform-api/src/internal/utils/api_test.goplatform-api/src/resources/default-llm-provider-templates/anthropic-template.yamlplatform-api/src/resources/default-llm-provider-templates/awsbedrock-template.yamlplatform-api/src/resources/default-llm-provider-templates/azureaifoundry-template.yamlplatform-api/src/resources/default-llm-provider-templates/azureopenai-template.yamlplatform-api/src/resources/default-llm-provider-templates/gemini-template.yamlplatform-api/src/resources/default-llm-provider-templates/mistral-template.yamlplatform-api/src/resources/default-llm-provider-templates/openai-template.yamlplatform-api/src/resources/openapi.yaml
|
@coderabbitai please review |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
cat platform-api/src/internal/deploymenttransform/version.go
echo "---"
cat platform-api/src/internal/deploymenttransform/registry.go
echo "---"
cat platform-api/src/internal/deploymenttransform/policies.go
echo "---"
cat platform-api/src/internal/constants/constants.go
echo "---"
cat platform-api/src/internal/dto/llm_deployment.go
echo "---"
cat platform-api/src/internal/repository/gateway.go | tail -30Length of output: 21308 🏁 Script executed: #!/bin/bash
cat platform-api/src/internal/service/llm_deployment.goLength of output: 63569 🏁 Script executed: #!/bin/bash
cat platform-api/src/internal/service/llm.go | grep -n "migrateLegacy\|splitLegacy\|GlobalPolicies\|OperationPolicies" | head -60
echo "---"
cat platform-api/src/internal/service/gateway.go | grep -n -A5 -B5 "UpdateGatewayVersion"
echo "---"
# Check if there's a sync test for APIBasePath
fd -e go "sync\|base_path\|openapi" platform-api/src
echo "---"
cat platform-api/src/internal/middleware/openapi_scope_registry_test.goLength of output: 6051
Review SummaryThe overall design is solid — the 1.
|
Purpose
Introduces
globalPoliciesandoperationPoliciesas first-class fields on LLM provider and proxy deployment artifacts, replacing the flatpolicieslist for new gateways.Schema change. Artifacts now carry two distinct policy lists:
globalPolicies— applied uniformly across every operation (provider-wide quota, auth, CORS). Foradvanced-ratelimit, the platform-api automatically injectskeyExtraction: [{type: "apiname"}]so the counter is shared across all operations rather than siloed per route.operationPolicies— scoped to specific paths and HTTP methods, preserving per-operation behaviour.deploymenttransform package (new). A version-aware artifact adaptation layer that sits between the generator and the wire format. Generators always produce the canonical latest shape;
deploymenttransformdowngrades the artifact for gateways below v1.2.0 (flattens both new lists into the legacypoliciesfield and stamps the correctapiVersion). Adding a new version boundary in future is a one-file registration, not a service-layer change.Version centralisation. constants.APIBasePath is now the single source of truth for the platform-api route prefix (
/api/v1alpha2). All 24 handler files build theirr.Group(...)call from this constant. A sync test locks the cross-language coupling between the OpenAPIservers:URL and the handler prefix so scope enforcement cannot silently mismatch on a future version bump.Bug fix. Gateway version was not being resolved from the database when generating a deployment YAML, causing the version check to always fall back to the old path regardless of the actual target gateway version.