@@ -9,9 +9,10 @@ import { AbstractClient } from "tencentcloud-sdk-nodejs/tencentcloud/common/abst
99import { Credential } from "tencentcloud-sdk-nodejs/tencentcloud/common/interface" ;
1010import { getCamClient , getStsClient } from "@/connectivity/client" ;
1111import * as loginMgt from "../../../views/login/loginMgt" ;
12+ import * as settingUtils from "../../../utils/settingUtils" ;
1213
1314export namespace user {
14- interface UserInfo {
15+ export interface UserInfo {
1516 secretId : string ;
1617 secretKey : string ;
1718 token ?: string ;
@@ -40,71 +41,81 @@ export namespace user {
4041 const credential = await getCredentailByInput ( ) ;
4142 const accessKey = credential . secretId ;
4243 const secretKey = credential . secretKey ;
44+ const region = credential . region ;
4345
4446 // get configuration
4547 const config = workspace . getConfiguration ( ) ;
48+
4649 // 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 )
4856 . then ( ( ) => {
4957 } , ( error ) => {
50- window . showErrorMessage ( '设置secretId失败 : ' + error ) ;
58+ window . showErrorMessage ( 'set secretKey failed : ' + error ) ;
5159 } ) ;
52- config . update ( 'tcTerraform.properties.secretKey ' , secretKey , ConfigurationTarget . Global )
60+ await config . update ( 'tcTerraform.properties.region ' , region , ConfigurationTarget . Global )
5361 . then ( ( ) => {
5462 } , ( error ) => {
55- window . showErrorMessage ( '设置secretKey失败 : ' + error ) ;
63+ window . showErrorMessage ( 'set region failed : ' + error ) ;
5664 } ) ;
5765
5866 // set in system environment
5967 process . env . TENCENTCLOUD_SECRET_ID = accessKey ;
6068 process . env . TENCENTCLOUD_SECRET_KEY = secretKey ;
69+ process . env . TENCENTCLOUD_REGION = region ;
6170
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 ) ;
6985 }
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 ) ;
85100 }
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+ }
108119 }
109120 if ( oauth === pick ) {
110121 // to do
@@ -127,6 +138,7 @@ export namespace user {
127138
128139 await clearInfo ( ) ;
129140 loginMgt . clearStatusBar ( ) ;
141+ settingUtils . clearAKSKandRegion ( ) ;
130142
131143 tree . refreshTreeData ( ) ;
132144 }
0 commit comments