Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 1 | import api from '@/store/api'; |
| 2 | import i18n from '@/i18n'; |
| 3 | |
| 4 | const SecuritySettingsStore = { |
| 5 | namespaced: true, |
| 6 | state: { |
| 7 | sshProtocolEnabled: false, |
| 8 | ipmiProtocolEnabled: false, |
| 9 | }, |
| 10 | getters: { |
| 11 | sshProtocolEnabled: (state) => state.sshProtocolEnabled, |
| 12 | ipmiProtocolEnabled: (state) => state.ipmiProtocolEnabled, |
| 13 | }, |
| 14 | mutations: { |
| 15 | setSshProtocolEnabled: (state, sshProtocolEnabled) => |
| 16 | (state.sshProtocolEnabled = sshProtocolEnabled), |
| 17 | setIpmiProtocolEnabled: (state, ipmiProtocolEnabled) => |
| 18 | (state.ipmiProtocolEnabled = ipmiProtocolEnabled), |
| 19 | }, |
| 20 | actions: { |
| 21 | async getNetworkProtocolStatus({ commit }) { |
| 22 | return await api |
| 23 | .get('/redfish/v1/Managers/bmc/NetworkProtocol') |
| 24 | .then((response) => { |
| 25 | const sshProtocol = response.data.SSH.ProtocolEnabled; |
| 26 | const ipmiProtocol = response.data.IPMI.ProtocolEnabled; |
| 27 | commit('setSshProtocolEnabled', sshProtocol); |
| 28 | commit('setIpmiProtocolEnabled', ipmiProtocol); |
| 29 | }) |
| 30 | .catch((error) => console.log(error)); |
| 31 | }, |
| 32 | async saveIpmiProtocolState({ commit }, protocolEnabled) { |
| 33 | commit('setIpmiProtocolEnabled', protocolEnabled); |
| 34 | const ipmi = { |
| 35 | IPMI: { |
| 36 | ProtocolEnabled: protocolEnabled, |
| 37 | }, |
| 38 | }; |
| 39 | return await api |
| 40 | .patch('/redfish/v1/Managers/bmc/NetworkProtocol', ipmi) |
| 41 | .then(() => { |
| 42 | if (protocolEnabled) { |
| 43 | return i18n.t('pageSecuritySettings.toast.successIpmiEnabled'); |
| 44 | } else { |
| 45 | return i18n.t('pageSecuritySettings.toast.successIpmiDisabled'); |
| 46 | } |
| 47 | }) |
| 48 | .catch((error) => { |
| 49 | console.log(error); |
| 50 | commit('setIpmiProtocolEnabled', !protocolEnabled); |
| 51 | if (protocolEnabled) { |
| 52 | throw new Error( |
| 53 | i18n.t('pageSecuritySettings.toast.errorIpmiEnabled') |
| 54 | ); |
| 55 | } else { |
| 56 | throw new Error( |
| 57 | i18n.t('pageSecuritySettings.toast.errorIpmiDisabled') |
| 58 | ); |
| 59 | } |
| 60 | }); |
| 61 | }, |
| 62 | async saveSshProtocolState({ commit }, protocolEnabled) { |
| 63 | commit('setSshProtocolEnabled', protocolEnabled); |
| 64 | const ssh = { |
| 65 | SSH: { |
| 66 | ProtocolEnabled: protocolEnabled, |
| 67 | }, |
| 68 | }; |
| 69 | return await api |
| 70 | .patch('/redfish/v1/Managers/bmc/NetworkProtocol', ssh) |
| 71 | .then(() => { |
| 72 | if (protocolEnabled) { |
| 73 | return i18n.t('pageSecuritySettings.toast.successSshEnabled'); |
| 74 | } else { |
| 75 | return i18n.t('pageSecuritySettings.toast.successSshDisabled'); |
| 76 | } |
| 77 | }) |
| 78 | .catch((error) => { |
| 79 | console.log(error); |
| 80 | commit('setSshProtocolEnabled', !protocolEnabled); |
| 81 | if (protocolEnabled) { |
| 82 | throw new Error( |
| 83 | i18n.t('pageSecuritySettings.toast.errorSshEnabled') |
| 84 | ); |
| 85 | } else { |
| 86 | throw new Error( |
| 87 | i18n.t('pageSecuritySettings.toast.errorSshDisabled') |
| 88 | ); |
| 89 | } |
| 90 | }); |
| 91 | }, |
| 92 | }, |
| 93 | }; |
| 94 | |
| 95 | export default SecuritySettingsStore; |