Skip to content

Commit ae5773f

Browse files
author
lixiaolong
committed
[fix] 从SaaS获取token限制时间一分钟,超时取消操作并提示重新重新获取
1 parent c933309 commit ae5773f

File tree

5 files changed

+47
-22
lines changed

5 files changed

+47
-22
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# 更新记录
22

3+
## [1.0.5]
4+
5+
- 从SaaS获取token限制时间一分钟,超时取消操作并提示重新重新获取
6+
37
## [1.0.4]
48

59
- 兼容 VSCode 1.70.X版本

README.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
[![Version](https://vsmarketplacebadges.dev/version-short/xmirror.opensca.svg)](https://marketplace.visualstudio.com/items?itemName=xmirror.opensca)
2-
[![Downloads](https://vsmarketplacebadges.dev/downloads-short/xmirror.opensca.svg)](https://marketplace.visualstudio.com/items?itemName=xmirror.opensca)
3-
[![Rating](https://vsmarketplacebadges.dev/rating-star/xmirror.opensca.svg)](https://marketplace.visualstudio.com/items?itemName=xmirror.opensca)
4-
![License](https://img.shields.io/github/license/XmirrorSecurity/OpenSCA-VSCode-plugin)
5-
61
<p align="center">
72
<img alt="logo" src="https://opensca.xmirror.cn/docs/img/OpenSCAlogo.png">
83
</p>
94
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">OpenSCA Xcheck</h1>
105
<h4 align="center">VS Code平台的OpenSCA Xcheck插件,让代码更安全</h4>
11-
6+
<p align="center">
7+
<a href="https://github.com/XmirrorSecurity/OpenSCA-intellij-plugin/blob/master/LICENSE"><img src="https://img.shields.io/github/license/XmirrorSecurity/OpenSCA-intellij-plugin?style=flat-square"></a>
8+
<!-- <a href="https://github.com/XmirrorSecurity/OpenSCA-intellij-plugin/releases"><img src="https://img.shields.io/github/v/release/XmirrorSecurity/OpenSCA-intellij-plugin?style=flat-square"></a> -->
9+
</p>
1210

1311
---
1412

@@ -20,8 +18,6 @@
2018

2119
**安装方法一**:在[适配的VS Code](https://code.visualstudio.com/)中通过应用商店安装(推荐)
2220

23-
> 点击这里直达 [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=xmirror.opensca)
24-
2521
在VS Code中左边栏打开扩展->扩展的搜索框中输入“OpenSCA Xcheck”,点击“Install”
2622

2723
<img src="https://opensca.xmirror.cn/docs/img/vscode_01.jpg" alt="xcheck_market" />

src/command/scan.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,18 +186,17 @@ export default class Scan extends Utils implements IScan {
186186
const confJson: string = fs.readFileSync(this.defaultConfigPath, 'utf-8') || '{}';
187187
interface ConfType {
188188
path?: string;
189+
token?: string;
189190
out?: string;
190191
vuln?: boolean;
191192
dedup?: boolean;
192193
progress?: boolean;
193194
url?: string;
194-
token?: string;
195195
log?: string;
196196
origin?: any;
197197
maven?: any[];
198198
}
199-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
200-
let conf: ConfType = JSON.parse(confJson);
199+
let conf: ConfType = <ConfType>JSON.parse(confJson);
201200
const localDataSource: object = vscode.workspace.getConfiguration('opensca').get('localDataSource') || {};
202201
const usingRemoteDataSource: boolean = vscode.workspace.getConfiguration('opensca').get('usingRemoteDataSource') || false;
203202
const usingLocalDataSource: boolean = vscode.workspace.getConfiguration('opensca').get('usingLocalDataSource') || false;

src/command/setToken.ts

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ export default class SetToken extends Utils implements ISetToken {
2020
constructor() {
2121
super();
2222
}
23+
24+
/**
25+
* 点击设置token
26+
* @returns {void}
27+
*/
2328
async toSetToken(): Promise<void> {
2429
Loger.info('点击设置token');
2530
const token = await vscode.window.showInputBox({
@@ -50,6 +55,10 @@ export default class SetToken extends Utils implements ISetToken {
5055
});
5156
}
5257

58+
/**
59+
* 点击获取token
60+
* @returns {void}
61+
*/
5362
toGetToken(): void {
5463
if (this.vsProgress) {
5564
vscode.window.showWarningMessage(`正在获取token,请耐心等待`);
@@ -73,6 +82,10 @@ export default class SetToken extends Utils implements ISetToken {
7382
});
7483
}
7584

85+
/**
86+
* 获取token
87+
* @returns {void}
88+
*/
7689
private getToken(): void {
7790
this.vsProgress = vscode.window.withProgress(
7891
{
@@ -93,32 +106,48 @@ export default class SetToken extends Utils implements ISetToken {
93106
),
94107
5000
95108
);
109+
// 时间过长打断操作
110+
setTimeout(() => {
111+
if (!this.vsProgress) {
112+
return;
113+
}
114+
reject(false);
115+
this.cancel();
116+
Loger.warning('token获取超时');
117+
vscode.window.showWarningMessage('token获取超时', '重新获取', '取消').then(selection => {
118+
if (selection === '重新获取') {
119+
vscode.commands.executeCommand(OPENSCA_GET_TOKEN_COMMAND);
120+
} else if (selection === '取消') {
121+
Loger.warning('点击取消了重新获取token');
122+
}
123+
});
124+
}, 1000 * 60);
96125
});
97126
}
98127
);
99128
}
100129

101130
/**
102-
* 停止检测
131+
* 取消获取token
103132
* @returns {void}
104133
*/
105-
cancel(): void {
134+
private cancel(): void {
106135
if (this.vsProgress) {
107136
this.vsProgress.then(() => {
108137
Loger.info('结束获取 OSS Token.');
109138
});
110139
this.vsProgress = undefined;
111140
}
112-
this.clearInterval();
113-
}
114-
115-
private clearInterval() {
116141
if (this.interval) {
117142
clearInterval(this.interval);
118143
this.interval = null;
119144
}
120145
}
121146

147+
/**
148+
* 从服务端自动获取token
149+
* @returns {void}
150+
*/
122151
private async autoGetTokenService(resolve: { (): void }, reject: { (): void }) {
123152
const res: TokenResponseType = await Service.ossToken(this.tokenId);
124153
if (isObject(res) && res.code !== 0) {
@@ -141,7 +170,6 @@ export default class SetToken extends Utils implements ISetToken {
141170
vscode.commands.executeCommand(OPENSCA_GET_TOKEN_COMMAND);
142171
}
143172
});
144-
this.cancel();
145173
}
146174

147175
if (code !== 200) {

src/common/utils.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ export default class Utils {
151151
} else {
152152
return {};
153153
}
154-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
155-
const outputRes: ReportType = JSON.parse(outputJson);
154+
const outputRes: ReportType = <ReportType>JSON.parse(outputJson);
156155
return outputRes.task_info;
157156
}
158157

@@ -164,8 +163,7 @@ export default class Utils {
164163
} else {
165164
return [];
166165
}
167-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
168-
const outputRes: ReportType = JSON.parse(outputJson);
166+
const outputRes: ReportType = <ReportType>JSON.parse(outputJson);
169167
const list: ComponentDataType[] = outputRes.children || [];
170168

171169
const _uniqWith = (list: ComponentDataType[]) => {

0 commit comments

Comments
 (0)