Skip to content

Commit 7af6680

Browse files
committed
Added stage to environment
1 parent 3406036 commit 7af6680

File tree

5 files changed

+57
-79
lines changed

5 files changed

+57
-79
lines changed

config-layers/common/in/erail/amazon/lambda/service/ProxyService.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ enable=true
88
log=true
99
host^=/in/erail/server/HttpServerOptions.host
1010
port^=/in/erail/server/HttpServerOptions.port
11-
pathPrefix=/v1
1211
webClient=/io/vertx/ext/web/client/WebClient
1312
server=/in/erail/server/Server

src/main/java/in/erail/amazon/lambda/AWSLambda.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,20 @@ public Single<String> handleMessage(JsonObject pRequest) {
7070
.subscribeOn(Schedulers.computation())
7171
.map(this::convertBodyToBase64)
7272
.map(reqJson -> reqJson.mapTo(RequestEvent.class))
73+
.doOnSuccess(this::populateSystemProperties)
7374
.flatMapMaybe(req -> getService().process(req))
7475
.toSingle(new ResponseEvent())
7576
.map(resp -> JsonObject.mapFrom(resp))
7677
.map(this::sanatizeResponse)
7778
.map(respJson -> respJson.toString());
7879
}
7980

81+
protected void populateSystemProperties(RequestEvent pRequest) {
82+
Optional
83+
.ofNullable(pRequest.getRequestContext().get("stage"))
84+
.ifPresent(s -> System.setProperty("stage", s.toString()));
85+
}
86+
8087
protected JsonObject sanatizeResponse(JsonObject pResp) {
8188
Preconditions.checkNotNull(pResp);
8289

src/main/java/in/erail/amazon/lambda/service/ProxyService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package in.erail.amazon.lambda.service;
22

33
import com.google.common.base.Joiner;
4-
import com.google.common.io.BaseEncoding;
54
import in.erail.model.RequestEvent;
65
import in.erail.model.ResponseEvent;
76
import in.erail.server.Server;

src/test/java/in/erail/amazon/lambda/AWSLambdaTest.java

Lines changed: 48 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -20,81 +20,49 @@ public class AWSLambdaTest {
2020
public Timeout rule = Timeout.seconds(2000);
2121

2222
public static String EVENT_MSG = "{\n"
23-
+ " \"resource\": \"/hello\",\n"
24-
+ " \"path\": \"/hello\",\n"
25-
+ " \"httpMethod\": \"GET\",\n"
23+
+ " \"resource\": \"/{proxy+}\",\n"
24+
+ " \"path\": \"/v1/users\",\n"
25+
+ " \"httpMethod\": \"POST\",\n"
2626
+ " \"headers\": {\n"
27-
+ " \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\",\n"
28-
+ " \"Accept-Encoding\": \"gzip, deflate, br\",\n"
29-
+ " \"Accept-Language\": \"en-GB,en-US;q=0.9,en;q=0.8\",\n"
30-
+ " \"cache-control\": \"max-age=0\",\n"
31-
+ " \"CloudFront-Forwarded-Proto\": \"https\",\n"
32-
+ " \"CloudFront-Is-Desktop-Viewer\": \"true\",\n"
33-
+ " \"CloudFront-Is-Mobile-Viewer\": \"false\",\n"
34-
+ " \"CloudFront-Is-SmartTV-Viewer\": \"false\",\n"
35-
+ " \"CloudFront-Is-Tablet-Viewer\": \"false\",\n"
36-
+ " \"CloudFront-Viewer-Country\": \"GB\",\n"
37-
+ " \"Host\": \"bhpdtkdfek.execute-api.us-east-2.amazonaws.com\",\n"
38-
+ " \"upgrade-insecure-requests\": \"1\",\n"
39-
+ " \"User-Agent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36\",\n"
40-
+ " \"Via\": \"2.0 cd068397b3367ed727e4988c0cabf85a.cloudfront.net (CloudFront)\",\n"
41-
+ " \"X-Amz-Cf-Id\": \"6opg4d-x5Hptb8RAXkVBhgxlN-KZbU57CU2ew1AVns864MLepMpESA==\",\n"
42-
+ " \"X-Amzn-Trace-Id\": \"Root=1-5c22ae99-c8f508c5e9bdc966fbd01b03\",\n"
43-
+ " \"X-Forwarded-For\": \"92.234.149.241, 70.132.20.88\",\n"
27+
+ " \"Accept\": \"*/*\",\n"
28+
+ " \"accept-encoding\": \"gzip, deflate\",\n"
29+
+ " \"cache-control\": \"no-cache\",\n"
30+
+ " \"Content-Type\": \"application/json\",\n"
31+
+ " \"Host\": \"jtsxwpy65j.execute-api.us-east-2.amazonaws.com\",\n"
32+
+ " \"Postman-Token\": \"dbbdafc8-5cc7-451c-b767-9f19eeb19941\",\n"
33+
+ " \"User-Agent\": \"PostmanRuntime/7.4.0\",\n"
34+
+ " \"X-Amzn-Trace-Id\": \"Root=1-5c2e854c-db47d2066bcaa15629df52d5\",\n"
35+
+ " \"X-Forwarded-For\": \"49.36.130.148\",\n"
4436
+ " \"X-Forwarded-Port\": \"443\",\n"
4537
+ " \"X-Forwarded-Proto\": \"https\"\n"
4638
+ " },\n"
4739
+ " \"multiValueHeaders\": {\n"
4840
+ " \"Accept\": [\n"
49-
+ " \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\"\n"
41+
+ " \"*/*\"\n"
5042
+ " ],\n"
51-
+ " \"Accept-Encoding\": [\n"
52-
+ " \"gzip, deflate, br\"\n"
53-
+ " ],\n"
54-
+ " \"Accept-Language\": [\n"
55-
+ " \"en-GB,en-US;q=0.9,en;q=0.8\"\n"
43+
+ " \"accept-encoding\": [\n"
44+
+ " \"gzip, deflate\"\n"
5645
+ " ],\n"
5746
+ " \"cache-control\": [\n"
58-
+ " \"max-age=0\"\n"
59-
+ " ],\n"
60-
+ " \"CloudFront-Forwarded-Proto\": [\n"
61-
+ " \"https\"\n"
62-
+ " ],\n"
63-
+ " \"CloudFront-Is-Desktop-Viewer\": [\n"
64-
+ " \"true\"\n"
65-
+ " ],\n"
66-
+ " \"CloudFront-Is-Mobile-Viewer\": [\n"
67-
+ " \"false\"\n"
68-
+ " ],\n"
69-
+ " \"CloudFront-Is-SmartTV-Viewer\": [\n"
70-
+ " \"false\"\n"
47+
+ " \"no-cache\"\n"
7148
+ " ],\n"
72-
+ " \"CloudFront-Is-Tablet-Viewer\": [\n"
73-
+ " \"false\"\n"
74-
+ " ],\n"
75-
+ " \"CloudFront-Viewer-Country\": [\n"
76-
+ " \"GB\"\n"
49+
+ " \"Content-Type\": [\n"
50+
+ " \"application/json\"\n"
7751
+ " ],\n"
7852
+ " \"Host\": [\n"
79-
+ " \"bhpdtkdfek.execute-api.us-east-2.amazonaws.com\"\n"
53+
+ " \"jtsxwpy65j.execute-api.us-east-2.amazonaws.com\"\n"
8054
+ " ],\n"
81-
+ " \"upgrade-insecure-requests\": [\n"
82-
+ " \"1\"\n"
55+
+ " \"Postman-Token\": [\n"
56+
+ " \"dbbdafc8-5cc7-451c-b767-9f19eeb19941\"\n"
8357
+ " ],\n"
8458
+ " \"User-Agent\": [\n"
85-
+ " \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36\"\n"
86-
+ " ],\n"
87-
+ " \"Via\": [\n"
88-
+ " \"2.0 cd068397b3367ed727e4988c0cabf85a.cloudfront.net (CloudFront)\"\n"
89-
+ " ],\n"
90-
+ " \"X-Amz-Cf-Id\": [\n"
91-
+ " \"6opg4d-x5Hptb8RAXkVBhgxlN-KZbU57CU2ew1AVns864MLepMpESA==\"\n"
59+
+ " \"PostmanRuntime/7.4.0\"\n"
9260
+ " ],\n"
9361
+ " \"X-Amzn-Trace-Id\": [\n"
94-
+ " \"Root=1-5c22ae99-c8f508c5e9bdc966fbd01b03\"\n"
62+
+ " \"Root=1-5c2e854c-db47d2066bcaa15629df52d5\"\n"
9563
+ " ],\n"
9664
+ " \"X-Forwarded-For\": [\n"
97-
+ " \"92.234.149.241, 70.132.20.88\"\n"
65+
+ " \"49.36.130.148\"\n"
9866
+ " ],\n"
9967
+ " \"X-Forwarded-Port\": [\n"
10068
+ " \"443\"\n"
@@ -105,39 +73,43 @@ public class AWSLambdaTest {
10573
+ " },\n"
10674
+ " \"queryStringParameters\": null,\n"
10775
+ " \"multiValueQueryStringParameters\": null,\n"
108-
+ " \"pathParameters\": null,\n"
109-
+ " \"stageVariables\": null,\n"
76+
+ " \"pathParameters\": {\n"
77+
+ " \"proxy\": \"v1/users\"\n"
78+
+ " },\n"
79+
+ " \"stageVariables\": {\n"
80+
+ " \"lambdaAlias\": \"test\"\n"
81+
+ " },\n"
11082
+ " \"requestContext\": {\n"
111-
+ " \"resourceId\": \"ikgn3l\",\n"
112-
+ " \"resourcePath\": \"/session\",\n"
113-
+ " \"httpMethod\": \"GET\",\n"
114-
+ " \"extendedRequestId\": \"SfA3_EY2CYcFowA=\",\n"
115-
+ " \"requestTime\": \"25/Dec/2018:22:26:33 +0000\",\n"
116-
+ " \"path\": \"/tutorial/session\",\n"
117-
+ " \"accountId\": \"762985365920\",\n"
83+
+ " \"resourceId\": \"tjdogf\",\n"
84+
+ " \"resourcePath\": \"/{proxy+}\",\n"
85+
+ " \"httpMethod\": \"POST\",\n"
86+
+ " \"extendedRequestId\": \"S8nEBFgziYcFXrg=\",\n"
87+
+ " \"requestTime\": \"03/Jan/2019:21:57:32 +0000\",\n"
88+
+ " \"path\": \"/test/v1/users\",\n"
89+
+ " \"accountId\": \"904774318525\",\n"
11890
+ " \"protocol\": \"HTTP/1.1\",\n"
119-
+ " \"stage\": \"tutorial\",\n"
120-
+ " \"domainPrefix\": \"bhpdtkdfek\",\n"
121-
+ " \"requestTimeEpoch\": 1545776793579,\n"
122-
+ " \"requestId\": \"22568c6e-0894-11e9-90cf-f74da74d2315\",\n"
91+
+ " \"stage\": \"test\",\n"
92+
+ " \"domainPrefix\": \"jtsxwpy65j\",\n"
93+
+ " \"requestTimeEpoch\": 1546552652926,\n"
94+
+ " \"requestId\": \"928bba1b-0fa2-11e9-ad27-8354b9dd01f4\",\n"
12395
+ " \"identity\": {\n"
12496
+ " \"cognitoIdentityPoolId\": null,\n"
12597
+ " \"accountId\": null,\n"
12698
+ " \"cognitoIdentityId\": null,\n"
12799
+ " \"caller\": null,\n"
128-
+ " \"sourceIp\": \"92.234.149.241\",\n"
100+
+ " \"sourceIp\": \"49.36.130.148\",\n"
129101
+ " \"accessKey\": null,\n"
130102
+ " \"cognitoAuthenticationType\": null,\n"
131103
+ " \"cognitoAuthenticationProvider\": null,\n"
132104
+ " \"userArn\": null,\n"
133-
+ " \"userAgent\": \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36\",\n"
105+
+ " \"userAgent\": \"PostmanRuntime/7.4.0\",\n"
134106
+ " \"user\": null\n"
135107
+ " },\n"
136-
+ " \"domainName\": \"bhpdtkdfek.execute-api.us-east-2.amazonaws.com\",\n"
137-
+ " \"apiId\": \"bhpdtkdfek\"\n"
108+
+ " \"domainName\": \"jtsxwpy65j.execute-api.us-east-2.amazonaws.com\",\n"
109+
+ " \"apiId\": \"jtsxwpy65j\"\n"
138110
+ " },\n"
139-
+ " \"body\": null,\n"
140-
+ " \"isBase64Encoded\": false "
111+
+ " \"body\": \"ewogICAgInR5cGUiOiAiQURNSU4iLAogICAgImZpcnN0TmFtZSI6ICJGaXJzdCBOYW1lIiwKICAgICJtaWRkbGVOYW1lIjogIk1pZGRsZSBOYW1lIiwKICAgICJsYXN0TmFtZSI6ICJMYXN0IE5hbWUiLAogICAgImFkZHJlc3MiOiAiVUI5OTIyIiwKICAgICJkb2IiOiAiMTk5Ni0xMC0xNSIsCiAgICAicGhvbmVMYW5kbGluZSI6ICI5ODc2NTU0NjYiLAogICAgInBob25lTW9iaWxlIjogIjQ0NDQ0NDQ0MzQzIiwKICAgICJwZXJtaXNzaW9ucyI6IFsKICAgICAgICAiYWxsIgogICAgXSwKICAgICJ1c2VybmFtZSI6ICJ1c2VyIG5hbWUiLAogICAgInBhc3N3b3JkIjogInVzZXIgcGFzc3dvcmQiCn0=\",\n"
112+
+ " \"isBase64Encoded\": true\n"
141113
+ "}";
142114

143115
@Test
@@ -154,6 +126,7 @@ public void testProcess() {
154126
assertTrue(jsonResp.containsKey("multiValueHeaders"));
155127
assertTrue(jsonResp.containsKey("body"));
156128
assertEquals(jsonResp.fieldNames().size(), 5);
129+
assertEquals(System.getProperty("stage"), "test");
157130
}
158131

159132
}

src/test/java/in/erail/amazon/lambda/service/ProxyServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ public class ProxyServiceTest {
2222
public Timeout rule = Timeout.seconds(2000);
2323

2424
public static String EVENT_MSG = "{\n"
25-
+ " \"resource\": \"/hello\",\n"
26-
+ " \"path\": \"/hello\",\n"
25+
+ " \"resource\": \"/v1/hello\",\n"
26+
+ " \"path\": \"/v1/hello\",\n"
2727
+ " \"httpMethod\": \"GET\",\n"
2828
+ " \"headers\": {\n"
2929
+ " \"Accept\": \"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\",\n"

0 commit comments

Comments
 (0)