Skip to content

Commit

Permalink
feat: azure key vault
Browse files Browse the repository at this point in the history
  • Loading branch information
Halo1236 committed Nov 5, 2024
1 parent 305e44e commit 4a9a905
Show file tree
Hide file tree
Showing 5 changed files with 205 additions and 38 deletions.
61 changes: 61 additions & 0 deletions src/views/settings/Feature/Vault/Azure.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<template>
<BaseKV :config="$data" :title="$tc('AzureKeyVault')" />
</template>

<script>
import BaseKV from './Base.vue'
export default {
name: 'AzureKV',
components: {
BaseKV
},
data() {
const vm = this
return {
url: `/api/v1/settings/setting/?category=azure_kv`,
hasDetailInMsg: false,
visible: false,
moreButtons: [
{
title: this.$t('Test'),
loading: false,
callback: function(value, form, btn) {
btn.loading = true
vm.$axios.post(
'/api/v1/settings/vault/azure/testing/',
value
).then(res => {
vm.$message.success(res['msg'])
}).catch(() => {
vm.$log.error('err occur')
}).finally(() => { btn.loading = false })
}
}
],
encryptedFields: ['VAULT_AZURE_CLIENT_SECRET'],
fields: [
[this.$t('AccountStorage'),
[
'VAULT_AZURE_HOST',
'VAULT_AZURE_CLIENT_ID',
'VAULT_AZURE_CLIENT_SECRET',
'VAULT_AZURE_TENANT_ID'
]
]
],
fieldsMeta: {
},
submitMethod() {
return 'patch'
}
}
},
computed: {},
methods: {}
}
</script>

<style scoped>
</style>
63 changes: 63 additions & 0 deletions src/views/settings/Feature/Vault/Base.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<template>
<div>
<el-button size="mini" type="primary" icon="el-icon-setting" @click="visible=true">{{ $t('Setting') }}</el-button>
<Dialog
v-if="visible"
:destroy-on-close="true"
:show-cancel="false"
:show-confirm="false"
:title="title"
:visible.sync="visible"
width="70%"
@confirm="onConfirm()"
v-on="$listeners"
>
<GenericCreateUpdateForm ref="form" v-bind="iConfig" @submitSuccess="submitSuccess" />
</Dialog>
</div>
</template>

<script>
import Dialog from '@/components/Dialog/index.vue'
import GenericCreateUpdateForm from '@/layout/components/GenericCreateUpdateForm/index.vue'
export default {
name: 'Base',
components: {
Dialog,
GenericCreateUpdateForm
},
props: {
title: {
type: String,
default: ''
},
config: {
type: Object,
default: () => ({})
}
},
data() {
return {
visible: false
}
},
computed: {
iConfig() {
return this.config
}
},
methods: {
onConfirm() {
},
submitSuccess(res) {
this.$emit('input', !!res[this.enableField])
this.visible = false
}
}
}
</script>

<style scoped>
</style>
64 changes: 64 additions & 0 deletions src/views/settings/Feature/Vault/HCP.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<template>
<BaseKV :config="$data" :title="$tc('HashicorpVault')" />
</template>

<script>
import BaseKV from './Base.vue'
export default {
name: 'HashiCorpKV',
components: {
BaseKV
},
data() {
const vm = this
return {
url: `/api/v1/settings/setting/?category=hcp`,
hasDetailInMsg: false,
visible: false,
moreButtons: [
{
title: this.$t('Test'),
loading: false,
callback: function(value, form, btn) {
btn.loading = true
vm.$axios.post(
'/api/v1/settings/vault/hcp/testing/',
value
).then(res => {
vm.$message.success(res['msg'])
}).catch(() => {
vm.$log.error('err occur')
}).finally(() => { btn.loading = false })
}
}
],
encryptedFields: ['VAULT_HCP_TOKEN'],
fields: [
[this.$t('AccountStorage'),
[
'VAULT_HCP_HOST',
'VAULT_HCP_TOKEN',
'VAULT_HCP_MOUNT_POINT'
]
]
],
fieldsMeta: {
VAULT_HCP_MOUNT_POINT: {
helpText: this.$t('VaultHCPMountPoint'),
helpTextAsTip: true
}
},
submitMethod() {
return 'patch'
}
}
},
computed: {},
methods: {}
}
</script>

<style scoped>
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { GenericCreateUpdateForm } from '@/layout/components'
import IBox from '@/components/IBox/index.vue'
import { openTaskPage } from '@/utils/jms'
import store from '@/store'
import HashiCorpKV from './HCP.vue'
import AzureKV from './Azure.vue'
export default {
components: {
Expand All @@ -25,24 +27,6 @@ export default {
hasReset: false,
helpText: this.$t('VaultHelpText'),
moreButtons: [
{
title: this.$t('Test'),
loading: false,
disabled: !store.getters.publicSettings['VAULT_ENABLED'],
callback: function(value, form, btn) {
btn.loading = true
vm.$axios.post(
'/api/v1/settings/vault/testing/',
value
).then(res => {
vm.$message.success(res['msg'])
}).catch(() => {
vm.$log.error('err occur')
}).finally(() => {
btn.loading = false
})
}
},
{
title: this.$t('Sync'),
loading: false,
Expand All @@ -62,17 +46,9 @@ export default {
}
}
],
encryptedFields: ['VAULT_HCP_TOKEN'],
fields: [
[this.$t('Backend'),
[
'VAULT_ENABLED',
'VAULT_HCP_HOST',
'VAULT_HCP_TOKEN',
'VAULT_HCP_MOUNT_POINT'
]
],
[this.$t('History'), ['HISTORY_ACCOUNT_CLEAN_LIMIT']]
[this.$t('Basic'), ['VAULT_ENABLED', 'VAULT_BACKEND', 'HISTORY_ACCOUNT_CLEAN_LIMIT']],
[this.$t('Provider'), ['HCP', 'AZURE']]
],
fieldsMeta: {
HISTORY_ACCOUNT_CLEAN_LIMIT: {
Expand All @@ -83,21 +59,24 @@ export default {
VAULT_ENABLED: {
disabled: true
},
VAULT_HCP_HOST: {
VAULT_BACKEND: {
label: this.$t('Provider'),
hidden: (formValue) => {
return !formValue.VAULT_ENABLED
}
},
VAULT_HCP_TOKEN: {
hidden: (formValue) => {
return !formValue.VAULT_ENABLED
HCP: {
label: this.$t('HashicorpVault'),
component: HashiCorpKV,
hidden: (form) => {
return form['VAULT_BACKEND'] !== 'hcp'
}
},
VAULT_HCP_MOUNT_POINT: {
helpText: this.$t('VaultHCPMountPoint'),
helpTextAsTip: true,
hidden: (formValue) => {
return !formValue.VAULT_ENABLED
AZURE: {
label: this.$t('AzureKeyVault'),
component: AzureKV,
hidden: (form) => {
return form['VAULT_BACKEND'] !== 'azure'
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/views/settings/Feature/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<script>
import TabPage from '@/layout/components/TabPage/index.vue'
import Announcement from './Announcement.vue'
import Vault from './Vault.vue'
import Vault from './Vault/index.vue'
import Ticket from './Ticket.vue'
import Ops from './Ops.vue'
import Chat from './Chat.vue'
Expand Down

0 comments on commit 4a9a905

Please sign in to comment.