Skip to content

Commit 81f49fa

Browse files
committed
feat: allow private
1 parent d7c710d commit 81f49fa

File tree

3 files changed

+171
-0
lines changed

3 files changed

+171
-0
lines changed

lib/apiGateway/schema.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const method = Joi.string()
2323
.valid(['get', 'post', 'put', 'patch', 'options', 'head', 'delete', 'any'])
2424
.insensitive()
2525

26+
const privateField = Joi.boolean().default(false)
27+
2628
const cors = Joi.alternatives().try(
2729
Joi.boolean(),
2830
Joi.object({
@@ -98,6 +100,7 @@ const proxy = Joi.object({
98100
pathOverride,
99101
method,
100102
cors,
103+
private: privateField,
101104
authorizationType,
102105
authorizerId,
103106
authorizationScopes,

lib/apiGateway/validate.test.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,75 @@ describe('#validateServiceProxies()', () => {
137137
expect(() => serverlessApigatewayServiceProxy.validateServiceProxies()).to.not.throw()
138138
})
139139

140+
it('should work if "private" property is missing', () => {
141+
serverlessApigatewayServiceProxy.serverless.service.custom = {
142+
apiGatewayServiceProxies: [
143+
{
144+
kinesis: {
145+
path: '/kinesis',
146+
streamName: 'streamName',
147+
method: 'POST'
148+
}
149+
}
150+
]
151+
}
152+
153+
expect(() => serverlessApigatewayServiceProxy.validateServiceProxies()).to.not.throw()
154+
})
155+
156+
it('should work if "private" property is true', () => {
157+
serverlessApigatewayServiceProxy.serverless.service.custom = {
158+
apiGatewayServiceProxies: [
159+
{
160+
kinesis: {
161+
path: '/kinesis',
162+
streamName: 'streamName',
163+
method: 'POST',
164+
private: true
165+
}
166+
}
167+
]
168+
}
169+
170+
expect(() => serverlessApigatewayServiceProxy.validateServiceProxies()).to.not.throw()
171+
})
172+
173+
it('should work if "private" property is false', () => {
174+
serverlessApigatewayServiceProxy.serverless.service.custom = {
175+
apiGatewayServiceProxies: [
176+
{
177+
kinesis: {
178+
path: '/kinesis',
179+
streamName: 'streamName',
180+
method: 'POST',
181+
private: false
182+
}
183+
}
184+
]
185+
}
186+
187+
expect(() => serverlessApigatewayServiceProxy.validateServiceProxies()).to.not.throw()
188+
})
189+
190+
it('should throw if "private" property is set to unsupported type', () => {
191+
serverlessApigatewayServiceProxy.serverless.service.custom = {
192+
apiGatewayServiceProxies: [
193+
{
194+
kinesis: {
195+
path: '/kinesis',
196+
streamName: 'streamName',
197+
method: 'POST',
198+
private: 'xxxxx'
199+
}
200+
}
201+
]
202+
}
203+
expect(() => serverlessApigatewayServiceProxy.validateServiceProxies()).to.throw(
204+
serverless.classes.Error,
205+
'child "kinesis" fails because [child "private" fails because ["private" must be a boolean]]'
206+
)
207+
})
208+
140209
it('should process cors defaults', () => {
141210
serverlessApigatewayServiceProxy.serverless.service.custom = {
142211
apiGatewayServiceProxies: [

lib/package/sqs/compileMethodsToSqs.test.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,105 @@ describe('#compileMethodsToSqs()', () => {
221221
})
222222
})
223223

224+
it('should create corresponding resources when sqs proxies are given with private', () => {
225+
serverlessApigatewayServiceProxy.validated = {
226+
events: [
227+
{
228+
serviceName: 'sqs',
229+
http: {
230+
queueName: 'myQueue',
231+
path: 'sqs',
232+
method: 'post',
233+
auth: {
234+
authorizationType: 'NONE'
235+
},
236+
private: true
237+
}
238+
}
239+
]
240+
}
241+
serverlessApigatewayServiceProxy.apiGatewayRestApiLogicalId = 'ApiGatewayRestApi'
242+
serverlessApigatewayServiceProxy.apiGatewayResources = {
243+
sqs: {
244+
name: 'sqs',
245+
resourceLogicalId: 'ApiGatewayResourceSqs'
246+
}
247+
}
248+
249+
serverlessApigatewayServiceProxy.compileMethodsToSqs()
250+
251+
expect(serverless.service.provider.compiledCloudFormationTemplate.Resources).to.deep.equal({
252+
ApiGatewayMethodsqsPost: {
253+
Type: 'AWS::ApiGateway::Method',
254+
Properties: {
255+
HttpMethod: 'POST',
256+
RequestParameters: {},
257+
AuthorizationType: 'NONE',
258+
AuthorizationScopes: undefined,
259+
AuthorizerId: undefined,
260+
ApiKeyRequired: true,
261+
ResourceId: { Ref: 'ApiGatewayResourceSqs' },
262+
RestApiId: { Ref: 'ApiGatewayRestApi' },
263+
Integration: {
264+
IntegrationHttpMethod: 'POST',
265+
Type: 'AWS',
266+
Credentials: { 'Fn::GetAtt': ['ApigatewayToSqsRole', 'Arn'] },
267+
Uri: {
268+
'Fn::Sub': [
269+
'arn:aws:apigateway:${AWS::Region}:sqs:path//${AWS::AccountId}/${queueName}',
270+
{
271+
queueName: 'myQueue'
272+
}
273+
]
274+
},
275+
RequestParameters: {
276+
'integration.request.querystring.Action': "'SendMessage'",
277+
'integration.request.querystring.MessageBody': 'method.request.body'
278+
},
279+
RequestTemplates: { 'application/json': '{statusCode:200}' },
280+
IntegrationResponses: [
281+
{
282+
StatusCode: 200,
283+
SelectionPattern: 200,
284+
ResponseParameters: {},
285+
ResponseTemplates: {}
286+
},
287+
{
288+
StatusCode: 400,
289+
SelectionPattern: 400,
290+
ResponseParameters: {},
291+
ResponseTemplates: {}
292+
},
293+
{
294+
StatusCode: 500,
295+
SelectionPattern: 500,
296+
ResponseParameters: {},
297+
ResponseTemplates: {}
298+
}
299+
]
300+
},
301+
MethodResponses: [
302+
{
303+
ResponseParameters: {},
304+
ResponseModels: {},
305+
StatusCode: 200
306+
},
307+
{
308+
ResponseParameters: {},
309+
ResponseModels: {},
310+
StatusCode: 400
311+
},
312+
{
313+
ResponseParameters: {},
314+
ResponseModels: {},
315+
StatusCode: 500
316+
}
317+
]
318+
}
319+
}
320+
})
321+
})
322+
224323
it('should not create corresponding resources when other proxies are given', () => {
225324
serverlessApigatewayServiceProxy.validated = {
226325
events: [

0 commit comments

Comments
 (0)