-
Notifications
You must be signed in to change notification settings - Fork 560
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
Migrate to java events #657
base: main
Are you sure you want to change the base?
Conversation
The build fails because the V4 of Java-events is not released yet. |
We identified new issues on unchanged lines of code. Navigate to the Amazon CodeGuru Reviewer console to view the recommendations to fix them. |
import static com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletRequest.cleanUri; | ||
import static com.amazonaws.serverless.proxy.internal.servlet.AwsHttpServletRequest.decodeRequestPath; | ||
|
||
public class AwsHttpServletRequestHelper { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
This class references 44 other classes. By comparison, 98% of the classes in the CodeGuru reference dataset reference fewer. This indicates that this class is highly coupled with other classes. A class that is highly coupled with other classes is difficult to understand and its behavior might change unexpectedly when one of its referenced classes is updated. High coupling could also increase the integration test complexity, maintenance cost and technical debt. We recommend that you simplify this class or break it into multiple classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
* @param valueSeparator The separator to be used for parsing header values | ||
* @return A list of SimpleMapEntry objects with all of the possible values for the header. | ||
*/ | ||
protected static List<AwsHttpServletRequest.HeaderValue> parseHeaderValue(String headerValue, String valueSeparator, String qualifierSeparator) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
The cyclomatic complexity of this method is 13. By comparison, 98% of the methods in the CodeGuru reference dataset have a lower cyclomatic complexity. This indicates the method has a high number of decisions and it can make the logic difficult to understand and test.
We recommend that you simplify this method or break it into multiple methods. For example, consider extracting the code block on lines 438-446 into a separate method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class AwsAlbHttpServletRequest extends AwsHttpServletRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Recommendation generated by Amazon CodeGuru Reviewer. Leave feedback on this recommendation by replying to the comment or by reacting to the comment using emoji.
This class references 45 other classes. By comparison, 98% of the classes in the CodeGuru reference dataset reference fewer. This indicates that this class is highly coupled with other classes. A class that is highly coupled with other classes is difficult to understand and its behavior might change unexpectedly when one of its referenced classes is updated. High coupling could also increase the integration test complexity, maintenance cost and technical debt. We recommend that you simplify this class or break it into multiple classes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think breaking this class into multiple classes will increase complexity, making the code very hard to understand.
3b4a0ae
to
3e3965a
Compare
Thanks for all the work you put into it @mbfreder! Could you please rebase on main to resolve the conflicts? I will go through it in detail afterwards... |
3e3965a
to
a00d71f
Compare
Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are almost there :-)
Looking at the code it would be helpful to have not just com.amazonaws.services.lambda.runtime.events.apigateway.HttpRequestEvent
but also something like a V1Payload that bundles some properties of ApplicationLoadBalancerRequestEvent
and APIGatewayProxyRequestEvent
. Just an idea to reduce copy/ paste, not sure if the team would be open for it...
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class AwsAlbExceptionHandler implements ExceptionHandler<AwsProxyResponseEvent>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need that class? Can't we use AwsProxyExceptionHandler
? Unittests ran fine without it.
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class AwsAlbHttpServletRequest extends AwsHttpServletRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a Javadoc comment to the class
|
||
@Override | ||
public String getProtocol() { | ||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is that a valid return value?
} | ||
} | ||
|
||
return new StringBuilder().append("null") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks wrong, see also #647
|
||
if (request.getMultiValueHeaders() != null && request.getMultiValueHeaders().containsKey(HOST_HEADER_NAME)) { | ||
String hostHeader = getFirst(request.getMultiValueHeaders(), HOST_HEADER_NAME); | ||
if (SecurityUtils.isValidHost(hostHeader, "null", region)) { // ALB doesn't have apiId. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
null instead of "null"?
|
||
@Override | ||
public String getRequestId() { | ||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is that empty?
public HttpServletRequest readRequest(ApplicationLoadBalancerRequestEvent request, SecurityContext securityContext, Context lambdaContext, ContainerConfig config) throws InvalidRequestEventException { | ||
// Expect the HTTP method and context to be populated. If they are not, we are handling an | ||
// unsupported event type. | ||
if (request.getHttpMethod() == null || request.getHttpMethod().equals("") || request.getRequestContext() == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace equals("") with isEmpty()
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class AwsAlbHttpServletResponseWriter extends ResponseWriter<AwsHttpServletResponse, AwsProxyResponseEvent> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please create a Javadoc comment on class level
@@ -35,36 +35,38 @@ public class AwsProxySecurityContext | |||
// Constants - Package | |||
//------------------------------------------------------------- | |||
|
|||
static final String AUTH_SCHEME_CUSTOM = "CUSTOM_AUTHORIZER"; | |||
public static final String AUTH_SCHEME_CUSTOM = "CUSTOM_AUTHORIZER"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of making in public you may wanted to use the identical constant from AwsAlbSecurityContext
. either that or have the constants just once (in a base class?).
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>10</source> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be 17
Issue #, if available:
Description of changes:
Migrated to Java-events lib.
The build fails because the V4 of Java-events is not released yet.
By submitting this pull request