mirror of
https://gitee.com/goploy/goploy.git
synced 2024-12-02 12:10:05 +08:00
A copy ssh public key
This commit is contained in:
parent
2a408ba0fe
commit
b20ac01b12
@ -24,11 +24,9 @@ type Deploy Controller
|
||||
|
||||
// GetList -
|
||||
func (Deploy) GetList(gp *core.Goploy) *core.Response {
|
||||
projectName := gp.URLQuery.Get("projectName")
|
||||
projects, err := model.Project{
|
||||
NamespaceID: gp.Namespace.ID,
|
||||
UserID: gp.UserInfo.ID,
|
||||
Name: projectName,
|
||||
}.GetUserProjectList()
|
||||
|
||||
if err != nil {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/zhenorzz/goploy/core"
|
||||
"github.com/zhenorzz/goploy/model"
|
||||
"github.com/zhenorzz/goploy/utils"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// Server struct
|
||||
@ -52,6 +53,19 @@ func (Server) GetOption(gp *core.Goploy) *core.Response {
|
||||
}
|
||||
}
|
||||
|
||||
// GetPublicKey -
|
||||
func (Server) GetPublicKey(gp *core.Goploy) *core.Response {
|
||||
path := gp.URLQuery.Get("path")
|
||||
|
||||
contentByte, err := ioutil.ReadFile(path + ".pub")
|
||||
if err != nil {
|
||||
return &core.Response{Code: core.Error, Message: err.Error()}
|
||||
}
|
||||
return &core.Response{
|
||||
Data: string(contentByte),
|
||||
}
|
||||
}
|
||||
|
||||
// Check server
|
||||
func (Server) Check(gp *core.Goploy) *core.Response {
|
||||
type ReqData struct {
|
||||
|
@ -329,7 +329,7 @@ func (p Project) GetTotal() (int64, error) {
|
||||
|
||||
// GetUserProjectList -
|
||||
func (p Project) GetUserProjectList() (Projects, error) {
|
||||
builder := sq.
|
||||
rows, err := sq.
|
||||
Select(`
|
||||
project.id,
|
||||
project.name,
|
||||
@ -351,13 +351,9 @@ func (p Project) GetUserProjectList() (Projects, error) {
|
||||
"project_user.user_id": p.UserID,
|
||||
"project.state": Enable,
|
||||
}).
|
||||
OrderBy("project.id DESC")
|
||||
|
||||
if len(p.Name) > 0 {
|
||||
builder = builder.Where(sq.Like{"project.name": "%" + p.Name + "%"})
|
||||
}
|
||||
|
||||
rows, err := builder.RunWith(DB).Query()
|
||||
OrderBy("project.id DESC").
|
||||
RunWith(DB).
|
||||
Query()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -97,6 +97,7 @@ func Init() *router.Router {
|
||||
rt.Add("/server/getList", http.MethodGet, controller.Server{}.GetList)
|
||||
rt.Add("/server/getTotal", http.MethodGet, controller.Server{}.GetTotal)
|
||||
rt.Add("/server/getOption", http.MethodGet, controller.Server{}.GetOption)
|
||||
rt.Add("/server/getPublicKey", http.MethodGet, controller.Server{}.GetPublicKey)
|
||||
rt.Add("/server/check", http.MethodPost, controller.Server{}.Check).Roles([]string{core.RoleAdmin, core.RoleManager})
|
||||
rt.Add("/server/add", http.MethodPost, controller.Server{}.Add).Roles([]string{core.RoleAdmin, core.RoleManager})
|
||||
rt.Add("/server/edit", http.MethodPost, controller.Server{}.Edit).Roles([]string{core.RoleAdmin, core.RoleManager})
|
||||
|
@ -22,6 +22,17 @@ export function getTotal() {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Promise}
|
||||
*/
|
||||
export function getPublicKey(path) {
|
||||
return request({
|
||||
url: '/server/getPublicKey',
|
||||
method: 'get',
|
||||
params: { path }
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {Promise}
|
||||
*/
|
||||
|
@ -137,6 +137,8 @@ export default {
|
||||
sshKeyOwner: 'SSH-Key Owner',
|
||||
sshKeyPath: 'SSH-Key Path',
|
||||
sshKeyPassword: 'SSH-Key Pswd',
|
||||
copyPub: 'Copy pub',
|
||||
copyPubTips: 'Copy success. Paste it to ~/.ssh/authorized_keys',
|
||||
testConnection: 'Test',
|
||||
removeServerTips: 'This action will delete the server({serverName}), continue?'
|
||||
},
|
||||
|
@ -137,6 +137,8 @@ export default {
|
||||
sshKeyOwner: 'SSH-Key 所有者',
|
||||
sshKeyPath: 'SSH-Key 路径',
|
||||
sshKeyPassword: 'SSH-Key 密码',
|
||||
copyPub: '复制共钥',
|
||||
copyPubTips: '复制成功,请粘贴到目标服务器~/.ssh/authorized_keys里面',
|
||||
testConnection: '测试连接',
|
||||
removeServerTips: '此操作将删除服务器({serverName}), 是否继续?'
|
||||
},
|
||||
|
@ -14,6 +14,26 @@ const mixin = {
|
||||
},
|
||||
isMember() {
|
||||
return this.$global.member === getNamespace()['role']
|
||||
},
|
||||
copy(content, message = '复制成功') {
|
||||
const el = document.createElement('textarea')
|
||||
el.value = content
|
||||
el.setAttribute('readonly', '')
|
||||
el.style.position = 'absolute'
|
||||
el.style.left = '-9999px'
|
||||
document.body.appendChild(el)
|
||||
const selected =
|
||||
document.getSelection().rangeCount > 0
|
||||
? document.getSelection().getRangeAt(0)
|
||||
: false
|
||||
el.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(el)
|
||||
if (selected) {
|
||||
document.getSelection().removeAllRanges()
|
||||
document.getSelection().addRange(selected)
|
||||
}
|
||||
this.$message.success(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,17 @@
|
||||
<template>
|
||||
<el-row class="app-container">
|
||||
<el-row class="app-bar" type="flex">
|
||||
<el-input v-model="projectName" style="width:300px" placeholder="Filter the project name" @change="getList" />
|
||||
<el-select v-model="searchProject.environment" placeholder="environment" clearable>
|
||||
<el-option :label="$t('envOption[1]')" :value="1" />
|
||||
<el-option :label="$t('envOption[2]')" :value="2" />
|
||||
<el-option :label="$t('envOption[3]')" :value="3" />
|
||||
<el-option :label="$t('envOption[4]')" :value="4" />
|
||||
</el-select>
|
||||
<el-select v-model="searchProject.autoDeploy" placeholder="auto deploy" clearable>
|
||||
<el-option :label="$t('close')" :value="0" />
|
||||
<el-option label="webhook" :value="1" />
|
||||
</el-select>
|
||||
<el-input v-model="searchProject.name" style="width:300px" placeholder="Filter the project name" />
|
||||
</el-row>
|
||||
<el-table
|
||||
:key="tableHeight"
|
||||
@ -611,7 +621,6 @@ export default {
|
||||
return {
|
||||
userId: '',
|
||||
userOption: [],
|
||||
projectName: '',
|
||||
publishToken: '',
|
||||
commitDialogVisible: false,
|
||||
tagDialogVisible: false,
|
||||
@ -624,10 +633,15 @@ export default {
|
||||
traceLoading: false,
|
||||
tableloading: false,
|
||||
tableData: [],
|
||||
searchProject: {
|
||||
name: '',
|
||||
environment: '',
|
||||
autoDeploy: ''
|
||||
},
|
||||
pagination: {
|
||||
total: 0,
|
||||
page: 1,
|
||||
rows: 20
|
||||
rows: 16
|
||||
},
|
||||
taskTableLoading: false,
|
||||
taskTableData: [],
|
||||
@ -741,7 +755,17 @@ export default {
|
||||
},
|
||||
computed: {
|
||||
tablePageData: function() {
|
||||
return this.tableData.slice((this.pagination.page - 1) * this.pagination.rows, this.pagination.page * this.pagination.rows)
|
||||
let tableData = this.tableData
|
||||
if (this.searchProject.name !== '') {
|
||||
tableData = this.tableData.filter(item => item.name.indexOf(this.searchProject.name) !== -1)
|
||||
}
|
||||
if (this.searchProject.environment !== '') {
|
||||
tableData = this.tableData.filter(item => item.environment === this.searchProject.environment)
|
||||
}
|
||||
if (this.searchProject.autoDeploy !== '') {
|
||||
tableData = this.tableData.filter(item => item.autoDeploy === this.searchProject.autoDeploy)
|
||||
}
|
||||
return tableData.slice((this.pagination.page - 1) * this.pagination.rows, this.pagination.page * this.pagination.rows)
|
||||
},
|
||||
previewFilterlength: function() {
|
||||
let number = 0
|
||||
@ -813,7 +837,7 @@ export default {
|
||||
|
||||
getList() {
|
||||
this.tableloading = true
|
||||
getList(this.projectName).then((response) => {
|
||||
getList().then((response) => {
|
||||
this.tableData = response.data.list.map(element => {
|
||||
element.progressPercentage = 0
|
||||
element.tagType = 'info'
|
||||
|
@ -70,7 +70,9 @@
|
||||
<el-table-column prop="operation" :label="$t('op')" width="180" align="center" fixed="right">
|
||||
<template slot-scope="scope">
|
||||
<el-button type="primary" icon="el-icon-edit" @click="handleEdit(scope.row)" />
|
||||
<el-button type="info" icon="el-icon-document-copy" @click="handleCopy(scope.row)" />
|
||||
<el-tooltip class="item" effect="dark" content="Copy" placement="bottom">
|
||||
<el-button type="info" icon="el-icon-document-copy" @click="handleCopy(scope.row)" />
|
||||
</el-tooltip>
|
||||
<el-button type="danger" icon="el-icon-delete" @click="handleRemove(scope.row)" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
@ -54,7 +54,15 @@
|
||||
<el-input v-model="formData.owner" autocomplete="off" placeholder="root" />
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('serverPage.sshKeyPath')" prop="path">
|
||||
<el-input v-model="formData.path" autocomplete="off" placeholder="/root/.ssh/id_rsa" />
|
||||
<el-row type="flex">
|
||||
<el-input v-model="formData.path" autocomplete="off" placeholder="/root/.ssh/id_rsa" />
|
||||
<el-button
|
||||
:icon="'el-icon-copy-document'"
|
||||
type="success"
|
||||
:disabled="formData.path===''"
|
||||
@click="getPublicKey"
|
||||
>{{ $t('serverPage.copyPub') }}</el-button>
|
||||
</el-row>
|
||||
</el-form-item>
|
||||
<el-form-item :label="$t('serverPage.sshKeyPassword')" prop="password">
|
||||
<el-input v-model="formData.password" autocomplete="off" placeholder="" />
|
||||
@ -80,7 +88,7 @@
|
||||
</el-row>
|
||||
</template>
|
||||
<script>
|
||||
import { getList, getTotal, add, edit, check, remove } from '@/api/server'
|
||||
import { getList, getTotal, getPublicKey, add, edit, check, remove } from '@/api/server'
|
||||
|
||||
export default {
|
||||
name: 'Server',
|
||||
@ -154,6 +162,12 @@ export default {
|
||||
})
|
||||
},
|
||||
|
||||
getPublicKey() {
|
||||
getPublicKey(this.formData.path).then((response) => {
|
||||
this.copy(response.data, this.$t('serverPage.copyPubTips'))
|
||||
})
|
||||
},
|
||||
|
||||
// 分页事件
|
||||
handlePageChange(val) {
|
||||
this.pagination.page = val
|
||||
|
Loading…
Reference in New Issue
Block a user