Skip to content

Commit 249cd00

Browse files
committed
chore: #49 camelCase for the functionality and adding greedy to readme
1 parent ce86c60 commit 249cd00

File tree

4 files changed

+148
-6
lines changed

4 files changed

+148
-6
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ custom:
214214
path: /s3/{folder}/{file}
215215
method: get
216216
action: GetObject
217-
pathoverride: '{folder}/{file}.xml'
217+
pathOverride: '{folder}/{file}.xml'
218218
bucket:
219219
Ref: S3Bucket
220220
cors: true
@@ -229,6 +229,30 @@ custom:
229229
This will result in API Gateway setting the Path Override attribute to `{bucket}/{folder}/{file}.xml`
230230
So for example if you navigate to the API Gatway endpoint `/language/en` it will fetch the file in S3 from `{bucket}/language/en.xml`
231231

232+
##### Can use greedy, for deeper Folders
233+
The forementioned example can also be shortened by a greedy approach. Thanks to @taylorreece for mentioning this.
234+
235+
```yaml
236+
custom:
237+
apiGatewayServiceProxies:
238+
- s3:
239+
path: /s3/{myPath+}
240+
method: get
241+
action: GetObject
242+
pathOverride: '{myPath}.xml'
243+
bucket:
244+
Ref: S3Bucket
245+
cors: true
246+
247+
requestParameters:
248+
# if requestParameters has a 'integration.request.path.object' property you should remove the key setting
249+
'integration.request.path.myPath': 'method.request.path.myPath'
250+
'integration.request.path.object': 'context.requestId'
251+
'integration.request.header.cache-control': "'public, max-age=31536000, immutable'"
252+
```
253+
254+
This will translate for example `/s3/a/b/c` to `a/b/c.xml`
255+
232256
### SNS
233257

234258
Sample syntax for SNS proxy in `serverless.yml`.

lib/apiGateway/schema.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ const roleArn = stringOrGetAtt('roleArn', 'Arn')
9191

9292
const acceptParameters = Joi.object().pattern(Joi.string(), Joi.boolean().required())
9393

94-
const pathoverride = Joi.string()
94+
const pathOverride = Joi.string()
9595

9696
const proxy = Joi.object({
9797
path,
98-
pathoverride,
98+
pathOverride,
9999
method,
100100
cors,
101101
authorizationType,

lib/package/s3/compileMethodsToS3.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ module.exports = {
144144

145145
let pather = '{bucket}/{object}'
146146

147-
if (_.has(http, 'pathoverride')) {
148-
pather = '{bucket}/' + http.pathoverride
147+
if (_.has(http, 'pathOverride')) {
148+
pather = '{bucket}/' + http.pathOverride
149149
}
150150

151151
const integration = {

lib/package/s3/compileMethodsToS3.test.js

Lines changed: 119 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ describe('#compileMethodsToS3()', () => {
697697
key: {
698698
pathParam: 'item'
699699
},
700-
pathoverride: '{folder}/{item}.xml',
700+
pathOverride: '{folder}/{item}.xml',
701701
auth: { authorizationType: 'NONE' },
702702
requestParameters: {
703703
'integration.request.path.folder': 'method.request.path.folder',
@@ -805,4 +805,122 @@ describe('#compileMethodsToS3()', () => {
805805
}
806806
})
807807
})
808+
809+
it('should create corresponding resources when s3 GetObject proxy is given with a greedy path override', () => {
810+
serverlessApigatewayServiceProxy.validated = {
811+
events: [
812+
{
813+
serviceName: 's3',
814+
http: {
815+
path: '/{myPath+}',
816+
method: 'get',
817+
bucket: {
818+
Ref: 'MyBucket'
819+
},
820+
action: 'GetObject',
821+
key: {
822+
pathParam: 'myPath'
823+
},
824+
pathOverride: '{myPath}.xml',
825+
auth: { authorizationType: 'NONE' },
826+
requestParameters: {
827+
'integration.request.path.myPath': 'method.request.path.myPath'
828+
}
829+
}
830+
}
831+
]
832+
}
833+
serverlessApigatewayServiceProxy.apiGatewayRestApiLogicalId = 'ApiGatewayRestApi'
834+
serverlessApigatewayServiceProxy.apiGatewayResources = {
835+
'/{myPath+}': {
836+
name: 'greedyPath',
837+
resourceLogicalId: 'ApiGatewayPathOverrideS3'
838+
}
839+
}
840+
841+
serverlessApigatewayServiceProxy.compileMethodsToS3()
842+
expect(serverless.service.provider.compiledCloudFormationTemplate.Resources).to.deep.equal({
843+
ApiGatewayMethodgreedyPathGet: {
844+
Type: 'AWS::ApiGateway::Method',
845+
Properties: {
846+
HttpMethod: 'GET',
847+
RequestParameters: {
848+
'method.request.path.myPath': true
849+
},
850+
AuthorizationType: 'NONE',
851+
AuthorizationScopes: undefined,
852+
AuthorizerId: undefined,
853+
ApiKeyRequired: false,
854+
ResourceId: { Ref: 'ApiGatewayPathOverrideS3' },
855+
RestApiId: { Ref: 'ApiGatewayRestApi' },
856+
Integration: {
857+
Type: 'AWS',
858+
IntegrationHttpMethod: 'GET',
859+
Credentials: { 'Fn::GetAtt': ['ApigatewayToS3Role', 'Arn'] },
860+
Uri: {
861+
'Fn::Sub': ['arn:aws:apigateway:${AWS::Region}:s3:path/{bucket}/{myPath}.xml', {}]
862+
},
863+
PassthroughBehavior: 'WHEN_NO_MATCH',
864+
RequestParameters: {
865+
'integration.request.path.bucket': {
866+
'Fn::Sub': [
867+
"'${bucket}'",
868+
{
869+
bucket: {
870+
Ref: 'MyBucket'
871+
}
872+
}
873+
]
874+
},
875+
'integration.request.path.object': 'method.request.path.myPath',
876+
'integration.request.path.myPath': 'method.request.path.myPath'
877+
},
878+
IntegrationResponses: [
879+
{
880+
StatusCode: 400,
881+
SelectionPattern: '4\\d{2}',
882+
ResponseParameters: {},
883+
ResponseTemplates: {}
884+
},
885+
{
886+
StatusCode: 500,
887+
SelectionPattern: '5\\d{2}',
888+
ResponseParameters: {},
889+
ResponseTemplates: {}
890+
},
891+
{
892+
StatusCode: 200,
893+
SelectionPattern: '2\\d{2}',
894+
ResponseParameters: {
895+
'method.response.header.Content-Type': 'integration.response.header.Content-Type',
896+
'method.response.header.content-type': 'integration.response.header.content-type'
897+
},
898+
ResponseTemplates: {}
899+
}
900+
]
901+
},
902+
MethodResponses: [
903+
{
904+
ResponseParameters: {
905+
'method.response.header.Content-Type': true,
906+
'method.response.header.content-type': true
907+
},
908+
ResponseModels: {},
909+
StatusCode: 200
910+
},
911+
{
912+
ResponseParameters: {},
913+
ResponseModels: {},
914+
StatusCode: 400
915+
},
916+
{
917+
ResponseParameters: {},
918+
ResponseModels: {},
919+
StatusCode: 500
920+
}
921+
]
922+
}
923+
}
924+
})
925+
})
808926
})

0 commit comments

Comments
 (0)