Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.

Commit dcadf0b

Browse files
authored
Merge pull request #50 from eamonnfaherty/master
adding host override and vpcconfig
2 parents 784ee36 + 9750599 commit dcadf0b

File tree

2 files changed

+69
-6
lines changed

2 files changed

+69
-6
lines changed

functions/source/ZipDl/lambda_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def lambda_handler(event, context):
140140
name = event['body-json']['repository']['name']
141141
archive_url = "{scheme}://{netloc}/rest/api/latest/projects/{project}/repos/{repo}/archive?at={hash}&format=zip".format(
142142
scheme=url_parts.scheme,
143-
netloc=url_parts.netloc,
143+
netloc=url_parts.netloc if os.environ.get("SCM_HOSTNAME_OVERRIDE", '') == '' else os.environ.get("SCM_HOSTNAME_OVERRIDE"),
144144
project=owner,
145145
repo=name,
146146
hash=change['toHash'],

templates/git2s3.template

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@
9898
"ConstraintDescription": "this token must be generated from the git server/provider"
9999
},
100100
"OauthKey": {
101-
"Description": "zipdl method only. OAuth2 Key needed for BitBucket",
101+
"Description": "zipdl method only. OAuth2 Key needed for BitBucket. For bitbucket server this should be a username.",
102102
"Type": "String",
103103
"Default": "",
104104
"ConstraintDescription": "this key must be generated from the git server/provider"
105105
},
106106
"OauthSecret": {
107107
"NoEcho": "true",
108-
"Description": "zipdl method only. OAuth2 Secret needed for BitBucket",
108+
"Description": "zipdl method only. OAuth2 Secret needed for BitBucket. For bitbucket server this should be a password.",
109109
"Type": "String",
110110
"Default": "",
111111
"ConstraintDescription": "this secret must be generated from the git server/provider"
@@ -128,6 +128,26 @@
128128
"Default": "quickstart-git2s3/",
129129
"Description": "S3 key prefix for the Quick Start assets. Quick Start key prefix can include numbers, lowercase letters, uppercase letters, hyphens (-), and forward slash (/).",
130130
"Type": "String"
131+
},
132+
"VPCId": {
133+
"Description": "Id of the VPC the DL Zip lambda should run in",
134+
"Type": "AWS::EC2::VPC::Id",
135+
"Default": ""
136+
},
137+
"VPCCidrRange": {
138+
"Description": "CIDR range of the VPC",
139+
"Type": "String",
140+
"Default": ""
141+
},
142+
"SubnetIds": {
143+
"Description": "SubnetIds the DL Zip lambda should run in",
144+
"Type": "List<AWS::EC2::Subnet::Id>",
145+
"Default": ""
146+
},
147+
"ScmHostnameOverride": {
148+
"Description": "Hostname to override the incoming json request with",
149+
"Type": "String",
150+
"Default": ""
131151
}
132152
},
133153
"Conditions": {
@@ -214,6 +234,11 @@
214234
]
215235
}
216236
]
237+
},
238+
"ShouldRunInVPC":{
239+
"Fn::Not": [{
240+
"Fn::Equals": [{"Ref": "VPCId"}, ""]
241+
}]
217242
}
218243
},
219244
"Resources": {
@@ -906,7 +931,7 @@
906931
"Runtime": "python2.7",
907932
"Timeout": "300",
908933
"Environment": {
909-
"Variables":
934+
"Variables":
910935
{ "ExcludeGit":"True" }
911936
},
912937
"Code": {
@@ -922,6 +947,7 @@
922947
"ZipDlRole": {
923948
"Type": "AWS::IAM::Role",
924949
"Properties": {
950+
"ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaENIManagementAccess" ],
925951
"AssumeRolePolicyDocument": {
926952
"Statement": [
927953
{
@@ -991,8 +1017,28 @@
9911017
]
9921018
}
9931019
},
1020+
"ZipDlLambdaSecurityGroup": {
1021+
"Type": "AWS::EC2::SecurityGroup",
1022+
"Properties": {
1023+
"GroupDescription": "Security Group to allow the lambda to access the git service",
1024+
"GroupName": "ZipDlLambdaSecurityGroup",
1025+
"SecurityGroupEgress": [ {
1026+
"CidrIp": {"Ref": "VPCCidrRange"},
1027+
"FromPort": -1,
1028+
"IpProtocol": 'tcp',
1029+
"ToPort": -1
1030+
} ],
1031+
"SecurityGroupIngress": [ {
1032+
"CidrIp": {"Ref": "VPCCidrRange"},
1033+
"FromPort": -1,
1034+
"IpProtocol": 'tcp',
1035+
"ToPort": -1
1036+
} ],
1037+
"VpcId": {"Ref": "VPCId"}
1038+
}
1039+
},
9941040
"ZipDlLambda": {
995-
"DependsOn": "CopyZips",
1041+
"DependsOn": "CopyZips",
9961042
"Type": "AWS::Lambda::Function",
9971043
"Properties": {
9981044
"Handler": "lambda_function.lambda_handler",
@@ -1012,7 +1058,24 @@
10121058
},
10131059
"Runtime": "python2.7",
10141060
"MemorySize": 128,
1015-
"Timeout": 30
1061+
"Timeout": 30,
1062+
"VpcConfig": {
1063+
"Fn::If": [
1064+
"ShouldRunInVPC",
1065+
{
1066+
"SecurityGroupIds": [
1067+
{ "Ref" : "ZipDlLambdaSecurityGroup"}
1068+
],
1069+
"SubnetIds": { "Ref" : "SubnetIds"},
1070+
},
1071+
{
1072+
"Ref": "AWS::NoValue"
1073+
}
1074+
]
1075+
},
1076+
"Environment": {
1077+
"Variables": { "SCM_HOSTNAME_OVERRIDE": {"Ref": "ScmHostnameOverride" }}
1078+
}
10161079
}
10171080
},
10181081
"WebHookRole": {

0 commit comments

Comments
 (0)