Skip to content

Commit 1e20f30

Browse files
authored
Merge pull request #71 from aliyun/tanhehe/improve_some_user_experience
fix generated role contains invalid char bug fix error message for invalid role add php7.2 support fix generating role bug with `_` fix apigateway "RepeatedPathError: The specified path conflict with the API" bug
2 parents 00991f7 + 08faf7b commit 1e20f30

5 files changed

Lines changed: 30 additions & 11 deletions

File tree

lib/deploy/deploy-by-tpl.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ function extractFcRole(role) {
3131
return roleName;
3232
}
3333

34+
function nomalizeRoleOrPoliceName(roleName) {
35+
return roleName.replace(/_/g, '-');
36+
}
3437

3538
async function deployFunction(serviceName, functionName, functionDefinition) {
3639
const properties = functionDefinition.Properties || {};
@@ -99,7 +102,7 @@ async function deployPolicy(serviceName, roleName, policy, curCount) {
99102

100103
const profile = await getProfile();
101104

102-
const policyName = `AliyunFcGeneratedServicePolicy-${profile.defaultRegion}-${serviceName}${curCount}`;
105+
const policyName = nomalizeRoleOrPoliceName(`AliyunFcGeneratedServicePolicy-${profile.defaultRegion}-${serviceName}${curCount}`);
103106

104107
await makeAndAttachPolicy(policyName, policy, roleName);
105108

@@ -133,10 +136,15 @@ async function deployFcService(serviceName, serviceDefinition) {
133136
const profile = await getProfile();
134137

135138
if ( roleArn ) {
136-
roleName = extractFcRole(roleArn);
139+
try {
140+
roleName = extractFcRole(roleArn);
141+
} catch(ex) {
142+
throw new Error('The role you provided is not correct. You must provide the correct role arn.');
143+
}
137144
createRoleIfNotExist = false;
138145
} else {
139146
roleName = `aliyunfcgeneratedrole-${profile.defaultRegion}-${serviceName}`;
147+
roleName = nomalizeRoleOrPoliceName(roleName);
140148
createRoleIfNotExist = true;
141149
}
142150

@@ -152,7 +160,7 @@ async function deployFcService(serviceName, serviceDefinition) {
152160

153161
if (logConfig.Logstore && logConfig.Project) {
154162
if (!roleArn) {
155-
const logPolicyName = `AliyunFcGeneratedLogPolicy-${profile.defaultRegion}-${serviceName}`;
163+
const logPolicyName = nomalizeRoleOrPoliceName(`AliyunFcGeneratedLogPolicy-${profile.defaultRegion}-${serviceName}`);
156164
await makeAndAttachPolicy(logPolicyName, {
157165
'Version': '1',
158166
'Statement': [

lib/deploy/deploy-support.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ async function makeService({serviceName,
235235
try {
236236
service = await fc.getService(serviceName);
237237
} catch (ex) {
238-
if (ex.code !== 'ServiceNotFound') {
238+
if (ex.code === 'AccessDenied') {
239+
throw ex;
240+
} else if (ex.code !== 'ServiceNotFound') {
239241
console.log(red(`\tretry ${times} times`));
240242
retry(ex);
241243
}
@@ -596,8 +598,13 @@ async function makeApi(group, {
596598
ApiName: apiName,
597599
GroupId: group.GroupId
598600
});
599-
600-
var api = result.ApiSummarys && result.ApiSummarys.ApiSummary[0];
601+
602+
var apiSummarys = result.ApiSummarys && result.ApiSummarys.ApiSummary;
603+
var api;
604+
605+
if (apiSummarys) {
606+
api = apiSummarys.find(summary => summary.ApiName === apiName);
607+
}
601608

602609
const requestParameters = parameters.map((item) => {
603610
return Object.assign(getDefaultRequestParameter(), item);

lib/ram.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,12 @@ async function makeRole(roleName, createRoleIfNotExist, description='FunctionCom
161161
process.exit(-1);
162162
}
163163
} catch (ex) {
164-
console.log(red(`retry ${times} times`));
165-
retry(ex);
164+
if (ex.code && ex.code.startsWith('InvalidParameter')) {
165+
throw ex;
166+
} else {
167+
console.log(red(`retry ${times} times`));
168+
retry(ex);
169+
}
166170
}
167171
}, retryOptions);
168172

lib/validate/schema/function.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const functionSchema = {
1717
},
1818
'Runtime': {
1919
'type': 'string',
20-
'enum': ['nodejs6', 'nodejs8', 'python2.7', 'python3', 'java8'],
20+
'enum': ['nodejs6', 'nodejs8', 'python2.7', 'python3', 'java8', 'php7.2'],
2121
},
2222
'CodeUri': {
2323
'type': 'string'
@@ -56,4 +56,4 @@ const functionSchema = {
5656
},
5757
'required': ['Type'],
5858
};
59-
module.exports = functionSchema;
59+
module.exports = functionSchema;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alicloud/fun",
3-
"version": "2.2.1",
3+
"version": "2.3.0",
44
"description": "(have)Fun with Serverless",
55
"engines": {
66
"node": ">=8.0.0"

0 commit comments

Comments
 (0)