Skip to content

Commit da0ef2d

Browse files
author
dfounderliu
committed
fix auth
1 parent 5520993 commit da0ef2d

File tree

12 files changed

+38
-153
lines changed

12 files changed

+38
-153
lines changed

deploy/tencentDeploy.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,7 @@ class TencentDeploy {
2727

2828
async deploy() {
2929
const provider = new tencentProvider(this.serverless, this.options)
30-
if (
31-
!this.options.credentials ||
32-
!this.options.credentials.tencent_secret_id ||
33-
!this.options.credentials.tencent_owneruin
34-
) {
35-
const tencentTemp = await provider.getTempKey()
36-
this.options.credentials = {
37-
tencent_secret_id: tencentTemp.tencent_secret_id,
38-
tencent_secret_key: tencentTemp.tencent_secret_key,
39-
tencent_appid: tencentTemp.tencent_appid,
40-
tencent_owneruin: tencentTemp.tencent_owneruin
41-
}
42-
this.options.token = tencentTemp.token
43-
this.options.timestamp = tencentTemp.timestamp
44-
}
30+
this.options = await provider.getUserCred(this.options)
4531
await provider.getUserAuth(this.options.credentials.tencent_owneruin)
4632

4733
const services = this.provider.getServiceResource()

deploy/tencentDeployFunction.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,7 @@ class TencentDeployFunction {
3232

3333
async deploy() {
3434
const provider = new tencentProvider(this.serverless, this.options)
35-
if (
36-
!this.options.credentials ||
37-
!this.options.credentials.tencent_secret_id ||
38-
!this.options.credentials.tencent_owneruin
39-
) {
40-
const tencentTemp = await provider.getTempKey()
41-
this.options.credentials = {
42-
tencent_secret_id: tencentTemp.tencent_secret_id,
43-
tencent_secret_key: tencentTemp.tencent_secret_key,
44-
tencent_appid: tencentTemp.tencent_appid,
45-
tencent_owneruin: tencentTemp.tencent_owneruin
46-
}
47-
this.options.token = tencentTemp.token
48-
this.options.timestamp = tencentTemp.timestamp
49-
}
35+
this.options = await provider.getUserCred(this.options)
5036
await provider.getUserAuth(this.options.credentials.tencent_owneruin)
5137

5238
const services = this.provider.getServiceResource()

deploy/tencentDeployList.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,9 @@ class TencentDeployList {
2424

2525
async serviceList() {
2626
const provider = new tencentProvider(this.serverless, this.options)
27-
if (
28-
!this.options.credentials ||
29-
!this.options.credentials.tencent_secret_id ||
30-
!this.options.credentials.tencent_owneruin
31-
) {
32-
const tencentTemp = await provider.getTempKey()
33-
this.options.credentials = {
34-
tencent_secret_id: tencentTemp.tencent_secret_id,
35-
tencent_secret_key: tencentTemp.tencent_secret_key,
36-
tencent_appid: tencentTemp.tencent_appid,
37-
tencent_owneruin: tencentTemp.tencent_owneruin
38-
}
39-
this.options.token = tencentTemp.token
40-
this.options.timestamp = tencentTemp.timestamp
41-
}
27+
this.options = await provider.getUserCred(this.options)
4228
await provider.getUserAuth(this.options.credentials.tencent_owneruin)
29+
4330
const Handler = new RollbackService(this.options, this.serverless)
4431
const fileKeyPrefix = this.serverless.service.service + '-' + this.options.stage
4532
const cosBucket = this.provider.getDeployCosBucket()

deploy/tencentDeployListFunctions.js

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,9 @@ class TencentDeployListFunction {
2626

2727
async functionList() {
2828
const provider = new tencentProvider(this.serverless, this.options)
29-
if (
30-
!this.options.credentials ||
31-
!this.options.credentials.tencent_secret_id ||
32-
!this.options.credentials.tencent_owneruin
33-
) {
34-
const tencentTemp = await provider.getTempKey()
35-
this.options.credentials = {
36-
tencent_secret_id: tencentTemp.tencent_secret_id,
37-
tencent_secret_key: tencentTemp.tencent_secret_key,
38-
tencent_appid: tencentTemp.tencent_appid,
39-
tencent_owneruin: tencentTemp.tencent_owneruin
40-
}
41-
this.options.token = tencentTemp.token
42-
this.options.timestamp = tencentTemp.timestamp
43-
}
29+
this.options = await provider.getUserCred(this.options)
4430
await provider.getUserAuth(this.options.credentials.tencent_owneruin)
31+
4532
try {
4633
const infoHandler = new InfoFunction(this.options, this.serverless)
4734
const deployHandler = new ListFunctions(this.options, this.serverless)

info/tencentInfo.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,7 @@ class TencentInfo {
2525

2626
async info() {
2727
const provider = new tencentProvider(this.serverless, this.options)
28-
if (
29-
!this.options.credentials ||
30-
!this.options.credentials.tencent_secret_id ||
31-
!this.options.credentials.tencent_owneruin
32-
) {
33-
const tencentTemp = await provider.getTempKey()
34-
this.options.credentials = {
35-
tencent_secret_id: tencentTemp.tencent_secret_id,
36-
tencent_secret_key: tencentTemp.tencent_secret_key,
37-
tencent_appid: tencentTemp.tencent_appid,
38-
tencent_owneruin: tencentTemp.tencent_owneruin
39-
}
40-
this.options.token = tencentTemp.token
41-
this.options.timestamp = tencentTemp.timestamp
42-
}
28+
this.options = await provider.getUserCred(this.options)
4329
await provider.getUserAuth(this.options.credentials.tencent_owneruin)
4430
try {
4531
const region = this.options.region

invoke/tencentInvoke.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,7 @@ class TencentInvoke {
2424

2525
async invoke() {
2626
const provider = new tencentProvider(this.serverless, this.options)
27-
if (
28-
!this.options.credentials ||
29-
!this.options.credentials.tencent_secret_id ||
30-
!this.options.credentials.tencent_owneruin
31-
) {
32-
const tencentTemp = await provider.getTempKey()
33-
this.options.credentials = {
34-
tencent_secret_id: tencentTemp.tencent_secret_id,
35-
tencent_secret_key: tencentTemp.tencent_secret_key,
36-
tencent_appid: tencentTemp.tencent_appid,
37-
tencent_owneruin: tencentTemp.tencent_owneruin
38-
}
39-
this.options.token = tencentTemp.token
40-
this.options.timestamp = tencentTemp.timestamp
41-
}
27+
this.options = await provider.getUserCred(this.options)
4228
await provider.getUserAuth(this.options.credentials.tencent_owneruin)
4329
try {
4430
const options = {

logs/tencentLogs.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,7 @@ class TencentLogs {
5050

5151
async logs() {
5252
const provider = new tencentProvider(this.serverless, this.options)
53-
if (
54-
!this.options.credentials ||
55-
!this.options.credentials.tencent_secret_id ||
56-
!this.options.credentials.tencent_owneruin
57-
) {
58-
const tencentTemp = await provider.getTempKey()
59-
this.options.credentials = {
60-
tencent_secret_id: tencentTemp.tencent_secret_id,
61-
tencent_secret_key: tencentTemp.tencent_secret_key,
62-
tencent_appid: tencentTemp.tencent_appid,
63-
tencent_owneruin: tencentTemp.tencent_owneruin
64-
}
65-
this.options.token = tencentTemp.token
66-
this.options.timestamp = tencentTemp.timestamp
67-
}
53+
this.options = await provider.getUserCred(this.options)
6854
await provider.getUserAuth(this.options.credentials.tencent_owneruin)
6955
try {
7056
const timeFormat = 'yyyy-MM-dd hh:mm:ss'

metrics/tencentMetrics.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,7 @@ class TencentInfo {
5858

5959
async metrics() {
6060
const provider = new tencentProvider(this.serverless, this.options)
61-
if (
62-
!this.options.credentials ||
63-
!this.options.credentials.tencent_secret_id ||
64-
!this.options.credentials.tencent_owneruin
65-
) {
66-
const tencentTemp = await provider.getTempKey()
67-
this.options.credentials = {
68-
tencent_secret_id: tencentTemp.tencent_secret_id,
69-
tencent_secret_key: tencentTemp.tencent_secret_key,
70-
tencent_appid: tencentTemp.tencent_appid,
71-
tencent_owneruin: tencentTemp.tencent_owneruin
72-
}
73-
this.options.token = tencentTemp.token
74-
this.options.timestamp = tencentTemp.timestamp
75-
}
61+
this.options = await provider.getUserCred(this.options)
7662
await provider.getUserAuth(this.options.credentials.tencent_owneruin)
7763
try {
7864
const Handler = new MetricsFunction(this.options, this.serverless)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-tencent-scf",
3-
"version": "0.1.27",
3+
"version": "0.1.28",
44
"description": "Provider plugin for the Serverless Framework v1.x which adds support for Tencent Cloud Functions.",
55
"main": "index.js",
66
"author": "Tencent Cloud, Inc.",
@@ -44,7 +44,7 @@
4444
"tencentcloud-sdk-nodejs": "^3.0.87",
4545
"universal-analytics": "^0.4.20",
4646
"tencent-login": "^0.1.6",
47-
"serverless-tencent-auth-tool": "^1.0.0"
47+
"serverless-tencent-auth-tool": "^1.0.9"
4848
},
4949
"devDependencies": {
5050
"coveralls": "^3.0.5",

provider/tencentProvider.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,33 @@ class TencentProvider {
5656
return constants.providerName
5757
}
5858

59+
async getUserCred(options) {
60+
if (!options.credentials || !options.credentials.tencent_secret_id) {
61+
const tencentTemp = await this.getTempKey()
62+
this.options.credentials = {
63+
tencent_secret_id: tencentTemp.tencent_secret_id,
64+
tencent_secret_key: tencentTemp.tencent_secret_key,
65+
tencent_appid: tencentTemp.tencent_appid,
66+
tencent_owneruin: tencentTemp.tencent_owneruin
67+
}
68+
options.token = tencentTemp.token
69+
options.timestamp = tencentTemp.timestamp
70+
}
71+
if (!options.credentials.tencent_owneruin || !options.credentials.tencent_appid) {
72+
const appid = await this.getAppid({
73+
SecretId: options.credentials.tencent_secret_id,
74+
SecretKey: options.credentials.tencent_secret_key
75+
})
76+
options.credentials.tencent_appid = appid.AppId
77+
options.credentials.tencent_owneruin = appid.OwnerUin
78+
}
79+
return options
80+
}
81+
5982
async getUserAuth(uin) {
6083
try {
6184
const getUserAuthInfo = new GetUserAuthInfo()
62-
const result = await getUserAuthInfo.isAuth(uin)
85+
const result = await getUserAuthInfo.isAuth(uin, 'plugin')
6386
if (result['Error'] == true) {
6487
console.log('Failed to get real name authentication result.')
6588
process.exit(-1)

0 commit comments

Comments
 (0)