Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 1 | import api from '@/store/api'; |
| 2 | import i18n from '@/i18n'; |
| 3 | |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 4 | const PoliciesStore = { |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 5 | namespaced: true, |
| 6 | state: { |
| 7 | sshProtocolEnabled: false, |
| 8 | ipmiProtocolEnabled: false, |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 9 | rtadEnabled: 'Disabled', |
| 10 | vtpmEnabled: 'Disabled', |
kirankumarb07 | 2dabfc1 | 2023-03-29 11:19:31 +0530 | [diff] [blame] | 11 | sessionTimeoutValue: null, |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 12 | }, |
| 13 | getters: { |
| 14 | sshProtocolEnabled: (state) => state.sshProtocolEnabled, |
| 15 | ipmiProtocolEnabled: (state) => state.ipmiProtocolEnabled, |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 16 | rtadEnabled: (state) => state.rtadEnabled, |
| 17 | vtpmEnabled: (state) => state.vtpmEnabled, |
kirankumarb07 | 2dabfc1 | 2023-03-29 11:19:31 +0530 | [diff] [blame] | 18 | getSessionTimeoutValue: (state) => state.sessionTimeoutValue, |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 19 | }, |
| 20 | mutations: { |
| 21 | setSshProtocolEnabled: (state, sshProtocolEnabled) => |
| 22 | (state.sshProtocolEnabled = sshProtocolEnabled), |
| 23 | setIpmiProtocolEnabled: (state, ipmiProtocolEnabled) => |
| 24 | (state.ipmiProtocolEnabled = ipmiProtocolEnabled), |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 25 | setRtadEnabled: (state, rtadEnabled) => (state.rtadEnabled = rtadEnabled), |
| 26 | setVtpmEnabled: (state, vtpmEnabled) => (state.vtpmEnabled = vtpmEnabled), |
kirankumarb07 | 2dabfc1 | 2023-03-29 11:19:31 +0530 | [diff] [blame] | 27 | setSessionTimeoutValue(state, sessionTimeoutValue) { |
| 28 | state.sessionTimeoutValue = sessionTimeoutValue; |
| 29 | }, |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 30 | }, |
| 31 | actions: { |
| 32 | async getNetworkProtocolStatus({ commit }) { |
| 33 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame^] | 34 | .get(`${await this.dispatch('global/getBmcPath')}/NetworkProtocol`) |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 35 | .then((response) => { |
| 36 | const sshProtocol = response.data.SSH.ProtocolEnabled; |
| 37 | const ipmiProtocol = response.data.IPMI.ProtocolEnabled; |
| 38 | commit('setSshProtocolEnabled', sshProtocol); |
| 39 | commit('setIpmiProtocolEnabled', ipmiProtocol); |
| 40 | }) |
| 41 | .catch((error) => console.log(error)); |
| 42 | }, |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 43 | async getBiosStatus({ commit }) { |
| 44 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame^] | 45 | .get(`${await this.dispatch('global/getSystemPath')}/Bios`) |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 46 | .then((response) => { |
| 47 | commit('setRtadEnabled', response.data.Attributes.pvm_rtad); |
| 48 | commit('setVtpmEnabled', response.data.Attributes.pvm_vtpm); |
| 49 | }) |
| 50 | .catch((error) => console.log(error)); |
| 51 | }, |
kirankumarb07 | 2dabfc1 | 2023-03-29 11:19:31 +0530 | [diff] [blame] | 52 | async getSessionTimeout({ commit }) { |
| 53 | return await api |
| 54 | .get('/redfish/v1/SessionService') |
| 55 | .then((response) => { |
| 56 | const sessionTimeoutValue = response.data.SessionTimeout; |
| 57 | commit('setSessionTimeoutValue', sessionTimeoutValue); |
| 58 | }) |
| 59 | .catch((error) => console.log(error)); |
| 60 | }, |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 61 | async saveIpmiProtocolState({ commit }, protocolEnabled) { |
| 62 | commit('setIpmiProtocolEnabled', protocolEnabled); |
| 63 | const ipmi = { |
| 64 | IPMI: { |
| 65 | ProtocolEnabled: protocolEnabled, |
| 66 | }, |
| 67 | }; |
| 68 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame^] | 69 | .patch( |
| 70 | `${await this.dispatch('global/getBmcPath')}/NetworkProtocol`, |
| 71 | ipmi, |
| 72 | ) |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 73 | .then(() => { |
| 74 | if (protocolEnabled) { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 75 | return i18n.t('pagePolicies.toast.successIpmiEnabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 76 | } else { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 77 | return i18n.t('pagePolicies.toast.successIpmiDisabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 78 | } |
| 79 | }) |
| 80 | .catch((error) => { |
| 81 | console.log(error); |
| 82 | commit('setIpmiProtocolEnabled', !protocolEnabled); |
| 83 | if (protocolEnabled) { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 84 | throw new Error(i18n.t('pagePolicies.toast.errorIpmiEnabled')); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 85 | } else { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 86 | throw new Error(i18n.t('pagePolicies.toast.errorIpmiDisabled')); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 87 | } |
| 88 | }); |
| 89 | }, |
| 90 | async saveSshProtocolState({ commit }, protocolEnabled) { |
| 91 | commit('setSshProtocolEnabled', protocolEnabled); |
| 92 | const ssh = { |
| 93 | SSH: { |
| 94 | ProtocolEnabled: protocolEnabled, |
| 95 | }, |
| 96 | }; |
| 97 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame^] | 98 | .patch( |
| 99 | `${await this.dispatch('global/getBmcPath')}/NetworkProtocol`, |
| 100 | ssh, |
| 101 | ) |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 102 | .then(() => { |
| 103 | if (protocolEnabled) { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 104 | return i18n.t('pagePolicies.toast.successSshEnabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 105 | } else { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 106 | return i18n.t('pagePolicies.toast.successSshDisabled'); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 107 | } |
| 108 | }) |
| 109 | .catch((error) => { |
| 110 | console.log(error); |
| 111 | commit('setSshProtocolEnabled', !protocolEnabled); |
| 112 | if (protocolEnabled) { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 113 | throw new Error(i18n.t('pagePolicies.toast.errorSshEnabled')); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 114 | } else { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 115 | throw new Error(i18n.t('pagePolicies.toast.errorSshDisabled')); |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 116 | } |
| 117 | }); |
| 118 | }, |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 119 | async saveRtadState({ commit }, updatedRtad) { |
| 120 | commit('setRtadEnabled', updatedRtad); |
| 121 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame^] | 122 | .patch(`${await this.dispatch('global/getSystemPath')}/Bios/Settings`, { |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 123 | Attributes: { |
| 124 | pvm_rtad: updatedRtad, |
| 125 | }, |
| 126 | }) |
| 127 | .then(() => { |
| 128 | if (updatedRtad === 'Enabled') { |
| 129 | return i18n.t('pagePolicies.toast.successRtadEnabled'); |
| 130 | } else { |
| 131 | return i18n.t('pagePolicies.toast.successRtadDisabled'); |
| 132 | } |
| 133 | }) |
| 134 | .catch((error) => { |
| 135 | console.log(error); |
| 136 | if (updatedRtad === 'Enabled') { |
| 137 | throw new Error(i18n.t('pagePolicies.toast.errorRtadEnabled')); |
| 138 | } else { |
| 139 | throw new Error(i18n.t('pagePolicies.toast.errorRtadDisabled')); |
| 140 | } |
| 141 | }); |
| 142 | }, |
| 143 | async saveVtpmState({ commit }, updatedVtpm) { |
| 144 | commit('setVtpmEnabled', updatedVtpm); |
| 145 | return await api |
Sean Zhang | 8841b7d | 2024-06-15 08:42:41 +0300 | [diff] [blame^] | 146 | .patch(`${await this.dispatch('global/getSystemPath')}/Bios/Settings`, { |
Nikhil Ashoka | aee2714 | 2022-01-27 19:10:31 +0530 | [diff] [blame] | 147 | Attributes: { |
| 148 | pvm_vtpm: updatedVtpm, |
| 149 | }, |
| 150 | }) |
| 151 | .then(() => { |
| 152 | if (updatedVtpm === 'Enabled') { |
| 153 | return i18n.t('pagePolicies.toast.successVtpmEnabled'); |
| 154 | } else { |
| 155 | return i18n.t('pagePolicies.toast.successVtpmDisabled'); |
| 156 | } |
| 157 | }) |
| 158 | .catch((error) => { |
| 159 | console.log(error); |
| 160 | if (updatedVtpm === 'Enabled') { |
| 161 | throw new Error(i18n.t('pagePolicies.toast.errorVtpmEnabled')); |
| 162 | } else { |
| 163 | throw new Error(i18n.t('pagePolicies.toast.errorVtpmDisabled')); |
| 164 | } |
| 165 | }); |
| 166 | }, |
kirankumarb07 | 2dabfc1 | 2023-03-29 11:19:31 +0530 | [diff] [blame] | 167 | async saveSessionTimeoutValue({ dispatch }, sessionTimeoutNewValue) { |
| 168 | const sessionValue = { |
| 169 | SessionTimeout: sessionTimeoutNewValue, |
| 170 | }; |
| 171 | return await api |
| 172 | .patch('/redfish/v1/SessionService', sessionValue) |
| 173 | .then(() => dispatch('getSessionTimeout')) |
| 174 | .then(() => { |
| 175 | return i18n.t('pagePolicies.toast.successSessionTimeout'); |
| 176 | }) |
| 177 | .catch((error) => { |
| 178 | console.log(error); |
| 179 | throw new Error(i18n.t('pagePolicies.toast.errorSessionTimeout')); |
| 180 | }); |
| 181 | }, |
Dixsie Wolmers | 8f030ba | 2020-12-07 13:12:53 -0600 | [diff] [blame] | 182 | }, |
| 183 | }; |
| 184 | |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 185 | export default PoliciesStore; |