diff --git a/dashboard/src/models/VolumesModel.js b/dashboard/src/models/VolumesModel.js index bf0722422..64b9e9e76 100644 --- a/dashboard/src/models/VolumesModel.js +++ b/dashboard/src/models/VolumesModel.js @@ -2,6 +2,47 @@ import { fetcher } from 'pankow'; import { API_ORIGIN } from '../constants.js'; +const mountTypes = [ + { name: 'CIFS', value: 'cifs' }, + { name: 'EXT4', value: 'ext4' }, + { name: 'Filesystem', value: 'filesystem' }, + { name: 'Filesystem (Mountpoint)', value: 'mountpoint' }, + { name: 'NFS', value: 'nfs' }, + { name: 'SSHFS', value: 'sshfs' }, + { name: 'XFS', value: 'xfs' }, +]; + +function filterConfigForMountType(mountType, config) { + let props = []; + switch (mountType) { + case 'filesystem': + props = ['hostPath']; + break; + case 'mountpoint': + props = ['hostPath']; + break; + case 'ext4': + props = ['diskPath']; + break; + case 'xfs': + props = ['diskPath']; + break; + case 'cifs': + props = ['host', 'seal', 'remoteDir', 'username', 'password']; + break; + case 'nfs': + props = ['host', 'remoteDir']; + break; + case 'sshfs': + props = ['host', 'port', 'remoteDir', 'user', 'privateKey']; + break; + } + + const ret = {}; + for (const p of props) ret[p] = config[p]; + return ret; +} + function create() { const accessToken = localStorage.token; @@ -46,17 +87,17 @@ function create() { async add(name, mountType, mountOptions) { let error, result; try { - result = await fetcher.post(`${API_ORIGIN}/api/v1/volumes`, { name, mountType, mountOptions }, { access_token: accessToken }); + result = await fetcher.post(`${API_ORIGIN}/api/v1/volumes`, { name, mountType, mountOptions: filterConfigForMountType(mountType, mountOptions) }, { access_token: accessToken }); } catch (e) { error = e; } if (error || result.status !== 201) throw error || result; }, - async update(id, mountOptions) { + async update(id, mountType, mountOptions) { let error, result; try { - result = await fetcher.post(`${API_ORIGIN}/api/v1/volumes/${id}`, { mountOptions }, { access_token: accessToken }); + result = await fetcher.post(`${API_ORIGIN}/api/v1/volumes/${id}`, { mountOptions: filterConfigForMountType(mountType, mountOptions) }, { access_token: accessToken }); } catch (e) { error = e; } @@ -92,5 +133,6 @@ function create() { } export default { - create + create, + mountTypes, }; diff --git a/dashboard/src/views/VolumesView.vue b/dashboard/src/views/VolumesView.vue index afd4378bc..f4590c19e 100644 --- a/dashboard/src/views/VolumesView.vue +++ b/dashboard/src/views/VolumesView.vue @@ -12,16 +12,6 @@ import VolumesModel from '../models/VolumesModel.js'; const volumesModel = VolumesModel.create(); -const mountTypeOptions = [ - { name: 'CIFS', value: 'cifs' }, - { name: 'EXT4', value: 'ext4' }, - { name: 'Filesystem', value: 'filesystem' }, - { name: 'Filesystem (Mountpoint)', value: 'mountpoint' }, - { name: 'NFS', value: 'nfs' }, - { name: 'SSHFS', value: 'sshfs' }, - { name: 'XFS', value: 'xfs' }, -]; - const columns = { status: {}, name: { @@ -161,7 +151,7 @@ async function submitVolumeDialog() { if (volumeDialogData.value.mode === 'new') { await volumesModel.add(volumeDialogData.value.name, volumeDialogData.value.mountType, mountOptions); } else { - await volumesModel.update(volumeDialogData.value.id, mountOptions); + await volumesModel.update(volumeDialogData.value.id, volumeDialogData.value.mountType, mountOptions); } } catch (error) { volumeDialogData.value.error = error.body ? error.body.message : 'Internal error'; @@ -223,7 +213,7 @@ onMounted(async () =>{