Skip to content

Commit

Permalink
more changes based on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tinaliang committed Mar 13, 2018
1 parent 170dc23 commit 4eec2ff
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 25 deletions.
17 changes: 8 additions & 9 deletions lib/gcp/cloudfunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ function _createFunction(options) {
var func = location + '/functions/' + options.functionName;
var endpoint = '/' + API_VERSION + '/' + location + '/functions';
var data = {
sourceArchiveUrl: options.sourceArchiveUrl,
sourceUploadUrl: options.sourceUploadUrl,
name: func,
entryPoint: options.entryPoint,
Expand Down Expand Up @@ -75,6 +74,14 @@ function _updateFunction(options) {
labels: options.labels
}, options.trigger);

if (options.sourceArchiveUrl) {
masks = _.concat(masks, ['sourceArchiveUrl']);
} else if (options.sourceUploadUrl) {
masks = _.concat(masks, ['sourceUploadUrl']);
} else {
return RSVP.reject('We were unable to retrieve the functions source code. Please make sure you have the correct permissions and try again.');
}

var masks = ['name', 'labels'];
if (options.trigger.eventTrigger) {
masks = _.concat(masks, _.map(_.keys(options.trigger.eventTrigger), function(subkey) {
Expand All @@ -84,14 +91,6 @@ function _updateFunction(options) {
masks = _.concat(masks, 'httpsTrigger');
}

if (options.sourceArchiveUrl) {
masks = _.concat(masks, ['sourceArchiveUrl']);
} else if (options.sourceUploadUrl) {
masks = _.concat(masks, ['sourceUploadUrl']);
} else {
return RSVP.reject('Url for functions source code is undefined. Please make sure you have the correct permissions and try again.');
}

return api.request('PATCH', endpoint, {
qs: {
updateMask: masks.join(',')
Expand Down
16 changes: 0 additions & 16 deletions lib/gcp/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,6 @@ function _getBucket(bucket) {
});
}

function _getUploadUrl(projectId, location) {
var parent = 'projects/' + projectId + '/locations/' + location;
return api.request('POST', '/v1/' + parent + '/functions:generateUploadUrl', {
auth: true,
json: false,
origin: api.functionsOrigin
}).then(function(result) {
var responseBody = JSON.parse(result.body);
return RSVP.resolve(responseBody.uploadUrl);
}, function(err) {
logger.info('\n\nThere was an issue deploying your functions. Verify that your project has a Google App Engine instance setup at https://console.cloud.google.com/appengine and try again. If this issue persists, please contact support.');
return RSVP.reject(err);
});
}

function _uploadSource(source, uploadUrl) {
return api.request('PUT', uploadUrl, {
data: source.stream,
Expand All @@ -63,6 +48,5 @@ module.exports = {
get: _getBucket,
getDefault: _getDefaultBucket
},
getUploadUrl: _getUploadUrl,
upload: _uploadSource
};

0 comments on commit 4eec2ff

Please sign in to comment.