-
Notifications
You must be signed in to change notification settings - Fork 126
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
Adding support for egress and ingress settings #243
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,6 +62,18 @@ module.exports = { | |
}); | ||
} | ||
|
||
if (funcObject.egress) { | ||
_.assign(funcTemplate.properties, { | ||
vpcConnectorEgressSettings: _.get(funcObject, 'egress') || _.get(this, 'serverless.service.provider.egress'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}); | ||
} | ||
|
||
if (funcObject.ingress) { | ||
_.assign(funcTemplate.properties, { | ||
ingressSettings: _.get(funcObject, 'ingress') || _.get(this, 'serverless.service.provider.ingress'), | ||
Comment on lines
+71
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
}); | ||
} | ||
|
||
if (funcObject.maxInstances) { | ||
funcTemplate.properties.maxInstances = funcObject.maxInstances; | ||
} | ||
|
@@ -157,6 +169,46 @@ const validateVpcConnectorProperty = (funcObject, functionName) => { | |
} | ||
}; | ||
|
||
/** | ||
* Validate the function egress settings per | ||
* https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions#vpcconnectoregresssettings | ||
* @param {*} funcObject | ||
* @param {*} functionName | ||
*/ | ||
const validateVpcEgressProperty = (funcObject, functionName) => { | ||
if (funcObject.egress && typeof funcObject.egress === 'string') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's do just |
||
const validTypes = ['VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED', 'PRIVATE_RANGES_ONLY', 'ALL_TRAFFIC']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's define it as |
||
if (!validTypes.includes(funcObject.egress)) { | ||
const errorMessage = [ | ||
`The function "${functionName}" has an invalid egress setting`, | ||
' Egress setting should be ALL_TRAFFIC, PRIVATE_RANGES_ONLY or VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED', | ||
' Please check the docs for more info.', | ||
].join(''); | ||
throw new Error(errorMessage); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* Validate the function ingress settings per | ||
* https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions#ingresssettings | ||
* @param {*} funcObject | ||
* @param {*} functionName | ||
*/ | ||
const validateVpcIngressProperty = (funcObject, functionName) => { | ||
if (funcObject.ingress && typeof funcObject.ingress === 'string') { | ||
const validTypes = ['INGRESS_SETTINGS_UNSPECIFIED', 'ALLOW_ALL', 'ALLOW_INTERNAL_ONLY', 'ALLOW_INTERNAL_AND_GCLB']; | ||
Comment on lines
+199
to
+200
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
if (!validTypes.includes(funcObject.ingress)) { | ||
const errorMessage = [ | ||
`The function "${functionName}" has an invalid ingress setting`, | ||
' Ingress setting should be ALLOW_ALL, ALLOW_INTERNAL_ONLY, ALLOW_INTERNAL_AND_GCLB or INGRESS_SETTINGS_UNSPECIFIED', | ||
' Please check the docs for more info.', | ||
].join(''); | ||
throw new Error(errorMessage); | ||
} | ||
} | ||
}; | ||
|
||
const getFunctionTemplate = (funcObject, projectName, region, sourceArchiveUrl) => { | ||
//eslint-disable-line | ||
return { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use
Object.assign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just following existing established formatting.
I will come back to these change requests in a few weeks, we will just have to work with our fork for now.