Skip to content

Commit

Permalink
Adding support for egress and ingress settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Troy Kelly authored Nov 20, 2020
1 parent be817a2 commit 7c3df59
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions package/lib/compileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ module.exports = {
});
}

if (funcObject.egress) {
_.assign(funcTemplate.properties, {
vpcConnectorEgressSettings: _.get(funcObject, 'egress') || _.get(this, 'serverless.service.provider.egress'),
});
}

if (funcObject.ingress) {
_.assign(funcTemplate.properties, {
ingressSettings: _.get(funcObject, 'ingress') || _.get(this, 'serverless.service.provider.ingress'),
});
}

if (funcObject.maxInstances) {
funcTemplate.properties.maxInstances = funcObject.maxInstances;
}
Expand Down Expand Up @@ -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') {
const validTypes = ['VPC_CONNECTOR_EGRESS_SETTINGS_UNSPECIFIED', 'PRIVATE_RANGES_ONLY', 'ALL_TRAFFIC'];
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'];
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 {
Expand Down

0 comments on commit 7c3df59

Please sign in to comment.