Skip to content

feat: V1 and V2 of the API Gateway custom authorizer event and the si… #166

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

Merged
merged 4 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.amazonaws.services.lambda.runtime.events;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
* The API Gateway customer authorizer event object as described - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html
*
*/

@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public class APIGatewayCustomAuthorizerEvent {

private String version;
private String type;
private String methodArn;
private String identitySource;
private String authorizationToken;
private String resource;
private String path;
private String httpMethod;
private Map<String, String> headers;
private Map<String, String> queryStringParameters;
private Map<String, String> pathParameters;
private Map<String, String> stageVariables;
private RequestContext requestContext;

@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public static class RequestContext {
private String path;
private String accountId;
private String resourceId;
private String stage;
private String requestId;
private Identity identity;
private String resourcePath;
private String httpMethod;
private String apiId;
}

@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public static class Identity {
private String apiKey;
private String sourceIp;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.amazonaws.services.lambda.runtime.events;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.Map;

/**
* The V2 API Gateway customer authorizer event object as described - https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html
*
*/

@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public class APIGatewayV2CustomAuthorizerEvent {

private String version;
private String type;
private String routeArn;
private List<String> identitySource;
private String routeKey;
private String rawPath;
private String rawQueryString;
private List<String> cookies;
private Map<String, String> headers;
private Map<String, String> queryStringParameters;
private RequestContext requestContext;
private Map<String, String> pathParameters;
private Map<String, String> stageVariables;

@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public static class RequestContext {

private String accountId;
private String apiId;
private String domainName;
private String domainPrefix;
private Http http;
private String requestId;
private String routeKey;
private String stage;
private String time; // "time": "12/Mar/2020:19:03:58 +0000",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be an object?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be better off as a ZonedDateTime object

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, ZonedDateTime (de)serialization is not currently supported in the Java runtimes, either String or org.joda.time.DateTime (currently preferred) should be fine.

Copy link

@pankajagrawal16 pankajagrawal16 Oct 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is possible to write a custom StdDeserializer to achieve this, but we dont want to do that ? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately registering a custom mapper in this library is not currently supported by the Java runtime and this is probably the best solution we can implement at this time IMHO

private int timeEpoch;
}

@AllArgsConstructor
@Builder(setterPrefix = "with")
@Data
@NoArgsConstructor
public static class Http {

private String method;
private String path;
private String protocol;
private String sourceIp;
private String userAgent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.amazonaws.services.lambda.runtime.events;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Map;

/**
* The simplified IAM Policy response object as described in https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-lambda-authorizer.html
*
*/

@Data
@Builder(setterPrefix = "with")
@NoArgsConstructor
@AllArgsConstructor
public class SimpleIAMPolicy {

private boolean isAuthorized;
private Map<String, String> context;
}