Skip to content
Snippets Groups Projects
Commit 7b9d39d2 authored by Francé Wilke's avatar Francé Wilke
Browse files

Remove "legacy" handler checks

parent 10715b81
No related branches found
No related tags found
No related merge requests found
...@@ -3,7 +3,6 @@ package handler_utils ...@@ -3,7 +3,6 @@ package handler_utils
import ( import (
"github.com/aws/aws-lambda-go/events" "github.com/aws/aws-lambda-go/events"
"gitlab.com/uafrica/go-utils/errors" "gitlab.com/uafrica/go-utils/errors"
"gitlab.com/uafrica/go-utils/logs"
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
...@@ -12,8 +11,6 @@ import ( ...@@ -12,8 +11,6 @@ import (
// ValidateAPIEndpoints checks that all API endpoints are correctly defined using one of the supported handler types // ValidateAPIEndpoints checks that all API endpoints are correctly defined using one of the supported handler types
// return updated endpoints with additional information // return updated endpoints with additional information
func ValidateAPIEndpoints(endpoints map[string]map[string]interface{}) (map[string]map[string]interface{}, error) { func ValidateAPIEndpoints(endpoints map[string]map[string]interface{}) (map[string]map[string]interface{}, error) {
countLegacy := 0
countHandler := 0
for resource, methodHandlers := range endpoints { for resource, methodHandlers := range endpoints {
if resource == "" { if resource == "" {
return nil, errors.Errorf("blank resource") return nil, errors.Errorf("blank resource")
...@@ -35,21 +32,14 @@ func ValidateAPIEndpoints(endpoints map[string]map[string]interface{}) (map[stri ...@@ -35,21 +32,14 @@ func ValidateAPIEndpoints(endpoints map[string]map[string]interface{}) (map[stri
return nil, errors.Errorf("nil handler on %s %s", method, resource) return nil, errors.Errorf("nil handler on %s %s", method, resource)
} }
if _, ok := handlerFunc.(func(req events.APIGatewayProxyRequest) (response events.APIGatewayProxyResponse, err error)); ok {
//ok - leave as is - we support this legacyHandler
countLegacy++
} else {
handler, err := NewHandler(handlerFunc) handler, err := NewHandler(handlerFunc)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "%s %s has invalid handler %T", method, resource, handlerFunc) return nil, errors.Wrapf(err, "%s %s has invalid handler %T", method, resource, handlerFunc)
} }
//replace the endpoint value so that we can quickly call this handler //replace the endpoint value so that we can quickly call this handler
endpoints[resource][method] = handler endpoints[resource][method] = handler
countHandler++
}
} }
} }
logs.Info("Checked %d legacy and %d new handlers\n", countLegacy, countHandler)
return endpoints, nil return endpoints, nil
} }
...@@ -106,8 +96,6 @@ func ValidateRequestParams(request *events.APIGatewayProxyRequest, paramsStructT ...@@ -106,8 +96,6 @@ func ValidateRequestParams(request *events.APIGatewayProxyRequest, paramsStructT
return paramsStructValuePtr, nil return paramsStructValuePtr, nil
} }
func setParamFromStr(fieldValue reflect.Value, paramStrValue string) error { func setParamFromStr(fieldValue reflect.Value, paramStrValue string) error {
switch fieldValue.Type().Kind() { switch fieldValue.Type().Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
......
...@@ -11,8 +11,6 @@ import ( ...@@ -11,8 +11,6 @@ import (
// ValidateSQSEndpoints checks that all SQS endpoints are correctly defined using one of the supported handler types // ValidateSQSEndpoints checks that all SQS endpoints are correctly defined using one of the supported handler types
// return updated endpoints with additional information // return updated endpoints with additional information
func ValidateSQSEndpoints(endpoints map[string]interface{}) (map[string]interface{}, error) { func ValidateSQSEndpoints(endpoints map[string]interface{}) (map[string]interface{}, error) {
countLegacy := 0
countHandler := 0
for messageType, handlerFunc := range endpoints { for messageType, handlerFunc := range endpoints {
if messageType == "" { if messageType == "" {
return nil, errors.Errorf("blank messageType") return nil, errors.Errorf("blank messageType")
...@@ -21,10 +19,6 @@ func ValidateSQSEndpoints(endpoints map[string]interface{}) (map[string]interfac ...@@ -21,10 +19,6 @@ func ValidateSQSEndpoints(endpoints map[string]interface{}) (map[string]interfac
return nil, errors.Errorf("nil handler on %s", messageType) return nil, errors.Errorf("nil handler on %s", messageType)
} }
if _, ok := handlerFunc.(func(req events.SQSEvent) (err error)); ok {
// ok - leave as is - we support this legacyHandler
countLegacy++
} else {
handler, err := NewSQSHandler(handlerFunc) handler, err := NewSQSHandler(handlerFunc)
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "%v has invalid handler %T", messageType, handlerFunc) return nil, errors.Wrapf(err, "%v has invalid handler %T", messageType, handlerFunc)
...@@ -32,10 +26,7 @@ func ValidateSQSEndpoints(endpoints map[string]interface{}) (map[string]interfac ...@@ -32,10 +26,7 @@ func ValidateSQSEndpoints(endpoints map[string]interface{}) (map[string]interfac
// replace the endpoint value so we can quickly call this handler // replace the endpoint value so we can quickly call this handler
endpoints[messageType] = handler endpoints[messageType] = handler
logs.Info("%s: OK (request: %v)\n", messageType, handler.RecordType) logs.Info("%s: OK (request: %v)\n", messageType, handler.RecordType)
countHandler++
} }
}
logs.Info("Checked %d legacy and %d new handlers\n", countLegacy, countHandler)
return endpoints, nil return endpoints, nil
} }
......
...@@ -7,9 +7,8 @@ import ( ...@@ -7,9 +7,8 @@ import (
"strings" "strings"
) )
//convert fields in a struct to a map of parameters, as if defined in a URL // MapParams convert fields in a struct to a map of parameters, as if defined in a URL
//we use this mainly for legacy functions that expect params to be defined in a map[string]string // to convert the new params struct into a map[string]string
//to convert the new params struct into such a map
func MapParams(data interface{}) map[string]string { func MapParams(data interface{}) map[string]string {
params := map[string]string{} params := map[string]string{}
addStructParams(params, reflect.ValueOf(data)) addStructParams(params, reflect.ValueOf(data))
...@@ -42,7 +41,6 @@ func addStructParams(params map[string]string, structValue reflect.Value) { ...@@ -42,7 +41,6 @@ func addStructParams(params map[string]string, structValue reflect.Value) {
} }
if !skip { if !skip {
// lists must be written as JSON lists so they can be unmarshalled // lists must be written as JSON lists so they can be unmarshalled
//jsut because that is how the legacy code did it
if t.Field(i).Type.Kind() == reflect.Slice { if t.Field(i).Type.Kind() == reflect.Slice {
jsonValue, _ := json.Marshal(structValue.Field(i).Interface()) jsonValue, _ := json.Marshal(structValue.Field(i).Interface())
params[jsonTags[0]] = string(jsonValue) params[jsonTags[0]] = string(jsonValue)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment