mirror of
https://github.com/harvester/harvester-ui-extension.git
synced 2026-10-06 14:16:05 +08:00
Add volume and image encryption feature
Signed-off-by: andy.lee <andy.lee@suse.com>
This commit is contained in:
@@ -8,7 +8,6 @@ import NameNsDescription from '@shell/components/form/NameNsDescription';
|
||||
import { RadioGroup } from '@components/Form/Radio';
|
||||
import Select from '@shell/components/form/Select';
|
||||
import LabeledSelect from '@shell/components/form/LabeledSelect';
|
||||
|
||||
import CreateEditView from '@shell/mixins/create-edit-view';
|
||||
import { HCI as HCI_ANNOTATIONS } from '@pkg/harvester/config/labels-annotations';
|
||||
import { exceptionToErrorsArray } from '@shell/utils/error';
|
||||
@@ -18,6 +17,9 @@ import { VM_IMAGE_FILE_FORMAT } from '../validators/vm-image';
|
||||
import { OS } from '../mixins/harvester-vm';
|
||||
import { HCI } from '../types';
|
||||
|
||||
const ENCRYPT = 'encrypt';
|
||||
const DECRYPT = 'decrypt';
|
||||
const CLONE = 'clone';
|
||||
const DOWNLOAD = 'download';
|
||||
const UPLOAD = 'upload';
|
||||
const rawORqcow2 = 'raw_qcow2';
|
||||
@@ -59,6 +61,8 @@ export default {
|
||||
const defaultStorage = this.$store.getters[`${ inStore }/all`](STORAGE_CLASS).find(s => s.isDefault);
|
||||
|
||||
this['storageClassName'] = this.storageClassName || defaultStorage?.metadata?.name || 'longhorn';
|
||||
this.images = this.$store.getters[`${ inStore }/all`](HCI.IMAGE);
|
||||
this.selectedImage = this.images.find(i => i.name === this.value.name) || null;
|
||||
},
|
||||
|
||||
data() {
|
||||
@@ -71,12 +75,14 @@ export default {
|
||||
}
|
||||
|
||||
return {
|
||||
url: this.value.spec.url,
|
||||
files: [],
|
||||
resource: '',
|
||||
headers: {},
|
||||
fileUrl: '',
|
||||
file: '',
|
||||
selectedImage: null,
|
||||
images: [],
|
||||
url: this.value.spec.url,
|
||||
files: [],
|
||||
resource: '',
|
||||
headers: {},
|
||||
fileUrl: '',
|
||||
file: '',
|
||||
};
|
||||
},
|
||||
|
||||
@@ -94,9 +100,16 @@ export default {
|
||||
},
|
||||
|
||||
showEditAsYaml() {
|
||||
return this.value.spec.sourceType === DOWNLOAD;
|
||||
return this.value.spec.sourceType === DOWNLOAD || this.value.spec.sourceType === CLONE;
|
||||
},
|
||||
radioGroupOptions() {
|
||||
return [
|
||||
DOWNLOAD,
|
||||
UPLOAD,
|
||||
ENCRYPT,
|
||||
DECRYPT
|
||||
];
|
||||
},
|
||||
|
||||
storageClassOptions() {
|
||||
const inStore = this.$store.getters['currentProduct'].inStore;
|
||||
const storages = this.$store.getters[`${ inStore }/all`](STORAGE_CLASS);
|
||||
@@ -122,9 +135,66 @@ export default {
|
||||
this.value.metadata.annotations[HCI_ANNOTATIONS.STORAGE_CLASS] = nue;
|
||||
}
|
||||
},
|
||||
sourceImageOptions() {
|
||||
let options = [];
|
||||
|
||||
if (this.value.spec.sourceType !== CLONE) {
|
||||
return options;
|
||||
}
|
||||
if (this.value.spec.securityParameters.cryptoOperation === ENCRYPT) {
|
||||
options = this.images.filter(image => !image.isEncrypted);
|
||||
} else {
|
||||
options = this.images.filter(image => image.isEncrypted);
|
||||
}
|
||||
|
||||
return options.map(image => image.spec.displayName);
|
||||
},
|
||||
sourceImageName: {
|
||||
get() {
|
||||
return this.selectedImage?.spec.displayName;
|
||||
},
|
||||
set(imageDisplayName) {
|
||||
this.selectedImage = this.images.find(i => i.spec.displayName === imageDisplayName);
|
||||
// sourceImageName should bring the name of the image
|
||||
this.value.spec.securityParameters.sourceImageName = this.selectedImage?.metadata.name || '';
|
||||
}
|
||||
},
|
||||
sourceType: {
|
||||
get() {
|
||||
if (this.value.spec.sourceType === CLONE) {
|
||||
return this.value.spec.securityParameters.cryptoOperation;
|
||||
} else {
|
||||
return this.value.spec.sourceType;
|
||||
}
|
||||
},
|
||||
|
||||
set(neu) {
|
||||
if (neu === DECRYPT || neu === ENCRYPT) {
|
||||
this.value.spec.sourceType = CLONE;
|
||||
this.$set(this.value.spec, 'securityParameters', {
|
||||
cryptoOperation: neu,
|
||||
sourceImageName: '',
|
||||
sourceImageNamespace: this.value.metadata.namespace
|
||||
});
|
||||
this.selectedImage = null;
|
||||
} else {
|
||||
this.$delete(this.value.spec, 'securityParameters');
|
||||
this.value.spec.sourceType = neu;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
'value.metadata.namespace'(neu) {
|
||||
if (this.value.spec.sourceType === CLONE) {
|
||||
this.$set(this.value.spec, 'securityParameters', {
|
||||
cryptoOperation: this.value.spec.securityParameters.cryptoOperation,
|
||||
sourceImageName: '',
|
||||
sourceImageNamespace: neu
|
||||
});
|
||||
}
|
||||
},
|
||||
'value.spec.url'(neu) {
|
||||
const url = neu.trim();
|
||||
|
||||
@@ -300,15 +370,14 @@ export default {
|
||||
>
|
||||
<RadioGroup
|
||||
v-if="isCreate"
|
||||
v-model:value="value.spec.sourceType"
|
||||
v-model:value="sourceType"
|
||||
name="model"
|
||||
:options="[
|
||||
'download',
|
||||
'upload',
|
||||
]"
|
||||
:options="radioGroupOptions"
|
||||
:labels="[
|
||||
t('harvester.image.sourceType.download'),
|
||||
t('harvester.image.sourceType.upload'),
|
||||
t('harvester.image.sourceType.encrypt'),
|
||||
t('harvester.image.sourceType.decrypt'),
|
||||
]"
|
||||
:mode="mode"
|
||||
/>
|
||||
@@ -334,7 +403,7 @@ export default {
|
||||
:tooltip="t('harvester.image.urlTip', {}, true)"
|
||||
/>
|
||||
|
||||
<div v-else>
|
||||
<div v-else-if="value.spec.sourceType === 'upload'">
|
||||
<LabeledInput
|
||||
v-if="isView"
|
||||
v-model:value="imageName"
|
||||
@@ -379,6 +448,16 @@ export default {
|
||||
label-key="harvester.image.checksum"
|
||||
:tooltip="t('harvester.image.checksumTip')"
|
||||
/>
|
||||
|
||||
<LabeledSelect
|
||||
v-if="value.spec.sourceType === 'clone'"
|
||||
v-model="sourceImageName"
|
||||
:options="sourceImageOptions"
|
||||
:label="t('harvester.image.sourceImage')"
|
||||
:mode="mode"
|
||||
:disabled="isEdit"
|
||||
class="mb-20"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Tab>
|
||||
|
||||
Reference in New Issue
Block a user