@@ -9,9 +9,10 @@ import { AbstractClient } from "tencentcloud-sdk-nodejs/tencentcloud/common/abst
9
9
import { Credential } from "tencentcloud-sdk-nodejs/tencentcloud/common/interface" ;
10
10
import { getCamClient , getStsClient } from "@/connectivity/client" ;
11
11
import * as loginMgt from "../../../views/login/loginMgt" ;
12
+ import * as settingUtils from "../../../utils/settingUtils" ;
12
13
13
14
export namespace user {
14
- interface UserInfo {
15
+ export interface UserInfo {
15
16
secretId : string ;
16
17
secretKey : string ;
17
18
token ?: string ;
@@ -40,71 +41,81 @@ export namespace user {
40
41
const credential = await getCredentailByInput ( ) ;
41
42
const accessKey = credential . secretId ;
42
43
const secretKey = credential . secretKey ;
44
+ const region = credential . region ;
43
45
44
46
// get configuration
45
47
const config = workspace . getConfiguration ( ) ;
48
+
46
49
// set in vscode configuration(setting.json)
47
- config . update ( 'tcTerraform.properties.secretId' , accessKey , ConfigurationTarget . Global )
50
+ await config . update ( 'tcTerraform.properties.secretId' , accessKey , ConfigurationTarget . Global )
51
+ . then ( ( ) => {
52
+ } , ( error ) => {
53
+ window . showErrorMessage ( 'set secretId failed: ' + error ) ;
54
+ } ) ;
55
+ await config . update ( 'tcTerraform.properties.secretKey' , secretKey , ConfigurationTarget . Global )
48
56
. then ( ( ) => {
49
57
} , ( error ) => {
50
- window . showErrorMessage ( '设置secretId失败 : ' + error ) ;
58
+ window . showErrorMessage ( 'set secretKey failed : ' + error ) ;
51
59
} ) ;
52
- config . update ( 'tcTerraform.properties.secretKey ' , secretKey , ConfigurationTarget . Global )
60
+ await config . update ( 'tcTerraform.properties.region ' , region , ConfigurationTarget . Global )
53
61
. then ( ( ) => {
54
62
} , ( error ) => {
55
- window . showErrorMessage ( '设置secretKey失败 : ' + error ) ;
63
+ window . showErrorMessage ( 'set region failed : ' + error ) ;
56
64
} ) ;
57
65
58
66
// set in system environment
59
67
process . env . TENCENTCLOUD_SECRET_ID = accessKey ;
60
68
process . env . TENCENTCLOUD_SECRET_KEY = secretKey ;
69
+ process . env . TENCENTCLOUD_REGION = region ;
61
70
62
- // query user info
63
- const stsResp = await ( await getStsClient ( ) ) . GetCallerIdentity ( ) .
64
- then (
65
- ( result ) => {
66
- console . debug ( '[DEBUG]--------------------------------result:' , result ) ;
67
- if ( ! result ) {
68
- throw new Error ( '[Warn] GetCallerIdentity result.TotalCount is 0.' ) ;
71
+ try {
72
+ // query user info
73
+ const stsClient = await getStsClient ( ) ;
74
+ const stsResp = await stsClient ?. GetCallerIdentity ( ) .
75
+ then (
76
+ ( result ) => {
77
+ console . debug ( '[DEBUG]--------------------------------result:' , result ) ;
78
+ if ( ! result ) {
79
+ throw new Error ( '[Warn] GetCallerIdentity result.TotalCount is 0.' ) ;
80
+ }
81
+ return result ;
82
+ } ,
83
+ ( err ) => {
84
+ throw new Error ( err ) ;
69
85
}
70
- return result ;
71
- } ,
72
- ( err ) => {
73
- console . error ( '[TencentCloudSDKError] GetCallerIdentity got a error from SDK.' , err . message ) ;
74
- window . showErrorMessage ( 'Login Failed. Reason:' + err . message ) ;
75
- return err ;
76
- }
77
- ) ;
78
-
79
- const camResp = await ( await getCamClient ( ) ) . GetUserAppId ( ) .
80
- then (
81
- ( result ) => {
82
- console . debug ( '[DEBUG]--------------------------------result:' , result ) ;
83
- if ( ! result ) {
84
- throw new Error ( '[Warn] GetUserAppId result.TotalCount is 0.' ) ;
86
+ ) ;
87
+
88
+ const camClient = await getCamClient ( ) ;
89
+ const camResp = await camClient ?. GetUserAppId ( ) .
90
+ then (
91
+ ( result ) => {
92
+ console . debug ( '[DEBUG]--------------------------------result:' , result ) ;
93
+ if ( ! result ) {
94
+ throw new Error ( '[Warn] GetUserAppId result.TotalCount is 0.' ) ;
95
+ }
96
+ return result ;
97
+ } ,
98
+ ( err ) => {
99
+ throw new Error ( err ) ;
85
100
}
86
- return result ;
87
- } ,
88
- ( err ) => {
89
- console . error ( '[TencentCloudSDKError] GetUserAppId got a error from SDK.' , err . message ) ;
90
- window . showErrorMessage ( 'Login Failed. Reason:' + err . message ) ;
91
- return err ;
92
- }
93
- ) ;
94
-
95
- // set user info
96
- let userinfo : UserInfo = {
97
- secretId : accessKey ,
98
- secretKey : secretKey ,
99
- uin : stsResp . PrincipalId ?? stsResp . UserId ?? "-" ,
100
- type : stsResp . Type ?? "unknow" ,
101
- appid : camResp . AppId ?? "-" ,
102
- arn : stsResp . Arn ,
103
- region : process . env . TENCENTCLOUD_REGION ?? "unknow" ,
104
- } ;
105
- setInfo ( userinfo ) ;
106
-
107
- // tree.refreshTreeData();
101
+ ) ;
102
+
103
+ // set user info
104
+ let userinfo : UserInfo = {
105
+ secretId : accessKey ,
106
+ secretKey : secretKey ,
107
+ uin : stsResp . PrincipalId ?? stsResp . UserId ?? "-" ,
108
+ type : stsResp . Type ?? "unknow" ,
109
+ appid : String ( camResp . AppId ) ?? "-" ,
110
+ arn : stsResp . Arn ,
111
+ region : region ?? "unknow" ,
112
+ } ;
113
+ setInfo ( userinfo ) ;
114
+
115
+ } catch ( err ) {
116
+ console . error ( '[TencentCloudSDKError]' , err . message ) ;
117
+ window . showErrorMessage ( 'Login Failed. Reason:' + err . message ) ;
118
+ }
108
119
}
109
120
if ( oauth === pick ) {
110
121
// to do
@@ -127,6 +138,7 @@ export namespace user {
127
138
128
139
await clearInfo ( ) ;
129
140
loginMgt . clearStatusBar ( ) ;
141
+ settingUtils . clearAKSKandRegion ( ) ;
130
142
131
143
tree . refreshTreeData ( ) ;
132
144
}
0 commit comments