Skip to content

Commit

Permalink
feat: git 代理开关
Browse files Browse the repository at this point in the history
  • Loading branch information
greper committed Dec 4, 2020
1 parent 1b36d57 commit 2866c58
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 12 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/modules/plugin/git/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'Git代理',
enabled: false,
setting: {
sslVerify: false
}
}
65 changes: 65 additions & 0 deletions packages/core/src/modules/plugin/git/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const pluginConfig = require('./config')
const Plugin = function (context) {
const { config, shell, event, log } = context
const pluginApi = {
async start () {
const ip = '127.0.0.1'
const port = config.get().server.port
await pluginApi.setProxy(ip, port)
return { ip, port }
},

async close () {
return pluginApi.unsetProxy()
},

async restart () {
await pluginApi.close()
await pluginApi.start()
},

async save (newConfig) {

},

async setProxy (ip, port) {
const cmds = [
`git config --global http.proxy http://${ip}:${port}`,
`git config --global https.proxy http://${ip}:${port}`
]
if (pluginConfig.setting.sslVerify === false) {
cmds.push('git config http.sslVerify "false"')
}

const ret = await shell.exec(cmds, { type: 'cmd' })
event.fire('status', { key: 'plugin.git.enabled', value: true })
log.info('开启【Git】代理成功')

return ret
},

async unsetProxy () {
const cmds = [
'git config --global --unset https.proxy',
'git config --global --unset http.proxy'
]
if (pluginConfig.setting.sslVerify === false) {
cmds.push('git config --unset http.sslVerify ')
}
const ret = await shell.exec(cmds, { type: 'cmd' })
event.fire('status', { key: 'plugin.git.enabled', value: false })
log.info('关闭【Git】代理成功')
return ret
}
}
return pluginApi
}

module.exports = {
key: 'git',
config: pluginConfig,
status: {
enabled: false
},
plugin: Plugin
}
4 changes: 3 additions & 1 deletion packages/core/src/modules/plugin/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const node = require('./node')
const git = require('./git')
const overwall = require('./overwall')

module.exports = {
node, overwall
node, git, overwall
}
61 changes: 61 additions & 0 deletions packages/gui/src/view/pages/plugin/git.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<template>
<ds-container>
<template slot="header">
Git代理设置
<span>
</span>
</template>

<div v-if="config">
<a-form layout="horizontal">
<a-form-item label="启用Git代理" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.plugin.git.enabled">
随应用启动
</a-checkbox>
<a-tag v-if="status.plugin.git.enabled" color="green">
当前已启动
</a-tag>
<a-tag v-else color="red">
当前未启动
</a-tag>
</a-form-item>
<a-form-item label="SSL校验" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.plugin.git.setting.sslVerify">
关闭sslVerify
</a-checkbox>
安装Git时未选择使用系统证书管理服务时必须关闭
</a-form-item>
</a-form>
</div>
<template slot="footer">
<div class="footer-bar">
<a-button class="md-mr-10" icon="sync" @click="resetDefault()">恢复默认</a-button>
<a-button :loading="applyLoading" icon="check" type="primary" @click="apply()">应用</a-button>
</div>
</template>
</ds-container>

</template>

<script>
import Plugin from '../../mixins/plugin'
export default {
name: 'Git',
mixins: [Plugin],
data () {
return {
key: 'plugin.git'
}
},
created () {
console.log('status:', this.status)
},
mounted () {
},
methods: {
ready () {
}
}
}
</script>
2 changes: 1 addition & 1 deletion packages/gui/src/view/pages/plugin/node.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
当前未启动
</a-tag>
</a-form-item>
<a-form-item label="SSL相关" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-form-item label="SSL校验" :label-col="labelCol" :wrapper-col="wrapperCol">
<a-checkbox v-model="config.plugin.node.setting['strict-ssl']">
关闭strict-ssl
</a-checkbox>
Expand Down
2 changes: 2 additions & 0 deletions packages/gui/src/view/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Index from '../pages/index'
import Server from '../pages/server'
import Proxy from '../pages/proxy'
import Node from '../pages/plugin/node'
import Git from '../pages/plugin/git'
import Overwall from '../pages/plugin/overwall'

const routes = [
Expand All @@ -10,6 +11,7 @@ const routes = [
{ path: '/server', component: Server },
{ path: '/proxy', component: Proxy },
{ path: '/plugin/node', component: Node },
{ path: '/plugin/git', component: Git },
{ path: '/plugin/overwall', component: Overwall }

]
Expand Down
3 changes: 2 additions & 1 deletion packages/gui/src/view/router/menu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export default function createMenus (app) {
const plugins = [
{ title: 'NPM加速', path: '/plugin/node', icon: 'like' }
{ title: 'NPM加速', path: '/plugin/node', icon: 'like' },
{ title: 'Git代理', path: '/plugin/git', icon: 'github' }
]
const menus = [
{ title: '首页', path: '/index', icon: 'home' },
Expand Down
18 changes: 9 additions & 9 deletions packages/gui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -901,12 +901,12 @@
ajv "^6.12.0"
ajv-keywords "^3.4.1"

"@docmirror/dev-sidecar@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@docmirror/dev-sidecar/-/dev-sidecar-1.2.0.tgz#2320c31f786afd495b8e12557bea396cb96e0985"
integrity sha512-i96YlPjQtrrAgDW52YOpuVFmQDl1A0Nx3x6/riv2yKVN4nGqAugdJvcAuhNi7BDrJfdLyls2jI35uzN5+bpYfQ==
"@docmirror/dev-sidecar@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@docmirror/dev-sidecar/-/dev-sidecar-1.2.2.tgz#4963a9dd9f3f46e614e1c1479887b8680f0f6650"
integrity sha512-gWD5WPuyijIuFrpinMR0QSLdqdhLEfZVi9lnRSor9TnnaoBpeY6QlufHACpDDo6hME8f62adXGFmL3UoFJS49Q==
dependencies:
"@docmirror/mitmproxy" "^1.2.0"
"@docmirror/mitmproxy" "^1.2.2"
agentkeepalive "^2.1.1"
charset "^1.0.0"
child_process "^1.0.2"
Expand All @@ -933,10 +933,10 @@
validator "^13.1.17"
winreg "^1.2.4"

"@docmirror/mitmproxy@^1.2.0":
version "1.2.0"
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.2.0.tgz#ab9910031272d8e16fe0e38d434f7b42971bc74e"
integrity sha512-DlzquSNVZOC/p5GwAdDwSiI4KCb3HlUY4A44pGGOBehsNThBoRU8ESKJjbyay9ah4RPSAWTSVYgMEiPZctR+wg==
"@docmirror/mitmproxy@^1.2.2":
version "1.2.2"
resolved "https://registry.yarnpkg.com/@docmirror/mitmproxy/-/mitmproxy-1.2.2.tgz#a4d0020e073eaa68adb7902b5634ab2a1a3bc058"
integrity sha512-xW1xyqUfpGAZZTzqSjoQM0Mmq8VVEyvS8AiTUBvgpxUAYG2sqNCacLETwYfNBP1MStUBtGXKklcISpIY6+R+DA==
dependencies:
agentkeepalive "^2.1.1"
child_process "^1.0.2"
Expand Down

0 comments on commit 2866c58

Please sign in to comment.