Skip to content

Add gateway implementations for custom LLM provider feature#2456

Merged
Tharanidk merged 4 commits into
wso2:mainfrom
Tharanidk:templates_gateway
Jul 10, 2026
Merged

Add gateway implementations for custom LLM provider feature#2456
Tharanidk merged 4 commits into
wso2:mainfrom
Tharanidk:templates_gateway

Conversation

@Tharanidk

@Tharanidk Tharanidk commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Purpose

Extends the LLM provider template model with three new spec fields: groupId, managedBy, and version, and wires them through the gateway-controller management API.

Fixed : #2523 as well

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (3)
gateway/gateway-controller/api/management-openapi.yaml (1)

5569-5588: 🗄️ Data Integrity & Integration | 🔵 Trivial | ⚡ Quick win

Consider adding a pattern constraint on version.

Other version fields in this spec (APIConfigData.version, LLMProviderConfigData.version, LLMProxyConfigData.version) enforce pattern: '^v\d+\.\d+$', and Policy.version enforces '^v\d+$'. The new LLMProviderTemplateData.version field has no format constraint, so malformed values (e.g., 1.0, latest) could be accepted and persisted as template metadata.

📝 Suggested diff
         version:
           type: string
           description: |
             Template content version (e.g. v1.0). Multiple versions of the same
             groupId can coexist; defaults to v1.0 when omitted.
+          pattern: '^v\d+\.\d+$'
           example: v1.0
🤖 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 `@gateway/gateway-controller/api/management-openapi.yaml` around lines 5569 -
5588, The new LLMProviderTemplateData.version field is missing the same format
validation used by other version fields in the OpenAPI spec. Update the version
property in management-openapi.yaml to add a pattern constraint consistent with
the existing version schema (matching the other template/config version fields),
so only valid version strings are accepted and persisted; keep the change
localized to the LLMProviderTemplateData.version definition.
gateway/gateway-controller/pkg/models/llm_provider_template.go (1)

46-72: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Correct fallback behavior; consider extracting shared helper.

GetGroupID, GetVersion, and GetManagedBy each repeat the same nil-check/trim/fallback pattern. A shared private helper would reduce duplication and keep the trimming semantics consistent if this logic changes later.

♻️ Suggested refactor
+func stringOrDefault(v *string, fallback string) string {
+	if v != nil {
+		if trimmed := strings.TrimSpace(*v); trimmed != "" {
+			return trimmed
+		}
+	}
+	return fallback
+}
+
 func (t *StoredLLMProviderTemplate) GetGroupID() string {
-	if t.Configuration.Spec.GroupId != nil {
-		if v := strings.TrimSpace(*t.Configuration.Spec.GroupId); v != "" {
-			return v
-		}
-	}
-	return t.Configuration.Metadata.Name
+	return stringOrDefault(t.Configuration.Spec.GroupId, t.Configuration.Metadata.Name)
 }

 func (t *StoredLLMProviderTemplate) GetVersion() string {
-	if t.Configuration.Spec.Version != nil {
-		if v := strings.TrimSpace(*t.Configuration.Spec.Version); v != "" {
-			return v
-		}
-	}
-	return DefaultTemplateVersion
+	return stringOrDefault(t.Configuration.Spec.Version, DefaultTemplateVersion)
 }

 func (t *StoredLLMProviderTemplate) GetManagedBy() string {
-	if t.Configuration.Spec.ManagedBy != nil {
-		if p := strings.TrimSpace(*t.Configuration.Spec.ManagedBy); p != "" {
-			return p
-		}
-	}
-	return DefaultTemplateManagedBy
+	return stringOrDefault(t.Configuration.Spec.ManagedBy, DefaultTemplateManagedBy)
 }
🤖 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 `@gateway/gateway-controller/pkg/models/llm_provider_template.go` around lines
46 - 72, GetGroupID, GetVersion, and GetManagedBy all duplicate the same
nil-check, trim, and fallback logic in StoredLLMProviderTemplate. Extract that
shared behavior into a private helper on StoredLLMProviderTemplate that accepts
the optional string pointer and fallback value, then have all three methods
delegate to it so the trimming semantics stay consistent and future changes only
need to be made in one place.
gateway/gateway-controller/pkg/utils/llm_deployment.go (1)

595-616: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Correct defaulting logic and placement.

normalizeTemplateDefaults is invoked after parsing and before render/validation, so validation and returned config both reflect the defaults — matches the documented OpenAPI fallback contract (groupId → metadata.name, version → v1.0, managedBy → customer) and is covered by tests.

Note: the nil-check/trim/fallback logic here duplicates the same pattern in StoredLLMProviderTemplate.GetGroupID/GetVersion/GetManagedBy (gateway/gateway-controller/pkg/models/llm_provider_template.go). Consider exposing a small shared helper from models (e.g., a NormalizeOptionalString(v *string, fallback string) *string) that both this function and the getters can use, to avoid the fallback semantics drifting between the two packages over time.

🤖 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 `@gateway/gateway-controller/pkg/utils/llm_deployment.go` around lines 595 -
616, The defaulting logic in normalizeTemplateDefaults is duplicated in
StoredLLMProviderTemplate.GetGroupID/GetVersion/GetManagedBy, which risks the
fallback behavior drifting over time. Extract the nil/trim/fallback handling
into a shared helper in models, such as a NormalizeOptionalString-style
function, and have both normalizeTemplateDefaults and the
StoredLLMProviderTemplate getters use that shared helper so groupId, version,
and managedBy stay consistent.
🤖 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.

Nitpick comments:
In `@gateway/gateway-controller/api/management-openapi.yaml`:
- Around line 5569-5588: The new LLMProviderTemplateData.version field is
missing the same format validation used by other version fields in the OpenAPI
spec. Update the version property in management-openapi.yaml to add a pattern
constraint consistent with the existing version schema (matching the other
template/config version fields), so only valid version strings are accepted and
persisted; keep the change localized to the LLMProviderTemplateData.version
definition.

In `@gateway/gateway-controller/pkg/models/llm_provider_template.go`:
- Around line 46-72: GetGroupID, GetVersion, and GetManagedBy all duplicate the
same nil-check, trim, and fallback logic in StoredLLMProviderTemplate. Extract
that shared behavior into a private helper on StoredLLMProviderTemplate that
accepts the optional string pointer and fallback value, then have all three
methods delegate to it so the trimming semantics stay consistent and future
changes only need to be made in one place.

In `@gateway/gateway-controller/pkg/utils/llm_deployment.go`:
- Around line 595-616: The defaulting logic in normalizeTemplateDefaults is
duplicated in StoredLLMProviderTemplate.GetGroupID/GetVersion/GetManagedBy,
which risks the fallback behavior drifting over time. Extract the
nil/trim/fallback handling into a shared helper in models, such as a
NormalizeOptionalString-style function, and have both normalizeTemplateDefaults
and the StoredLLMProviderTemplate getters use that shared helper so groupId,
version, and managedBy stay consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 38d5cf89-042b-4b5e-bbf7-216ed87092df

📥 Commits

Reviewing files that changed from the base of the PR and between eb1d7be and fd188d2.

📒 Files selected for processing (13)
  • gateway/gateway-controller/api/management-openapi.yaml
  • gateway/gateway-controller/default-llm-provider-templates/anthropic-template.yaml
  • gateway/gateway-controller/default-llm-provider-templates/awsbedrock-template.yaml
  • gateway/gateway-controller/default-llm-provider-templates/azureaifoundry-template.yaml
  • gateway/gateway-controller/default-llm-provider-templates/azureopenai-template.yaml
  • gateway/gateway-controller/default-llm-provider-templates/gemini-template.yaml
  • gateway/gateway-controller/default-llm-provider-templates/mistral-template.yaml
  • gateway/gateway-controller/default-llm-provider-templates/openai-template.yaml
  • gateway/gateway-controller/pkg/api/management/generated.go
  • gateway/gateway-controller/pkg/models/llm_provider_template.go
  • gateway/gateway-controller/pkg/models/llm_provider_template_test.go
  • gateway/gateway-controller/pkg/utils/llm_deployment.go
  • gateway/gateway-controller/pkg/utils/llm_deployment_test.go

Comment thread gateway/gateway-controller/api/management-openapi.yaml
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 6, 2026
Comment thread gateway/gateway-controller/pkg/models/llm_provider_template.go Outdated
Comment thread gateway/examples/llm-provider-template.yaml Outdated
thivindu
thivindu previously approved these changes Jul 6, 2026
@thivindu thivindu dismissed their stale review July 6, 2026 12:04

Requested changes

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

Dependency name: github.com/go-playground/validator/v10
Version: v10.29.0
Approved: ❌ No - Version constraint not met - approved versions: [>=v10.30.1]

Dependency name: github.com/go-viper/mapstructure/v2
Version: v2.4.0
Allowed range: >=v2.4.0
Approved: ✅ Yes

Dependency name: github.com/golang-jwt/jwt/v5
Version: v5.3.1
Allowed range: >=v5.3.1
Approved: ✅ Yes

Dependency name: github.com/google/uuid
Version: v1.6.0
Allowed range: >=v1.6.0
Approved: ✅ Yes

Dependency name: github.com/gorilla/websocket
Version: v1.5.3
Allowed range: >=v1.5.3
Approved: ✅ Yes

Dependency name: github.com/jackc/pgx/v5
Version: v5.9.2
Allowed range: >=v5.8.0
Approved: ✅ Yes

Dependency name: github.com/knadh/koanf/parsers/toml/v2
Version: v2.2.0
Allowed range: >=v2.2.0
Approved: ✅ Yes

Dependency name: github.com/knadh/koanf/providers/env
Version: v1.1.0
Allowed range: >=v1.1.0
Approved: ✅ Yes

Dependency name: github.com/knadh/koanf/providers/file
Version: v1.2.1
Allowed range: >=v1.2.1
Approved: ✅ Yes

Dependency name: github.com/knadh/koanf/v2
Version: v2.3.2
Allowed range: >=v2.3.2
Approved: ✅ Yes

Dependency name: github.com/mattn/go-sqlite3
Version: v1.14.41
Allowed range: >=v1.14.32
Approved: ✅ Yes

Dependency name: github.com/microsoft/go-mssqldb
Version: v1.10.0
Allowed range: >=v1.10.0
Approved: ✅ Yes

Dependency name: github.com/oapi-codegen/runtime
Version: v1.1.2
Approved: ❌ No - Version constraint not met - approved versions: [>=v1.2.0]

Dependency name: github.com/pb33f/libopenapi
Version: v0.28.2
Allowed range: >=v0.28.2
Approved: ✅ Yes

Dependency name: github.com/stretchr/testify
Version: v1.11.1
Allowed range: >=v1.11.1
Approved: ✅ Yes

Dependency name: golang.org/x/crypto
Version: v0.50.0
Allowed range: >=v0.31.0
Approved: ✅ Yes

Dependency name: gopkg.in/yaml.v3
Version: v3.0.1
Allowed range: >=v3.0.1
Approved: ✅ Yes


Next Steps

  1. Review the validation failures listed above
  2. Check if dependencies are in the approved dependency list
  3. Options to resolve:
    • Remove the unapproved dependencies from this PR
    • OR submit a PR to add these dependencies to the approved list in engineering-governance
  4. Once resolved, push changes to re-run validation

This PR is blocked until all dependencies are approved.

⚠️ Please verify the scope of the dependencies usage is necessary

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

Dependency name: github.com/go-playground/validator/v10
Version: v10.29.0
Approved: ❌ No - Version constraint not met - approved versions: [>=v10.30.1]

Dependency name: github.com/go-viper/mapstructure/v2
Version: v2.4.0
Allowed range: >=v2.4.0
Approved: ✅ Yes

Dependency name: github.com/golang-jwt/jwt/v5
Version: v5.3.1
Allowed range: >=v5.3.1
Approved: ✅ Yes

Dependency name: github.com/google/uuid
Version: v1.6.0
Allowed range: >=v1.6.0
Approved: ✅ Yes

Dependency name: github.com/gorilla/websocket
Version: v1.5.3
Allowed range: >=v1.5.3
Approved: ✅ Yes

Dependency name: github.com/jackc/pgx/v5
Version: v5.9.2
Allowed range: >=v5.8.0
Approved: ✅ Yes

Dependency name: github.com/knadh/koanf/parsers/toml/v2
Version: v2.2.0
Allowed range: >=v2.2.0
Approved: ✅ Yes

Dependency name: github.com/knadh/koanf/providers/env
Version: v1.1.0
Allowed range: >=v1.1.0
Approved: ✅ Yes

Dependency name: github.com/knadh/koanf/providers/file
Version: v1.2.1
Allowed range: >=v1.2.1
Approved: ✅ Yes

Dependency name: github.com/knadh/koanf/v2
Version: v2.3.2
Allowed range: >=v2.3.2
Approved: ✅ Yes

Dependency name: github.com/mattn/go-sqlite3
Version: v1.14.41
Allowed range: >=v1.14.32
Approved: ✅ Yes

Dependency name: github.com/microsoft/go-mssqldb
Version: v1.10.0
Allowed range: >=v1.10.0
Approved: ✅ Yes

Dependency name: github.com/oapi-codegen/runtime
Version: v1.1.2
Approved: ❌ No - Version constraint not met - approved versions: [>=v1.2.0]

Dependency name: github.com/pb33f/libopenapi
Version: v0.28.2
Allowed range: >=v0.28.2
Approved: ✅ Yes

Dependency name: github.com/stretchr/testify
Version: v1.11.1
Allowed range: >=v1.11.1
Approved: ✅ Yes

Dependency name: golang.org/x/crypto
Version: v0.50.0
Allowed range: >=v0.31.0
Approved: ✅ Yes

Dependency name: gopkg.in/yaml.v3
Version: v3.0.1
Allowed range: >=v3.0.1
Approved: ✅ Yes


Next Steps

  1. Review the validation failures listed above
  2. Check if dependencies are in the approved dependency list
  3. Options to resolve:
    • Remove the unapproved dependencies from this PR
    • OR submit a PR to add these dependencies to the approved list in engineering-governance
  4. Once resolved, push changes to re-run validation

This PR is blocked until all dependencies are approved.

⚠️ Please verify the scope of the dependencies usage is necessary

coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

Dependency name: github.com/oapi-codegen/runtime
Version: v1.2.0 (was v1.1.2)
Approved: ❌ No - Scope mismatch - allowed scopes: [wso2cloud], but 'api-platform' scope is required

Dependency name: github.com/go-playground/validator/v10
Version: v10.30.1 (was v10.29.0)
Allowed range: >=v10.30.1
Approved: ✅ Yes

Dependency name: github.com/oapi-codegen/runtime
Version: v1.2.0 (was v1.1.2)
Approved: ❌ No - Scope mismatch - allowed scopes: [wso2cloud], but 'api-platform' scope is required


Next Steps

  1. Review the validation failures listed above
  2. Check if dependencies are in the approved dependency list
  3. Options to resolve:
    • Remove the unapproved dependencies from this PR
    • OR submit a PR to add these dependencies to the approved list in engineering-governance
  4. Once resolved, push changes to re-run validation

This PR is blocked until all dependencies are approved.

⚠️ Please verify the scope of the dependencies usage is necessary

@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

Dependency name: github.com/oapi-codegen/runtime
Version: v1.2.0 (was v1.1.2)
Approved: ❌ No - Scope mismatch - allowed scopes: [wso2cloud], but 'api-platform' scope is required

Dependency name: github.com/pb33f/libopenapi
Version: v0.28.2
Allowed range: >=v0.28.2
Approved: ✅ Yes

Dependency name: github.com/go-playground/validator/v10
Version: v10.30.1 (was v10.29.0)
Allowed range: >=v10.30.1
Approved: ✅ Yes

Dependency name: github.com/oapi-codegen/runtime
Version: v1.2.0 (was v1.1.2)
Approved: ❌ No - Scope mismatch - allowed scopes: [wso2cloud], but 'api-platform' scope is required


Next Steps

  1. Review the validation failures listed above
  2. Check if dependencies are in the approved dependency list
  3. Options to resolve:
    • Remove the unapproved dependencies from this PR
    • OR submit a PR to add these dependencies to the approved list in engineering-governance
  4. Once resolved, push changes to re-run validation

This PR is blocked until all dependencies are approved.

⚠️ Please verify the scope of the dependencies usage is necessary

@Tharanidk Tharanidk force-pushed the templates_gateway branch from 6805b3d to 14a6c09 Compare July 10, 2026 08:58
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Validation Results

Dependency name: github.com/pb33f/libopenapi
Version: v0.28.2
Allowed range: >=v0.28.2
Approved: ✅ Yes

Dependency name: github.com/go-playground/validator/v10
Version: v10.30.1 (was v10.29.0)
Allowed range: >=v10.30.1
Approved: ✅ Yes

⚠️ Please verify the scope of the dependencies usage is necessary

@Tharanidk Tharanidk merged commit e5ae371 into wso2:main Jul 10, 2026
13 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task]: Use oganization for managedBy field - Custom Policies and LLM Templates

5 participants