Skip to content

Commit

Permalink
feat: Support serviceAccount option for deployment (#215)
Browse files Browse the repository at this point in the history
Co-authored-by: Xin Yi <[email protected]>
Co-authored-by: Xin Yi <[email protected]>
Co-authored-by: Luis Eduardo Chacón <[email protected]>
  • Loading branch information
4 people authored May 11, 2020
1 parent 86d40aa commit 1164495
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions package/lib/compileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ module.exports = {
`gs://${this.serverless.service.provider.deploymentBucketName}/${this.serverless.service.package.artifactFilePath}`
);

funcTemplate.properties.serviceAccountEmail =
_.get(funcObject, 'serviceAccountEmail') ||
_.get(this, 'serverless.service.provider.serviceAccountEmail') ||
null;
funcTemplate.properties.availableMemoryMb =
_.get(funcObject, 'memorySize') ||
_.get(this, 'serverless.service.provider.memorySize') ||
Expand All @@ -48,6 +52,10 @@ module.exports = {
funcObject.environment // eslint-disable-line comma-dangle
);

if (!funcTemplate.properties.serviceAccountEmail) {
delete funcTemplate.properties.serviceAccountEmail;
}

if (funcObject.vpc) {
_.assign(funcTemplate.properties, {
vpcConnector: _.get(funcObject, 'vpc') || _.get(this, 'serverless.service.provider.vpc'),
Expand Down
21 changes: 21 additions & 0 deletions provider/googleProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,27 @@ class GoogleProvider {
logging: google.logging('v2'),
cloudfunctions: google.cloudfunctions('v1'),
};

this.variableResolvers = {
gs: this.getGsValue,
};
}

getGsValue(variableString) {
const groups = variableString.split(':')[1].split('/');
const bucket = groups.shift();
const object = groups.join('/');

return this.serverless
.getProvider('google')
.request('storage', 'objects', 'get', {
bucket,
object,
alt: 'media',
})
.catch(err => {
throw new Error(`Error getting value for ${variableString}. ${err.message}`);
});
}

request() {
Expand Down

0 comments on commit 1164495

Please sign in to comment.