Skip to content
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

Fix nil pointer error #2724

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion gateway/enforcer/internal/datastore/api_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func convertBackendJWTTokenInfoToJWTConfig(info *api.BackendJWTTokenInfo) *dto.J
ConsumerDialectURI: "", // Add a default value or fetch if needed
SignatureAlgorithm: info.SigningAlgorithm,
Encoding: info.Encoding,
GatewayJWTGeneratorImpl: "", // Add a default value or fetch if needed
TokenIssuerDtoMap: make(map[string]dto.TokenIssuer), // Populate if required
JwtExcludedClaims: make(map[string]bool), // Populate if required
PublicCert: nil, // Add conversion logic if needed
Expand Down
24 changes: 12 additions & 12 deletions gateway/enforcer/internal/dto/jwt_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ import (

// JWTConfiguration represents the JWT configuration
type JWTConfiguration struct {
Enabled bool `json:"enabled"` // Whether JWT is enabled
JWTHeader string `json:"jwtHeader"` // JWT header name
ConsumerDialectURI string `json:"consumerDialectUri"` // URI for the consumer dialect
SignatureAlgorithm string `json:"signatureAlgorithm"` // Algorithm for signature
Encoding string `json:"encoding"` // Encoding type
TokenIssuerDtoMap map[string]TokenIssuer `json:"tokenIssuerDtoMap"` // Map of token issuers
JwtExcludedClaims map[string]bool `json:"jwtExcludedClaims"` // Excluded claims in JWT
PublicCert *x509.Certificate `json:"publicCert"` // Public certificate
PrivateKey *ecdsa.PrivateKey `json:"privateKey"` // Private key for signing JWT
TTL int64 `json:"ttl"` // Time to live for the JWT
CustomClaims map[string]ClaimValue `json:"customClaims"` // Custom claims
UseKid bool `json:"useKid"` // Whether to use kid
Enabled bool `json:"enabled"` // Whether JWT is enabled
JWTHeader string `json:"jwtHeader"` // JWT header name
ConsumerDialectURI string `json:"consumerDialectUri"` // URI for the consumer dialect
SignatureAlgorithm string `json:"signatureAlgorithm"` // Algorithm for signature
Encoding string `json:"encoding"` // Encoding type
TokenIssuerDtoMap map[string]TokenIssuer `json:"tokenIssuerDtoMap"` // Map of token issuers
JwtExcludedClaims map[string]bool `json:"jwtExcludedClaims"` // Excluded claims in JWT
PublicCert *x509.Certificate `json:"publicCert"` // Public certificate
PrivateKey *ecdsa.PrivateKey `json:"privateKey"` // Private key for signing JWT
TTL int64 `json:"ttl"` // Time to live for the JWT
CustomClaims map[string]ClaimValue `json:"customClaims"` // Custom claims
UseKid bool `json:"useKid"` // Whether to use kid
}
20 changes: 10 additions & 10 deletions gateway/enforcer/internal/extproc/ext_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,13 +415,13 @@ func (s *ExternalProcessingServer) Process(srv envoy_service_proc_v3.ExternalPro
},
}
s.log.Info("Response Header Flow")
matchedAPI := s.requestConfigHolder.MatchedAPI
if s.requestConfigHolder != nil &&
matchedAPI != nil &&
matchedAPI.AiProvider != nil &&
matchedAPI.AiProvider.CompletionToken != nil &&
s.requestConfigHolder.MatchedAPI != nil &&
s.requestConfigHolder.MatchedAPI.AiProvider != nil &&
s.requestConfigHolder.MatchedAPI.AiProvider.CompletionToken != nil &&
s.requestConfigHolder.ExternalProcessingEnvoyAttributes.EnableBackendBasedAIRatelimit == "true" &&
matchedAPI.AiProvider.CompletionToken.In == dto.InHeader {
s.requestConfigHolder.MatchedAPI.AiProvider.CompletionToken.In == dto.InHeader {
matchedAPI := s.requestConfigHolder.MatchedAPI
s.log.Info("Backend based AI rate limit enabled using headers")
tokenCount, err := ratelimit.ExtractTokenCountFromExternalProcessingResponseHeaders(req.GetResponseHeaders().GetHeaders().GetHeaders(),
matchedAPI.AiProvider.PromptTokens.Value,
Expand Down Expand Up @@ -522,13 +522,13 @@ func (s *ExternalProcessingServer) Process(srv envoy_service_proc_v3.ExternalPro
ResponseBody: rbq,
},
}
matchedAPI := s.requestConfigHolder.MatchedAPI
if s.requestConfigHolder != nil &&
matchedAPI != nil &&
matchedAPI.AiProvider != nil &&
matchedAPI.AiProvider.CompletionToken != nil &&
s.requestConfigHolder.MatchedAPI != nil &&
s.requestConfigHolder.MatchedAPI.AiProvider != nil &&
s.requestConfigHolder.MatchedAPI.AiProvider.CompletionToken != nil &&
s.requestConfigHolder.ExternalProcessingEnvoyAttributes.EnableBackendBasedAIRatelimit == "true" &&
matchedAPI.AiProvider.CompletionToken.In == dto.InBody {
s.requestConfigHolder.MatchedAPI.AiProvider.CompletionToken.In == dto.InBody {
matchedAPI := s.requestConfigHolder.MatchedAPI
s.log.Info("Backend based AI rate limit enabled using body")
tokenCount, err := ratelimit.ExtractTokenCountFromExternalProcessingResponseBody(req.GetResponseBody().Body,
matchedAPI.AiProvider.PromptTokens.Value,
Expand Down