From 8181f79357716d1b1d859acca038d90f8f920cb5 Mon Sep 17 00:00:00 2001 From: TaoTao-PC Date: Sat, 11 Apr 2020 16:52:50 +0800 Subject: [PATCH] Add an option like git config `sslVerify` fix #14 close #14 --- package.json | 6 ++++++ src/Config.ts | 8 ++++++++ src/issueProvider.ts | 17 +++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 235f23d..cb02490 100644 --- a/package.json +++ b/package.json @@ -93,6 +93,12 @@ "type": "string", "default": "", "description": "The repository name." + }, + "gitea.sslVerify": { + "scope": "resource", + "type": "boolean", + "default": true, + "description": "true=Stop when cannot verify SSL certificate, false=Continue any way. Like git config 'sslVerify'." } } } diff --git a/src/Config.ts b/src/Config.ts index 683df3c..db54991 100644 --- a/src/Config.ts +++ b/src/Config.ts @@ -5,6 +5,7 @@ interface ConfigStorage { instanceURL: string; owner: string; repo: string; + sslVerify: boolean; } export interface ConfigTypes extends ConfigStorage { @@ -69,4 +70,11 @@ export class Config implements ConfigTypes { public get repoApiUrl() { return this.instanceURL + '/api/v1/repos/' + this.owner + '/' + this.repo + '/issues'; } + + public set sslVerify(value){ + this.storage.update('sslVerify', value); + } + public get sslVerify(){ + return this.loadConfigValue('sslVerify', 'boolean') + } } diff --git a/src/issueProvider.ts b/src/issueProvider.ts index b78510b..666d895 100644 --- a/src/issueProvider.ts +++ b/src/issueProvider.ts @@ -1,5 +1,6 @@ import axios from 'axios'; import * as vscode from 'vscode'; +import * as https from 'https'; const marked = require('marked'); import { Issue } from './issue'; @@ -36,9 +37,15 @@ export class OpenIssuesProvider implements vscode.TreeDataProvider { const repoUri = config.repoApiUrl; const token = config.token; let stop = false; + + const agent = new https.Agent({ + // if true, stop when can't verify ssl + rejectUnauthorized: config.sslVerify, + }); + for (let i = 0; i !== 10; i++) { await axios - .get(repoUri + '?page=' + i, { headers: { Authorization: 'token ' + token } }) + .get(repoUri + '?page=' + i, { headers: { Authorization: 'token ' + token }, httpsAgent: agent }) .then((res) => { if (res.data.length === 0) { stop = true; @@ -88,9 +95,15 @@ export class ClosedIssuesProvider implements vscode.TreeDataProvider { const repoUri = config.repoApiUrl; const token = config.token; let stop = false; + + const agent = new https.Agent({ + // if true, stop when can't verify ssl + rejectUnauthorized: config.sslVerify, + }); + for (let i = 0; i !== 10; i++) { await axios - .get(repoUri + '?state=closed&page=' + i, { headers: { Authorization: 'token ' + token } }) + .get(repoUri + '?state=closed&page=' + i, { headers: { Authorization: 'token ' + token } , httpsAgent: agent} ) .then((res) => { console.log(res.data); if (res.data.length === 0) {