From 8497f86dd6d3150fa6e11b64a74794b2b07f62a1 Mon Sep 17 00:00:00 2001 From: huabing zhao Date: Wed, 25 Oct 2023 19:19:31 +0800 Subject: [PATCH] follow golang name convention: change Cors to CORS Signed-off-by: huabing zhao --- internal/gatewayapi/securitypolicy.go | 14 +++---- internal/ir/xds.go | 8 ++-- internal/ir/zz_generated.deepcopy.go | 54 +++++++++++++------------- internal/xds/translator/cors.go | 34 ++++++++-------- internal/xds/translator/httpfilters.go | 4 +- 5 files changed, 57 insertions(+), 57 deletions(-) diff --git a/internal/gatewayapi/securitypolicy.go b/internal/gatewayapi/securitypolicy.go index adaff622789..a578f1272d8 100644 --- a/internal/gatewayapi/securitypolicy.go +++ b/internal/gatewayapi/securitypolicy.go @@ -222,7 +222,7 @@ func resolveSecurityPolicyRouteTargetRef(policy *egv1a1.SecurityPolicy, routes m func (t *Translator) translateSecurityPolicyForRoute(policy *egv1a1.SecurityPolicy, route RouteContext, xdsIR XdsIRMap) { // Build IR - var cors *ir.Cors + var cors *ir.CORS if policy.Spec.CORS != nil { cors = t.buildCORS(policy) } @@ -234,7 +234,7 @@ func (t *Translator) translateSecurityPolicyForRoute(policy *egv1a1.SecurityPoli for _, r := range http.Routes { // Apply if there is a match if strings.HasPrefix(r.Name, prefix) { - r.Cors = cors + r.CORS = cors } } } @@ -244,7 +244,7 @@ func (t *Translator) translateSecurityPolicyForRoute(policy *egv1a1.SecurityPoli func (t *Translator) translateSecurityPolicyForGateway(policy *egv1a1.SecurityPolicy, gateway *GatewayContext, xdsIR XdsIRMap) { // Build IR - var cors *ir.Cors + var cors *ir.CORS if policy.Spec.CORS != nil { cors = t.buildCORS(policy) } @@ -259,15 +259,15 @@ func (t *Translator) translateSecurityPolicyForGateway(policy *egv1a1.SecurityPo for _, http := range ir.HTTP { for _, r := range http.Routes { // Apply if not already set - if r.Cors == nil { - r.Cors = cors + if r.CORS == nil { + r.CORS = cors } } } } -func (t *Translator) buildCORS(policy *egv1a1.SecurityPolicy) *ir.Cors { +func (t *Translator) buildCORS(policy *egv1a1.SecurityPolicy) *ir.CORS { var allowOrigins []*ir.StringMatch for _, origin := range policy.Spec.CORS.AllowOrigins { @@ -308,7 +308,7 @@ func (t *Translator) buildCORS(policy *egv1a1.SecurityPolicy) *ir.Cors { } } - return &ir.Cors{ + return &ir.CORS{ AllowOrigins: allowOrigins, AllowMethods: policy.Spec.CORS.AllowMethods, AllowHeaders: policy.Spec.CORS.AllowHeaders, diff --git a/internal/ir/xds.go b/internal/ir/xds.go index a343b173f4a..a4be0701f58 100644 --- a/internal/ir/xds.go +++ b/internal/ir/xds.go @@ -279,8 +279,8 @@ type HTTPRoute struct { Timeout *metav1.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"` // load balancer policy to use when routing to the backend endpoints. LoadBalancer *LoadBalancer `json:"loadBalancer,omitempty" yaml:"loadBalancer,omitempty"` - // Cors policy for the route. - Cors *Cors `json:"cors,omitempty" yaml:"cors,omitempty"` + // CORS policy for the route. + CORS *CORS `json:"cors,omitempty" yaml:"cors,omitempty"` // ExtensionRefs holds unstructured resources that were introduced by an extension and used on the HTTPRoute as extensionRef filters ExtensionRefs []*UnstructuredRef `json:"extensionRefs,omitempty" yaml:"extensionRefs,omitempty"` } @@ -314,10 +314,10 @@ type JwtRequestAuthentication struct { Providers []egv1a1.JwtAuthenticationFilterProvider `json:"providers,omitempty" yaml:"providers,omitempty"` } -// Cors holds the Cross-Origin Resource Sharing (CORS) policy for the route. +// CORS holds the Cross-Origin Resource Sharing (CORS) policy for the route. // // +k8s:deepcopy-gen=true -type Cors struct { +type CORS struct { // AllowOrigins defines the origins that are allowed to make requests. AllowOrigins []*StringMatch `json:"allowOrigins,omitempty" yaml:"allowOrigins,omitempty"` // AllowMethods defines the methods that are allowed to make requests. diff --git a/internal/ir/zz_generated.deepcopy.go b/internal/ir/zz_generated.deepcopy.go index d1bbb050455..e9b07241b18 100644 --- a/internal/ir/zz_generated.deepcopy.go +++ b/internal/ir/zz_generated.deepcopy.go @@ -78,27 +78,7 @@ func (in *AddHeader) DeepCopy() *AddHeader { } // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ConsistentHash) DeepCopyInto(out *ConsistentHash) { - *out = *in - if in.SourceIP != nil { - in, out := &in.SourceIP, &out.SourceIP - *out = new(bool) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConsistentHash. -func (in *ConsistentHash) DeepCopy() *ConsistentHash { - if in == nil { - return nil - } - out := new(ConsistentHash) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *Cors) DeepCopyInto(out *Cors) { +func (in *CORS) DeepCopyInto(out *CORS) { *out = *in if in.AllowOrigins != nil { in, out := &in.AllowOrigins, &out.AllowOrigins @@ -133,12 +113,32 @@ func (in *Cors) DeepCopyInto(out *Cors) { } } -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Cors. -func (in *Cors) DeepCopy() *Cors { +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CORS. +func (in *CORS) DeepCopy() *CORS { if in == nil { return nil } - out := new(Cors) + out := new(CORS) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ConsistentHash) DeepCopyInto(out *ConsistentHash) { + *out = *in + if in.SourceIP != nil { + in, out := &in.SourceIP, &out.SourceIP + *out = new(bool) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ConsistentHash. +func (in *ConsistentHash) DeepCopy() *ConsistentHash { + if in == nil { + return nil + } + out := new(ConsistentHash) in.DeepCopyInto(out) return out } @@ -456,9 +456,9 @@ func (in *HTTPRoute) DeepCopyInto(out *HTTPRoute) { *out = new(LoadBalancer) (*in).DeepCopyInto(*out) } - if in.Cors != nil { - in, out := &in.Cors, &out.Cors - *out = new(Cors) + if in.CORS != nil { + in, out := &in.CORS, &out.CORS + *out = new(CORS) (*in).DeepCopyInto(*out) } if in.ExtensionRefs != nil { diff --git a/internal/xds/translator/cors.go b/internal/xds/translator/cors.go index 775eeeb9ed5..b070b7fb54a 100644 --- a/internal/xds/translator/cors.go +++ b/internal/xds/translator/cors.go @@ -22,9 +22,9 @@ import ( "github.com/envoyproxy/gateway/internal/ir" ) -// patchHCMWithCorsFilter builds and appends the Cors Filter to the HTTP +// patchHCMWithCORSFilter builds and appends the CORS Filter to the HTTP // Connection Manager if applicable. -func patchHCMWithCorsFilter(mgr *hcmv3.HttpConnectionManager, irListener *ir.HTTPListener) error { +func patchHCMWithCORSFilter(mgr *hcmv3.HttpConnectionManager, irListener *ir.HTTPListener) error { if mgr == nil { return errors.New("hcm is nil") } @@ -33,7 +33,7 @@ func patchHCMWithCorsFilter(mgr *hcmv3.HttpConnectionManager, irListener *ir.HTT return errors.New("ir listener is nil") } - if !listenerContainsCors(irListener) { + if !listenerContainsCORS(irListener) { return nil } @@ -44,7 +44,7 @@ func patchHCMWithCorsFilter(mgr *hcmv3.HttpConnectionManager, irListener *ir.HTT } } - corsFilter, err := buildHCMCorsFilter() + corsFilter, err := buildHCMCORSFilter() if err != nil { return err } @@ -55,8 +55,8 @@ func patchHCMWithCorsFilter(mgr *hcmv3.HttpConnectionManager, irListener *ir.HTT return nil } -// buildHCMCorsFilter returns a Cors filter from the provided IR listener. -func buildHCMCorsFilter() (*hcmv3.HttpFilter, error) { +// buildHCMCORSFilter returns a CORS filter from the provided IR listener. +func buildHCMCORSFilter() (*hcmv3.HttpFilter, error) { corsProto := &corsv3.Cors{} corsAny, err := anypb.New(corsProto) @@ -72,15 +72,15 @@ func buildHCMCorsFilter() (*hcmv3.HttpFilter, error) { }, nil } -// listenerContainsCors returns true if the provided listener has Cors +// listenerContainsCORS returns true if the provided listener has CORS // policies attached to its routes. -func listenerContainsCors(irListener *ir.HTTPListener) bool { +func listenerContainsCORS(irListener *ir.HTTPListener) bool { if irListener == nil { return false } for _, route := range irListener.Routes { - if route.Cors != nil { + if route.CORS != nil { return true } } @@ -88,16 +88,16 @@ func listenerContainsCors(irListener *ir.HTTPListener) bool { return false } -// patchRouteWithCorsConfig patches the provided route with the Cors config if +// patchRouteWithCORSConfig patches the provided route with the CORS config if // applicable. -func patchRouteWithCorsConfig(route *routev3.Route, irRoute *ir.HTTPRoute) error { +func patchRouteWithCORSConfig(route *routev3.Route, irRoute *ir.HTTPRoute) error { if route == nil { return errors.New("xds route is nil") } if irRoute == nil { return errors.New("ir route is nil") } - if irRoute.Cors == nil { + if irRoute.CORS == nil { return nil } @@ -119,14 +119,14 @@ func patchRouteWithCorsConfig(route *routev3.Route, irRoute *ir.HTTPRoute) error //nolint:gocritic - for _, origin := range irRoute.Cors.AllowOrigins { + for _, origin := range irRoute.CORS.AllowOrigins { allowOrigins = append(allowOrigins, buildXdsStringMatcher(origin)) } - allowMethods = strings.Join(irRoute.Cors.AllowMethods, ", ") - allowHeaders = strings.Join(irRoute.Cors.AllowHeaders, ", ") - exposeHeaders = strings.Join(irRoute.Cors.ExposeHeaders, ", ") - maxAge = strconv.Itoa(int(irRoute.Cors.MaxAge.Seconds())) + allowMethods = strings.Join(irRoute.CORS.AllowMethods, ", ") + allowHeaders = strings.Join(irRoute.CORS.AllowHeaders, ", ") + exposeHeaders = strings.Join(irRoute.CORS.ExposeHeaders, ", ") + maxAge = strconv.Itoa(int(irRoute.CORS.MaxAge.Seconds())) routeCfgProto := &corsv3.CorsPolicy{ AllowOriginStringMatch: allowOrigins, diff --git a/internal/xds/translator/httpfilters.go b/internal/xds/translator/httpfilters.go index da5c5aca045..cef974cec33 100644 --- a/internal/xds/translator/httpfilters.go +++ b/internal/xds/translator/httpfilters.go @@ -106,7 +106,7 @@ func (t *Translator) patchHCMWithFilters( } // Add the cors filter, if needed - if err := patchHCMWithCorsFilter(mgr, irListener); err != nil { + if err := patchHCMWithCORSFilter(mgr, irListener); err != nil { return err } @@ -135,7 +135,7 @@ func patchRouteWithFilters( } // Add the cors per route config to the route, if needed. - if err := patchRouteWithCorsConfig(route, irRoute); err != nil { + if err := patchRouteWithCORSConfig(route, irRoute); err != nil { return err } return nil