perf: add auto generate ssh-key

This commit is contained in:
wangruidong
2024-08-12 17:03:04 +08:00
committed by Bryan
parent 32cd030479
commit 9b97dc9a74
2 changed files with 44 additions and 4 deletions

View File

@@ -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'))
}
}
}

View File

@@ -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']
},