diff --git a/go.mod b/go.mod index 3b9b267b..51e7ea9c 100644 --- a/go.mod +++ b/go.mod @@ -6,12 +6,12 @@ require ( github.com/avast/retry-go/v3 v3.1.1 github.com/cloudevents/sdk-go/protocol/nats/v2 v2.14.0 github.com/cloudevents/sdk-go/v2 v2.14.0 - github.com/go-logr/logr v1.3.0 + github.com/go-logr/logr v1.4.1 github.com/go-logr/zapr v1.3.0 github.com/google/uuid v1.5.0 github.com/kelseyhightower/envconfig v1.4.0 - github.com/kyma-project/api-gateway v0.0.0-20231219125807-3eb98237c138 - github.com/kyma-project/kyma/common/logging v0.0.0-20231219124408-e2f66abc2d9a + github.com/kyma-project/api-gateway v0.0.0-20231222161810-7e09cec0147d + github.com/kyma-project/kyma/common/logging v0.0.0-20231220133808-e2c22b79a28b github.com/kyma-project/nats-manager v1.0.3-0.20231219150808-13159cfea47c github.com/mitchellh/hashstructure/v2 v2.0.2 github.com/nats-io/nats-server/v2 v2.10.7 @@ -21,7 +21,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.17.0 github.com/stretchr/testify v1.8.4 - github.com/vektra/mockery/v2 v2.38.0 + github.com/vektra/mockery/v2 v2.39.1 go.uber.org/atomic v1.11.0 go.uber.org/zap v1.26.0 golang.org/x/oauth2 v0.15.0 @@ -39,7 +39,7 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect - github.com/chigopher/pathlib v0.15.0 // indirect + github.com/chigopher/pathlib v0.19.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/emicklei/go-restful/v3 v3.11.0 // indirect github.com/evanphx/json-patch v5.6.0+incompatible // indirect @@ -107,7 +107,7 @@ require ( google.golang.org/appengine v1.6.8 // indirect google.golang.org/genproto v0.0.0-20231002182017-d307bd883b97 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20230920204549-e6e6cdab5c13 // indirect - google.golang.org/protobuf v1.31.0 // indirect + google.golang.org/protobuf v1.32.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect diff --git a/go.sum b/go.sum index 1432a49e..602dac2f 100644 --- a/go.sum +++ b/go.sum @@ -47,8 +47,8 @@ github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dR github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/chigopher/pathlib v0.15.0 h1:1pg96WL3iC1/YyWV4UJSl3E0GBf4B+h5amBtsbAAieY= -github.com/chigopher/pathlib v0.15.0/go.mod h1:3+YPPV21mU9vyw8Mjp+F33CyCfE6iOzinpiqBcccv7I= +github.com/chigopher/pathlib v0.19.1 h1:RoLlUJc0CqBGwq239cilyhxPNLXTK+HXoASGyGznx5A= +github.com/chigopher/pathlib v0.19.1/go.mod h1:tzC1dZLW8o33UQpWkNkhvPwL5n4yyFRFm/jL1YGWFvY= github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI= github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= @@ -87,8 +87,9 @@ github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyT github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= -github.com/go-logr/logr v1.3.0 h1:2y3SDp0ZXuc6/cjLSZ+Q3ir+QB9T/iG5yYRXqsagWSY= github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ= github.com/go-logr/zapr v1.3.0/go.mod h1:YKepepNBd1u/oyhd/yQmtjVXmm9uML4IXUgMOwR8/Gg= github.com/go-openapi/jsonpointer v0.19.6 h1:eCs3fxoIi3Wh6vtgmLTOjdhSpiqphQ+DaPn38N2ZdrE= @@ -215,10 +216,10 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/kyma-project/api-gateway v0.0.0-20231219125807-3eb98237c138 h1:D+Id5H4vn7+e9aqCO56+IQ0cXw2J9FlocfZoZaJXjnY= -github.com/kyma-project/api-gateway v0.0.0-20231219125807-3eb98237c138/go.mod h1:yZEy93fAph+0UOhkfCa4QVkh+R2IvPWWKdCmbIu3/rY= -github.com/kyma-project/kyma/common/logging v0.0.0-20231219124408-e2f66abc2d9a h1:6K6iTCj29ErBL7KpizLOekavD/RaqsC6ByVECNIAqwo= -github.com/kyma-project/kyma/common/logging v0.0.0-20231219124408-e2f66abc2d9a/go.mod h1:JGb5RBi8Uz+RZ/jf54+qA+RqY6uPQBJ8pO1w3KSwm1Q= +github.com/kyma-project/api-gateway v0.0.0-20231222161810-7e09cec0147d h1:e/n/Yz21rtlYH4+BFGHPJ3JEzCmgoG/hQoxPdCC7yP4= +github.com/kyma-project/api-gateway v0.0.0-20231222161810-7e09cec0147d/go.mod h1:mzEmmizP+fyI3QK+qFZhyfSXJbAj+d2AbiXVSmo4fMk= +github.com/kyma-project/kyma/common/logging v0.0.0-20231220133808-e2c22b79a28b h1:mYJvj9IKQyQMwHsyO+7tXd/PYLk4WZKnlbxnmTiDHqQ= +github.com/kyma-project/kyma/common/logging v0.0.0-20231220133808-e2c22b79a28b/go.mod h1:JGb5RBi8Uz+RZ/jf54+qA+RqY6uPQBJ8pO1w3KSwm1Q= github.com/kyma-project/nats-manager v1.0.3-0.20231219150808-13159cfea47c h1:LTWJ2YZBh0DVkFl4eKqR0ZSzlGRHVkiLt6hOxTNV3nc= github.com/kyma-project/nats-manager v1.0.3-0.20231219150808-13159cfea47c/go.mod h1:1vHtViq9rGpz1rWY2RKkBWzDWeEFStZJSqBCMtpuOOI= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= @@ -326,8 +327,8 @@ github.com/subosito/gotenv v1.4.2 h1:X1TuBLAMDFbaTAChgCBLu3DU3UPyELpnF2jjJ2cz/S8 github.com/subosito/gotenv v1.4.2/go.mod h1:ayKnFf/c6rvx/2iiLrJUk1e6plDbT3edrFNGqEflhK0= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/vektra/mockery/v2 v2.38.0 h1:I0LBuUzZHqAU4d1DknW0DTFBPO6n8TaD38WL2KJf3yI= -github.com/vektra/mockery/v2 v2.38.0/go.mod h1:diB13hxXG6QrTR0ol2Rk8s2dRMftzvExSvPDKr+IYKk= +github.com/vektra/mockery/v2 v2.39.1 h1:zgnW69s+351ZF/L+O5pO64MpVP96aDtw8jwOGvGXzwU= +github.com/vektra/mockery/v2 v2.39.1/go.mod h1:dPzGtjT0/Uu4hqpF6QNHwz+GLago7lq1bxdj9wHbGKo= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -679,8 +680,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= -google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/pkg/object/apirule.go b/pkg/object/apirule.go index d1440b1f..2354a295 100644 --- a/pkg/object/apirule.go +++ b/pkg/object/apirule.go @@ -144,7 +144,7 @@ func WithRules(certsURL string, subs []eventingv1alpha2.Subscription, svc apigat for _, sub := range subs { hostURL, err := url.ParseRequestURI(sub.Spec.Sink) if err != nil { - // It's ok as the relevant subscription will have a valid cluster local URL in the same namespace + // It's ok as the relevant subscription will have a valid cluster local URL in the same namespace. continue } if hostURL.Path == "" { @@ -157,7 +157,7 @@ func WithRules(certsURL string, subs []eventingv1alpha2.Subscription, svc apigat for _, path := range uniquePaths { rule := apigatewayv1beta1.Rule{ Path: path, - Methods: methods, + Methods: StringsToMethods(methods), AccessStrategies: accessStrategies, Service: &svc, } @@ -166,3 +166,12 @@ func WithRules(certsURL string, subs []eventingv1alpha2.Subscription, svc apigat r.Spec.Rules = rules } } + +// StringsToMethods converts a slice of strings into a slice of HttpMethod as defined by api-gateway. +func StringsToMethods(methods []string) []apigatewayv1beta1.HttpMethod { + httpMethodes := []apigatewayv1beta1.HttpMethod{} + for _, m := range methods { + httpMethodes = append(httpMethodes, apigatewayv1beta1.HttpMethod(m)) + } + return httpMethodes +} diff --git a/pkg/object/apirule_test.go b/pkg/object/apirule_test.go index e2435ec4..8944a993 100644 --- a/pkg/object/apirule_test.go +++ b/pkg/object/apirule_test.go @@ -2,6 +2,7 @@ package object import ( "fmt" + "net/http" "reflect" "testing" @@ -14,6 +15,30 @@ import ( eventingv1alpha2 "github.com/kyma-project/eventing-manager/api/eventing/v1alpha2" ) +func TestStringsToMethods(t *testing.T) { + // arrange + givenStrings := []string{ + http.MethodGet, + http.MethodPut, + http.MethodHead, + http.MethodPost, + http.MethodPatch, + http.MethodConnect, + http.MethodTrace, + http.MethodOptions, + http.MethodDelete, + } + + // act + methods := StringsToMethods(givenStrings) + actualStrings := apigatewayv1beta1.ConvertHttpMethodsToStrings(methods) + + // assert + if !reflect.DeepEqual(givenStrings, actualStrings) { + t.Fatalf("slices of strings are not. wanted: %v but got %v", givenStrings, actualStrings) + } +} + func TestApplyExistingAPIRuleAttributes(t *testing.T) { // given const ( @@ -579,7 +604,9 @@ func TestWithRules(t *testing.T) { Spec: eventingv1alpha2.SubscriptionSpec{Sink: sink1}, } - methods = []string{"some.method"} + methods = []string{ + http.MethodGet, + } ) type args struct { @@ -620,7 +647,7 @@ func TestWithRules(t *testing.T) { Port: ptr.To(port), IsExternal: ptr.To(external), }, - Methods: methods, + Methods: StringsToMethods(methods), AccessStrategies: []*apigatewayv1beta1.Authenticator{ { Handler: &apigatewayv1beta1.Handler{ @@ -639,7 +666,7 @@ func TestWithRules(t *testing.T) { Port: ptr.To(port), IsExternal: ptr.To(external), }, - Methods: methods, + Methods: StringsToMethods(methods), AccessStrategies: []*apigatewayv1beta1.Authenticator{ { Handler: &apigatewayv1beta1.Handler{ diff --git a/pkg/object/equality_test.go b/pkg/object/equality_test.go index c2a7411b..2926486b 100644 --- a/pkg/object/equality_test.go +++ b/pkg/object/equality_test.go @@ -32,8 +32,8 @@ func TestApiRuleEqual(t *testing.T) { } rule := apigatewayv1beta1.Rule{ Path: "path", - Methods: []string{ - http.MethodPost, + Methods: []apigatewayv1beta1.HttpMethod{ + apigatewayv1beta1.HttpMethod(http.MethodPost), }, AccessStrategies: []*apigatewayv1beta1.Authenticator{ { @@ -130,7 +130,9 @@ func TestApiRuleEqual(t *testing.T) { prep: func() *apigatewayv1beta1.APIRule { apiRuleCopy := apiRule.DeepCopy() newRule := rule.DeepCopy() - newRule.Methods = []string{http.MethodOptions} + newRule.Methods = []apigatewayv1beta1.HttpMethod{ + apigatewayv1beta1.HttpMethod(http.MethodOptions), + } apiRuleCopy.Spec.Rules = []apigatewayv1beta1.Rule{*newRule} return apiRuleCopy }, diff --git a/testing/matchers.go b/testing/matchers.go index 03adb9ad..86bc89bb 100644 --- a/testing/matchers.go +++ b/testing/matchers.go @@ -49,7 +49,7 @@ func HaveAPIRuleSpecRules(ruleMethods []string, accessStrategy, certsURL, path s return a.Spec.Rules }, ContainElement( MatchFields(IgnoreExtras|IgnoreMissing, Fields{ - "Methods": ConsistOf(ruleMethods), + "Methods": ConsistOf(object.StringsToMethods(ruleMethods)), "AccessStrategies": ConsistOf(haveAPIRuleAccessStrategies(authenticator)), "Gateway": Equal(constants.ClusterLocalAPIGateway), "Path": Equal(path), @@ -68,7 +68,7 @@ func HaveAPIRuleSpecRulesWithOry(ruleMethods []string, accessStrategy, path stri return a.Spec.Rules }, ContainElement( MatchFields(IgnoreExtras|IgnoreMissing, Fields{ - "Methods": ConsistOf(ruleMethods), + "Methods": ConsistOf(object.StringsToMethods(ruleMethods)), "AccessStrategies": ConsistOf(haveAPIRuleAccessStrategiesWithOry(accessStrategy)), "Gateway": Equal(constants.ClusterLocalAPIGateway), "Path": Equal(path), diff --git a/testing/test_helpers.go b/testing/test_helpers.go index ee7e3a3e..b51aec66 100644 --- a/testing/test_helpers.go +++ b/testing/test_helpers.go @@ -370,9 +370,9 @@ func WithPath() APIRuleOption { r.Spec.Rules = []apigatewayv1beta1.Rule{ { Path: "/path", - Methods: []string{ - http.MethodPost, - http.MethodOptions, + Methods: []apigatewayv1beta1.HttpMethod{ + apigatewayv1beta1.HttpMethod(http.MethodPost), + apigatewayv1beta1.HttpMethod(http.MethodOptions), }, AccessStrategies: []*apigatewayv1beta1.Authenticator{ authenticator,