mirror of
https://github.com/jumpserver/lina.git
synced 2026-01-29 21:28:52 +00:00
perf: add auto generate ssh-key
This commit is contained in:
@@ -1,23 +1,32 @@
|
||||
<template>
|
||||
<GenericCreateUpdatePage v-if="!loading" v-bind="$data" :after-get-form-value="afterGetFormValue" />
|
||||
<GenericCreateUpdatePage
|
||||
v-if="!loading"
|
||||
v-bind="$data"
|
||||
:after-get-form-value="afterGetFormValue"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import GenericCreateUpdatePage from '@/layout/components/GenericCreateUpdatePage/index.vue'
|
||||
import { downloadText } from '@/utils/common'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
GenericCreateUpdatePage
|
||||
},
|
||||
data() {
|
||||
const vm = this
|
||||
return {
|
||||
isCreated: this.$route?.meta.action === 'create',
|
||||
loading: true,
|
||||
url: '/api/v1/authentication/ssh-key/',
|
||||
fields: [
|
||||
'name',
|
||||
'generate_key_type',
|
||||
'current_public_key',
|
||||
'public_key',
|
||||
'is_active'
|
||||
'is_active',
|
||||
'comment'
|
||||
],
|
||||
fieldsMeta: {
|
||||
name: {},
|
||||
@@ -27,14 +36,41 @@ export default {
|
||||
type: 'textarea',
|
||||
placeholder: 'ssh-rsa AAAA...',
|
||||
autosize: { minRows: 3 }
|
||||
},
|
||||
hidden: (formValue) => {
|
||||
return formValue.generate_key_type === 'auto' || !this.isCreated
|
||||
}
|
||||
},
|
||||
current_public_key: {
|
||||
hidden: () => {
|
||||
return this.$route?.meta.action === 'create'
|
||||
return this.isCreated
|
||||
},
|
||||
disabled: true,
|
||||
label: this.$t('OldPublicKey')
|
||||
},
|
||||
generate_key_type: {
|
||||
helpTextAsTip: false,
|
||||
hidden: () => {
|
||||
return !this.isCreated
|
||||
}
|
||||
}
|
||||
},
|
||||
onSubmit(validValues) {
|
||||
const isCreated = this.$route?.meta.action === 'create'
|
||||
if (validValues['generate_key_type'] === 'auto' && isCreated) {
|
||||
const name = validValues['name']
|
||||
this.$axios.get(`/core/auth/profile/pubkey/generate/?name=${name}`)
|
||||
.then((res) => {
|
||||
vm.createSuccessHandle()
|
||||
downloadText(res, `${name}.jumpserver.pem`)
|
||||
})
|
||||
} else {
|
||||
const method = isCreated ? 'post' : 'patch'
|
||||
delete validValues['generate_key_type']
|
||||
this.$axios[method](this.iUrl, validValues)
|
||||
.then(() => {
|
||||
vm.createSuccessHandle()
|
||||
}).catch((error) => this.onPerformError(error, this.method, this))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,6 +85,10 @@ export default {
|
||||
const publicKey = value['public_key_hash_md5'] ? `${value['public_key_comment']} (${value['public_key_hash_md5']})` : ' '
|
||||
value['current_public_key'] = publicKey
|
||||
return value
|
||||
},
|
||||
createSuccessHandle() {
|
||||
this.$router.push({ name: 'SSHKeyList', query: { order: '-date_created', updated: new Date().getTime() }})
|
||||
this.$message.success(this.$tc('CreateSuccessMsg'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export default {
|
||||
tableConfig: {
|
||||
hasSelection: true,
|
||||
url: '/api/v1/authentication/ssh-key/',
|
||||
columns: ['id', 'name', 'is_active', 'date_created', 'date_last_used'],
|
||||
columns: ['id', 'name', 'comment', 'is_active', 'date_created', 'date_last_used'],
|
||||
columnsShow: {
|
||||
min: ['id', 'name']
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user