| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280 |
- <template>
- <div>
- <a-form-item v-if="!inDialog" :label="$t('compute.bastionHost.bastion_host')">
- <a-tooltip
- :title="switchDisabled ? $t('compute.bastionHost.bastion_host.switch_disabled') : null">
- <a-switch
- v-decorator="decorator.bastion_host_enable"
- :checkedChildren="$t('compute.text_115')"
- :unCheckedChildren="$t('compute.text_116')"
- :disabled="switchDisabled"
- @change="changeHandle" />
- </a-tooltip>
- </a-form-item>
- <template v-if="inDialog || bastionHostEnable">
- <a-form-item class="mt-2" :label="inDialog ? $t('compute.bastionHost.bastion_host') : $t('compute.bastionHost.add_bastion_host')">
- <base-select
- v-decorator="decorator.bastion_host_id"
- :options="bastionHosts"
- :filterable="true"
- :select-props="{
- placeholder: $t('compute.bastionHost.bastion_host.placeholder'),
- loading: bastionHostLoading
- }"
- @change="bastionHostChangeHandle" />
- </a-form-item>
- <a-form-item class="mt-2" :label="$t('compute.bastion_host_org')">
- <base-select
- v-decorator="decorator.bastion_org_id"
- :options="orgs"
- :filterable="true"
- :select-props="{
- placeholder: $t('compute.bastionHost.bastion_host.placeholder'),
- loading: orgLoading
- }"
- @change="bastionOrgChangeHandle" />
- </a-form-item>
- <a-form-item class="mt-2" :label="$t('compute.bastionHost.node')">
- <base-select
- v-decorator="decorator.nodes"
- :options="nodes"
- :filterable="true"
- :select-props="{
- placeholder: $t('compute.bastionHost.node.placeholder'),
- allowClear: true,
- mode: 'multiple',
- loading: nodeLoading
- }" />
- </a-form-item>
- <a-form-item class="mt-2" :label="$t('compute.bastionHost.port')">
- <a-input-number
- v-decorator="decorator.port"
- :placeholder="$t('compute.bastionHost.port.placeholder')" />
- </a-form-item>
- <a-form-item class="mt-2" :label="$t('compute.bastionHost.privileged_account')">
- <base-select
- v-decorator="decorator.privileged_accounts"
- :options="privilegedAccounts"
- :filterable="true"
- :select-props="{
- placeholder: $t('compute.bastionHost.privileged_account.placeholder'),
- allowClear: true,
- loading: accountLoading
- }" />
- </a-form-item>
- <a-form-item class="mt-2" :label="$t('compute.bastionHost.account')">
- <base-select
- v-decorator="decorator.accounts"
- :options="accounts"
- :filterable="true"
- :select-props="{
- placeholder: $t('compute.bastionHost.account.placeholder'),
- allowClear: true,
- mode: 'multiple',
- loading: accountLoading
- }" />
- </a-form-item>
- <a-form-item class="mt-2" :label="$t('compute.bastionHost.domain')">
- <base-select
- v-decorator="decorator.bastion_domain_id"
- :options="domains"
- :filterable="true"
- :select-props="{
- placeholder: $t('common.tips.select', [$t('compute.bastionHost.domain')]),
- allowClear: true,
- loading: domainLoading
- }" />
- </a-form-item>
- </template>
- </div>
- </template>
- <script>
- export default {
- name: 'BastionHost',
- props: {
- form: {
- type: Object,
- required: true,
- validator: val => val.fd && val.fc,
- },
- decorator: {
- type: Object,
- required: true,
- },
- inDialog: {
- type: Boolean,
- default: false,
- },
- },
- data () {
- return {
- bastionHostEnable: false,
- bastionHostLoading: false,
- nodeLoading: false,
- accountLoading: false,
- domainLoading: false,
- orgs: [],
- bastionHosts: [],
- nodes: [],
- privilegedAccounts: [],
- accounts: [],
- domains: [],
- currentBastionHostId: '',
- }
- },
- computed: {
- switchDisabled () {
- return !this.bastionHosts.length
- },
- },
- watch: {
- bastionHostEnable (v) {
- if (v) {
- this.fetchBastionHosts()
- }
- },
- },
- created () {
- if (this.$appConfig.isPrivate && !this.$store.getters.isSysCE) {
- this.fetchBastionHosts()
- }
- },
- methods: {
- initData (data) {
- this.bastionHostEnable = true
- this.currentBastionHostId = data.bastion_host_id
- this.fetchOrgs(data.bastion_host_id, data.bastion_org_id)
- this.fetchNodes(data.bastion_org_id, data.nodes)
- this.fetchAllAccounts(data.bastion_org_id, data.accounts)
- this.fetchDomains(data.bastion_org_id, data.bastion_domain_id)
- },
- changeHandle (v) {
- this.bastionHostEnable = v
- },
- bastionHostChangeHandle (v) {
- this.currentBastionHostId = v
- this.fetchOrgs(v)
- },
- bastionOrgChangeHandle (v) {
- if (this.currentBastionHostId) {
- this.fetchNodes(v)
- this.fetchAllAccounts(v)
- this.fetchDomains(v)
- } else {
- this.nodes = []
- this.accounts = []
- this.domains = []
- }
- },
- async fetchOrgs (bastionHostId, defaultOrgId) {
- try {
- this.orgLoading = true
- this.orgs = []
- const { data: { orgs = [] } } = await new this.$Manager('bastion_hosts')
- .getSpecific({ id: bastionHostId, spec: 'bastion-orgs' })
- this.orgs = orgs.map(o => {
- return {
- key: o.id,
- label: o.name,
- }
- })
- this.form.fc.setFieldsValue({
- bastion_org_id: defaultOrgId,
- })
- } catch (error) {
- throw error
- } finally {
- this.orgLoading = false
- }
- },
- async fetchBastionHosts () {
- try {
- this.bastionHostLoading = true
- this.bastionHosts = []
- const { data: { data = [] } } = await new this.$Manager('bastion_hosts').list({})
- this.bastionHosts = data
- } catch (error) {
- throw error
- } finally {
- this.bastionHostLoading = false
- }
- },
- async fetchNodes (bastionOrgId, defaultNodes) {
- try {
- this.nodeLoading = true
- this.nodes = []
- const { data: { nodes = [] } } = await new this.$Manager('bastion_hosts')
- .getSpecific({ id: this.currentBastionHostId, spec: 'nodes', params: { bastion_org_id: bastionOrgId } })
- this.nodes = nodes.map(o => {
- return {
- key: o.id,
- label: o.name,
- }
- })
- this.form.fc.setFieldsValue({
- nodes: defaultNodes,
- })
- } catch (error) {
- throw error
- } finally {
- this.nodeLoading = false
- }
- },
- async fetchAllAccounts (bastionOrgId, defaultAccounts = []) {
- try {
- this.accountLoading = true
- this.accounts = []
- this.privilegedAccounts = []
- const { data: { account_templates = [] } } = await new this.$Manager('bastion_hosts')
- .getSpecific({ id: this.currentBastionHostId, spec: 'account-templates', params: { bastion_org_id: bastionOrgId } })
- this.accounts = account_templates.filter(o => !o.privileged).map(o => {
- return {
- key: o.id,
- label: o.name,
- }
- })
- this.privilegedAccounts = account_templates.filter(o => o.privileged).map(o => {
- return {
- key: o.id,
- label: o.name,
- }
- })
- const privilegedAccounts = defaultAccounts.length ? defaultAccounts[0] : []
- const accounts = defaultAccounts.filter((_, index) => index !== 0)
- this.form.fc.setFieldsValue({
- accounts,
- privileged_accounts: privilegedAccounts,
- })
- } catch (error) {
- throw error
- } finally {
- this.accountLoading = false
- }
- },
- async fetchDomains (bastionOrgId, defaultDomainId) {
- try {
- this.domainLoading = true
- this.domains = []
- const { data: { domains = [] } } = await new this.$Manager('bastion_hosts')
- .getSpecific({ id: this.currentBastionHostId, spec: 'bastion-domains', params: { bastion_org_id: bastionOrgId } })
- this.domains = domains.map(o => {
- return {
- key: o.id,
- label: o.name,
- }
- })
- this.form.fc.setFieldsValue({
- bastion_domain_id: defaultDomainId,
- })
- } catch (error) {
- throw error
- } finally {
- this.domainLoading = false
- }
- },
- },
- }
- </script>
- <style></style>
|