Skip to content

Commit 78b9185

Browse files
authored
Merge pull request #6 from serverless-tencent/remove_appid
remove appid
2 parents cfd2e98 + 13e3893 commit 78b9185

File tree

7 files changed

+264
-7
lines changed

7 files changed

+264
-7
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ functions:
107107
httpMethod: ANY
108108
```
109109

110+
* [Click here you could get `Serverless.yml Reference`](./docs/en/yaml.md)
111+
110112
### Deploy the Service
111113

112114
Use this command to deploy your service for the first time and after you make changes to your Functions, Events or Resources in `serverless.yml` and want to deploy all changes within your Service at the same time.

docs/en/credentials.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ You need to create credentials Serverless can use to create resources in your Pr
2424
4. Create a file named `credentials` containing the credentials that you have collected.
2525
```ini
2626
[default]
27-
tencent_appid = 1251000000
2827
tencent_secret_id = AKIDteBxxxxxxxxxxnZfk
2928
tencent_secret_key = AKID2qsxxxxxxxxxxxxxtTo
3029
```

docs/en/yaml.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Serverless.yml Reference
2+
Here is a list of all available properties in serverless.yml when the provider is set to tencent.
3+
```yaml
4+
# Welcome to Serverless!
5+
#
6+
# This file is the main config file for your service.
7+
# It's very minimal at this point and uses default values.
8+
# You can always add more config options for more control.
9+
# We've included some commented out config examples here.
10+
# Just uncomment any of them to get that config option.
11+
#
12+
# For full config options, check the docs:
13+
# docs.serverless.com
14+
#
15+
# Happy Coding!
16+
17+
service: my-service # service name
18+
19+
provider: # provider information
20+
name: tencent
21+
runtime: Nodejs8.9 # Nodejs8.9 or Nodejs6.10
22+
credentials: ~/credentials
23+
24+
# you can overwrite defaults here
25+
# stage: dev
26+
# cosBucket: DEFAULT
27+
# role: QCS_SCFExcuteRole
28+
# memorySize: 256
29+
# timeout: 10
30+
# region: ap-shanghai
31+
# environment:
32+
# variables:
33+
# ENV_FIRST: env1
34+
# ENV_SECOND: env2
35+
# vpcConfig:
36+
# vpcId: test
37+
# subnetId: test
38+
39+
plugins:
40+
- serverless-tencent-scf
41+
42+
# you can add packaging information here
43+
#package:
44+
# include:
45+
# - include-me.js
46+
# - include-me-dir/**
47+
# exclude:
48+
# - exclude-me.js
49+
# - exclude-me-dir/**
50+
51+
functions:
52+
function_one:
53+
handler: index.main_handler
54+
# description: Tencent Serverless Cloud Function
55+
# runtime: Nodejs8.9 # Nodejs8.9 or Nodejs6.10
56+
# memorySize: 256
57+
# timeout: 10
58+
# environment:
59+
# variables:
60+
# ENV_FIRST: env1
61+
# ENV_Third: env2
62+
# vpcConfig:
63+
# vpcId: test
64+
# subnetId: test
65+
# events:
66+
# - timer:
67+
# name: timer
68+
# parameters:
69+
# cronExpression: '*/5 * * * *'
70+
# enable: true
71+
# - cos:
72+
# name: cli-appid.cos.ap-beijing.myqcloud.com
73+
# parameters:
74+
# bucket: cli-appid.cos.ap-beijing.myqcloud.com
75+
# filter:
76+
# prefix: filterdir/
77+
# suffix: .jpg
78+
# events: cos:ObjectCreated:*
79+
# enable: true
80+
# - apigw:
81+
# name: hello_world_apigw
82+
# parameters:
83+
# stageName: release
84+
# serviceId:
85+
# httpMethod: ANY
86+
# - cmq:
87+
# name: cmq_trigger
88+
# parameters:
89+
# name: test-topic-queue
90+
# enable: true
91+
# - ckafka:
92+
# name: ckafka_trigger
93+
# parameters:
94+
# name: ckafka-2o10hua5
95+
# topic: test
96+
# maxMsgNum: 999
97+
# offset: latest
98+
# enable: true
99+
100+
```

docs/zh/yaml.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Serverless.yml 参考
2+
以下是当提供商设置为tencent时,serverless.yml中所有可用属性的列表。
3+
```yaml
4+
# Welcome to Serverless!
5+
#
6+
# This file is the main config file for your service.
7+
# It's very minimal at this point and uses default values.
8+
# You can always add more config options for more control.
9+
# We've included some commented out config examples here.
10+
# Just uncomment any of them to get that config option.
11+
#
12+
# For full config options, check the docs:
13+
# docs.serverless.com
14+
#
15+
# Happy Coding!
16+
17+
service: my-service # service name
18+
19+
provider: # provider information
20+
name: tencent
21+
runtime: Nodejs8.9 # Nodejs8.9 or Nodejs6.10
22+
credentials: ~/credentials
23+
24+
# you can overwrite defaults here
25+
# stage: dev
26+
# cosBucket: DEFAULT
27+
# role: QCS_SCFExcuteRole
28+
# memorySize: 256
29+
# timeout: 10
30+
# region: ap-shanghai
31+
# environment:
32+
# variables:
33+
# ENV_FIRST: env1
34+
# ENV_SECOND: env2
35+
# vpcConfig:
36+
# vpcId: test
37+
# subnetId: test
38+
39+
plugins:
40+
- serverless-tencent-scf
41+
42+
# you can add packaging information here
43+
#package:
44+
# include:
45+
# - include-me.js
46+
# - include-me-dir/**
47+
# exclude:
48+
# - exclude-me.js
49+
# - exclude-me-dir/**
50+
51+
functions:
52+
function_one:
53+
handler: index.main_handler
54+
# description: Tencent Serverless Cloud Function
55+
# runtime: Nodejs8.9 # Nodejs8.9 or Nodejs6.10
56+
# memorySize: 256
57+
# timeout: 10
58+
# environment:
59+
# variables:
60+
# ENV_FIRST: env1
61+
# ENV_Third: env2
62+
# vpcConfig:
63+
# vpcId: test
64+
# subnetId: test
65+
# events:
66+
# - timer:
67+
# name: timer
68+
# parameters:
69+
# cronExpression: '*/5 * * * *'
70+
# enable: true
71+
# - cos:
72+
# name: cli-appid.cos.ap-beijing.myqcloud.com
73+
# parameters:
74+
# bucket: cli-appid.cos.ap-beijing.myqcloud.com
75+
# filter:
76+
# prefix: filterdir/
77+
# suffix: .jpg
78+
# events: cos:ObjectCreated:*
79+
# enable: true
80+
# - apigw:
81+
# name: hello_world_apigw
82+
# parameters:
83+
# stageName: release
84+
# serviceId:
85+
# httpMethod: ANY
86+
# - cmq:
87+
# name: cmq_trigger
88+
# parameters:
89+
# name: test-topic-queue
90+
# enable: true
91+
# - ckafka:
92+
# name: ckafka_trigger
93+
# parameters:
94+
# name: ckafka-2o10hua5
95+
# topic: test
96+
# maxMsgNum: 999
97+
# offset: latest
98+
# enable: true
99+
100+
```

docs/zh/配置账号.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
```ini
1919
[default]
20-
tencent_appid = appid
2120
tencent_secret_id = secretid
2221
tencent_secret_key = secretkey
2322
```
@@ -37,4 +36,4 @@ provider:
3736
credentials: ~/credentials
3837
```
3938

40-
新建示例模板的教程[参考此处]()
39+
新建示例模板的教程[参考此处]()

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-tencent-scf",
3-
"version": "0.2.0",
3+
"version": "0.1.13",
44
"description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.",
55
"main": "index.js",
66
"author": "serverless.com",

provider/tencentProvider.js

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,67 @@ const fs = require('fs');
55
const os = require('os');
66
const ini = require('ini');
77
const _ = require('lodash');
8-
8+
const util = require('util')
9+
const tencentcloud = require('tencentcloud-sdk-nodejs')
10+
const ClientProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/client_profile.js')
11+
const HttpProfile = require('tencentcloud-sdk-nodejs/tencentcloud/common/profile/http_profile.js')
12+
const AbstractModel = require('tencentcloud-sdk-nodejs/tencentcloud/common/abstract_model')
13+
const AbstractClient = require('tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client')
914
const constants = {
1015
providerName: 'tencent',
1116
};
1217

18+
class GetUserAppIdResponse extends AbstractModel {
19+
constructor() {
20+
super()
21+
22+
this.RequestId = null
23+
}
24+
25+
deserialize(params) {
26+
if (!params) {
27+
return
28+
}
29+
this.AppId = 'RequestId' in params ? params.AppId : null
30+
this.RequestId = 'RequestId' in params ? params.RequestId : null
31+
}
32+
}
33+
34+
class AppidClient extends AbstractClient {
35+
constructor(credential, region, profile) {
36+
super('cam.tencentcloudapi.com', '2019-01-16', credential, region, profile)
37+
}
38+
39+
GetUserAppId(req, cb) {
40+
const resp = new GetUserAppIdResponse()
41+
this.request('GetUserAppId', req, resp, cb)
42+
}
43+
}
44+
1345
class TencentProvider {
1446
static getProviderName() {
1547
return constants.providerName;
1648
}
1749

50+
getAppid(credentials) {
51+
const secret_id = credentials.SecretId
52+
const secret_key = credentials.SecretKey
53+
const cred = new tencentcloud.common.Credential(secret_id, secret_key)
54+
const httpProfile = new HttpProfile()
55+
httpProfile.reqTimeout = 30
56+
const clientProfile = new ClientProfile('HmacSHA256', httpProfile)
57+
const cam = new AppidClient(cred, 'ap-guangzhou', clientProfile)
58+
const req = new GetUserAppIdResponse()
59+
const body = {}
60+
req.from_json_string(JSON.stringify(body))
61+
const handler = util.promisify(cam.GetUserAppId.bind(cam))
62+
try {
63+
return handler(req)
64+
} catch (e) {
65+
throw 'Get Appid failed! '
66+
}
67+
}
68+
1869
constructor(serverless, options) {
1970
this.options = options;
2071
this.serverless = serverless;
@@ -89,7 +140,7 @@ class TencentProvider {
89140
return (vpcId && subnetId) ? {'VpcId': vpcId, 'SubnetId': subnetId} : null
90141
}
91142

92-
getCredentials() {
143+
async getCredentials() {
93144

94145
if (this.options.credentials) {
95146
return
@@ -104,14 +155,20 @@ class TencentProvider {
104155
// TODO(dfounderliu) support profiles other than [default]
105156
this.options.credentials = ini.parse(keyFileContent).default;
106157
[
107-
'tencent_appid',
108158
'tencent_secret_id',
109159
'tencent_secret_key'
110160
].forEach((field) => {
111161
if (!this.options.credentials[field]) {
112162
throw new Error(`Credentials in ${credentials} does not contain ${field}`);
113163
}
114164
});
165+
166+
// From cam to getting appid
167+
const appid = await this.getAppid({
168+
SecretId: this.options.credentials.tencent_secret_id,
169+
SecretKey: this.options.credentials.tencent_secret_key
170+
})
171+
this.options.credentials.tencent_appid = appid.AppId
115172
return
116173
}
117174
}

0 commit comments

Comments
 (0)