Skip to content

Commit 59fe8ce

Browse files
authored
refactor: Rely on CloudFunctions v1 not v1 beta (#165)
1 parent 4d52e4c commit 59fe8ce

File tree

4 files changed

+103
-58
lines changed

4 files changed

+103
-58
lines changed

info/lib/displayServiceInfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module.exports = {
3737
};
3838

3939
_.forEach(resources.resources, resource => {
40-
if (resource.type === 'cloudfunctions.v1beta2.function') {
40+
if (resource.type === 'gcp-types/cloudfunctions-v1:projects.locations.functions') {
4141
const serviceFuncName = getFunctionNameInService(
4242
resource.name,
4343
this.serverless.service.service,
@@ -53,7 +53,7 @@ module.exports = {
5353
const region = this.options.region;
5454
const project = this.serverless.service.provider.project;
5555
const baseUrl = `https://${region}-${project}.cloudfunctions.net`;
56-
const path = serviceFunc.handler; // NOTE this might change
56+
const path = serviceFunc.name; // NOTE this might change
5757
funcResource = `${baseUrl}/${path}`;
5858
}
5959

info/lib/displayServiceInfo.test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,14 @@ describe('DisplayServiceInfo', () => {
9696
const resources = {
9797
resources: [
9898
{ type: 'resource.which.should.be.filterered', name: 'someResource' },
99-
{ type: 'cloudfunctions.v1beta2.function', name: 'my-service-dev-func1' },
100-
{ type: 'cloudfunctions.v1beta2.function', name: 'my-service-dev-func2' },
99+
{
100+
type: 'gcp-types/cloudfunctions-v1:projects.locations.functions',
101+
name: 'my-service-dev-func1',
102+
},
103+
{
104+
type: 'gcp-types/cloudfunctions-v1:projects.locations.functions',
105+
name: 'my-service-dev-func2',
106+
},
101107
],
102108
};
103109

@@ -110,7 +116,7 @@ describe('DisplayServiceInfo', () => {
110116
functions: [
111117
{
112118
name: 'func1',
113-
resource: 'https://us-central1-my-project.cloudfunctions.net/handler',
119+
resource: 'https://us-central1-my-project.cloudfunctions.net/my-service-dev-func1',
114120
},
115121
{
116122
name: 'func2',
@@ -167,7 +173,7 @@ describe('DisplayServiceInfo', () => {
167173
functions: [
168174
{
169175
name: 'func1',
170-
resource: 'https://us-central1-my-project.cloudfunctions.net/handler',
176+
resource: 'https://us-central1-my-project.cloudfunctions.net/my-service-dev-func1',
171177
},
172178
{
173179
name: 'func2',
@@ -188,7 +194,8 @@ describe('DisplayServiceInfo', () => {
188194

189195
expectedOutput += `${chalk.yellow.underline('Deployed functions')}\n`;
190196
expectedOutput += `${chalk.yellow('func1')}\n`;
191-
expectedOutput += ' https://us-central1-my-project.cloudfunctions.net/handler\n';
197+
expectedOutput +=
198+
' https://us-central1-my-project.cloudfunctions.net/my-service-dev-func1\n';
192199
expectedOutput += `${chalk.yellow('func2')}\n`;
193200
expectedOutput += ' projects/*/topics/my-test-topic\n';
194201

package/lib/compileFunctions.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
compileFunctions() {
1212
const artifactFilePath = this.serverless.service.package.artifact;
1313
const fileName = artifactFilePath.split(path.sep).pop();
14+
const projectName = _.get(this, 'serverless.service.provider.project');
1415

1516
this.serverless.service.package.artifactFilePath = `${this.serverless.service.package.artifactDirectoryName}/${fileName}`;
1617

@@ -25,6 +26,7 @@ module.exports = {
2526

2627
const funcTemplate = getFunctionTemplate(
2728
funcObject,
29+
projectName,
2830
this.serverless.service.provider.region,
2931
`gs://${this.serverless.service.provider.deploymentBucketName}/${this.serverless.service.package.artifactFilePath}`
3032
);
@@ -150,17 +152,18 @@ const validateVpcConnectorProperty = (funcObject, functionName) => {
150152
}
151153
};
152154

153-
const getFunctionTemplate = (funcObject, region, sourceArchiveUrl) => {
155+
const getFunctionTemplate = (funcObject, projectName, region, sourceArchiveUrl) => {
154156
//eslint-disable-line
155157
return {
156-
type: 'cloudfunctions.v1beta2.function',
158+
type: 'gcp-types/cloudfunctions-v1:projects.locations.functions',
157159
name: funcObject.name,
158160
properties: {
159-
location: region,
161+
parent: `projects/${projectName}/locations/${region}`,
160162
availableMemoryMb: 256,
161163
runtime: 'nodejs8',
162164
timeout: '60s',
163-
function: funcObject.handler,
165+
entryPoint: funcObject.handler,
166+
function: funcObject.name,
164167
sourceArchiveUrl,
165168
},
166169
};

0 commit comments

Comments
 (0)