diff options
Diffstat (limited to 'src/store/modules')
21 files changed, 376 insertions, 168 deletions
diff --git a/src/store/modules/Authentication/AuthenticanStore.js b/src/store/modules/Authentication/AuthenticanStore.js index 2006661b..3ad41c6b 100644 --- a/src/store/modules/Authentication/AuthenticanStore.js +++ b/src/store/modules/Authentication/AuthenticanStore.js @@ -10,21 +10,28 @@ const AuthenticationStore = { authError: false, xsrfCookie: Cookies.get('XSRF-TOKEN'), isAuthenticatedCookie: Cookies.get('IsAuthenticated'), + sessionURI: localStorage.getItem('sessionURI'), }, getters: { consoleWindow: (state) => state.consoleWindow, authError: (state) => state.authError, isLoggedIn: (state) => { + // We might have gotten XSRF-TOKEN (and HttpOnly SESSION cookie) by Mutual TLS authentication, + // without going through explicit Session creation return ( state.xsrfCookie !== undefined || state.isAuthenticatedCookie == 'true' ); }, + // Used to authenticate WebSocket connections via subprotocol value token: (state) => state.xsrfCookie, }, mutations: { - authSuccess(state) { + authSuccess(state, { session }) { state.authError = false; state.xsrfCookie = Cookies.get('XSRF-TOKEN'); + // Preserve session data across page reloads and browser restarts + localStorage.setItem('sessionURI', session); + state.sessionURI = session; }, authError(state, authError = true) { state.authError = authError; @@ -35,30 +42,33 @@ const AuthenticationStore = { localStorage.removeItem('storedUsername'); state.xsrfCookie = undefined; state.isAuthenticatedCookie = undefined; + localStorage.removeItem('sessionURI'); + state.sessionURI = null; + state.consoleWindow = false; }, - setConsoleWindow: (state, window) => (state.consoleWindow = window), }, actions: { login({ commit }, { username, password }) { commit('authError', false); return api - .post('/login', { - username: username, - password: password, + .post('/redfish/v1/SessionService/Sessions', { + UserName: username, + Password: password, + }) + .then((response) => { + commit('authSuccess', { + session: response.headers['location'], + }); }) - .then(() => commit('authSuccess')) .catch((error) => { commit('authError'); throw new Error(error); }); }, - logout({ commit }) { + logout({ commit, state }) { api - .post('/logout', { data: [] }) - .then(() => { - commit('setConsoleWindow', false); - commit('logout'); - }) + .delete(state.sessionURI) + .then(() => commit('logout')) .then(() => router.push('/login')) .catch((error) => console.log(error)); }, diff --git a/src/store/modules/GlobalStore.js b/src/store/modules/GlobalStore.js index 036dc481..10d50b1a 100644 --- a/src/store/modules/GlobalStore.js +++ b/src/store/modules/GlobalStore.js @@ -77,9 +77,29 @@ const GlobalStore = { }, }, actions: { + async getBmcPath() { + const serviceRoot = await api + .get('/redfish/v1') + .catch((error) => console.log(error)); + let bmcPath = serviceRoot.data?.ManagerProvidingService?.['@odata.id']; + if (!bmcPath) { + const managers = await api + .get('/redfish/v1/Managers') + .catch((error) => console.log(error)); + bmcPath = managers.data?.Members?.[0]?.['@odata.id']; + } + return bmcPath; + }, + async getSystemPath() { + const systems = await api + .get('/redfish/v1/Systems') + .catch((error) => console.log(error)); + let systemPath = systems.data?.Members?.[0]?.['@odata.id']; + return systemPath; + }, async getBmcTime({ commit }) { return await api - .get('/redfish/v1/Managers/bmc') + .get(`${await this.dispatch('global/getBmcPath')}`) .then((response) => { const bmcDateTime = response.data.DateTime; const date = new Date(bmcDateTime); @@ -87,9 +107,9 @@ const GlobalStore = { }) .catch((error) => console.log(error)); }, - getSystemInfo({ commit }) { + async getSystemInfo({ commit }) { api - .get('/redfish/v1/Systems/system') + .get(`${await this.dispatch('global/getSystemPath')}`) .then( ({ data: { diff --git a/src/store/modules/HardwareStatus/BmcStore.js b/src/store/modules/HardwareStatus/BmcStore.js index d96926ea..f0e4cf96 100644 --- a/src/store/modules/HardwareStatus/BmcStore.js +++ b/src/store/modules/HardwareStatus/BmcStore.js @@ -47,7 +47,7 @@ const BmcStore = { actions: { async getBmcInfo({ commit }) { return await api - .get('/redfish/v1/Managers/bmc') + .get(`${await this.dispatch('global/getBmcPath')}`) .then(({ data }) => commit('setBmcInfo', data)) .catch((error) => console.log(error)); }, diff --git a/src/store/modules/HardwareStatus/MemoryStore.js b/src/store/modules/HardwareStatus/MemoryStore.js index 787a0502..d9a107d3 100644 --- a/src/store/modules/HardwareStatus/MemoryStore.js +++ b/src/store/modules/HardwareStatus/MemoryStore.js @@ -60,7 +60,7 @@ const MemoryStore = { actions: { async getDimms({ commit }) { return await api - .get('/redfish/v1/Systems/system/Memory') + .get(`${await this.dispatch('global/getSystemPath')}/Memory`) .then(({ data: { Members } }) => { const promises = Members.map((item) => api.get(item['@odata.id'])); return api.all(promises); diff --git a/src/store/modules/HardwareStatus/ProcessorStore.js b/src/store/modules/HardwareStatus/ProcessorStore.js index 49f96208..446fdb9c 100644 --- a/src/store/modules/HardwareStatus/ProcessorStore.js +++ b/src/store/modules/HardwareStatus/ProcessorStore.js @@ -63,7 +63,7 @@ const ProcessorStore = { actions: { async getProcessorsInfo({ commit }) { return await api - .get('/redfish/v1/Systems/system/Processors') + .get(`${await this.dispatch('global/getSystemPath')}/Processors`) .then(({ data: { Members = [] } }) => Members.map((member) => api.get(member['@odata.id'])), ) diff --git a/src/store/modules/HardwareStatus/ServerLedStore.js b/src/store/modules/HardwareStatus/ServerLedStore.js index af228022..d4af0648 100644 --- a/src/store/modules/HardwareStatus/ServerLedStore.js +++ b/src/store/modules/HardwareStatus/ServerLedStore.js @@ -17,7 +17,7 @@ const ServerLedStore = { actions: { async getIndicatorLedActiveState({ commit }) { return await api - .get('/redfish/v1/Systems/system') + .get(`${await this.dispatch('global/getSystemPath')}`) .then((response) => { commit( 'setIndicatorLedActiveState', @@ -29,7 +29,7 @@ const ServerLedStore = { async saveIndicatorLedActiveState({ commit }, payload) { commit('setIndicatorLedActiveState', payload); return await api - .patch('/redfish/v1/Systems/system', { + .patch(`${await this.dispatch('global/getSystemPath')}`, { LocationIndicatorActive: payload, }) .catch((error) => { diff --git a/src/store/modules/HardwareStatus/SystemStore.js b/src/store/modules/HardwareStatus/SystemStore.js index ea519d73..87d2810b 100644 --- a/src/store/modules/HardwareStatus/SystemStore.js +++ b/src/store/modules/HardwareStatus/SystemStore.js @@ -37,16 +37,13 @@ const SystemStore = { actions: { async getSystem({ commit }) { return await api - .get('/redfish/v1') - .then((response) => - api.get(`${response.data.Systems['@odata.id']}/system`), - ) + .get(`${await this.dispatch('global/getSystemPath')}`) .then(({ data }) => commit('setSystemInfo', data)) .catch((error) => console.log(error)); }, async changeIdentifyLedState({ commit }, ledState) { return await api - .patch('/redfish/v1/Systems/system', { + .patch(`${await this.dispatch('global/getSystemPath')}`, { LocationIndicatorActive: ledState, }) .then(() => { diff --git a/src/store/modules/Logs/DumpsStore.js b/src/store/modules/Logs/DumpsStore.js index 328e3164..9391e571 100644 --- a/src/store/modules/Logs/DumpsStore.js +++ b/src/store/modules/Logs/DumpsStore.js @@ -24,9 +24,7 @@ const DumpsStore = { actions: { async getBmcDumpEntries() { return api - .get('/redfish/v1/') - .then((response) => api.get(response.data.Managers['@odata.id'])) - .then((response) => api.get(`${response.data['@odata.id']}/bmc`)) + .get(`${await this.dispatch('global/getBmcPath')}`) .then((response) => api.get(response.data.LogServices['@odata.id'])) .then((response) => api.get(`${response.data['@odata.id']}/Dump`)) .then((response) => api.get(response.data.Entries['@odata.id'])) @@ -34,9 +32,7 @@ const DumpsStore = { }, async getSystemDumpEntries() { return api - .get('/redfish/v1/') - .then((response) => api.get(response.data.Systems['@odata.id'])) - .then((response) => api.get(`${response.data['@odata.id']}/system`)) + .get(`${await this.dispatch('global/getSystemPath')}`) .then((response) => api.get(response.data.LogServices['@odata.id'])) .then((response) => api.get(`${response.data['@odata.id']}/Dump`)) .then((response) => api.get(response.data.Entries['@odata.id'])) @@ -56,7 +52,7 @@ const DumpsStore = { async createBmcDump() { return await api .post( - '/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.CollectDiagnosticData', + `${await this.dispatch('global/getBmcPath')}/LogServices/Dump/Actions/LogService.CollectDiagnosticData`, { DiagnosticDataType: 'Manager', OEMDiagnosticDataType: '', @@ -70,7 +66,7 @@ const DumpsStore = { async createSystemDump() { return await api .post( - '/redfish/v1/Systems/system/LogServices/Dump/Actions/LogService.CollectDiagnosticData', + `${await this.dispatch('global/getSystemPath')}/LogServices/Dump/Actions/LogService.CollectDiagnosticData`, { DiagnosticDataType: 'OEM', OEMDiagnosticDataType: 'System', @@ -123,7 +119,7 @@ const DumpsStore = { const totalDumpCount = state.allDumps.length; return await api .post( - '/redfish/v1/Managers/bmc/LogServices/Dump/Actions/LogService.ClearLog', + `${await this.dispatch('global/getBmcPath')}/LogServices/Dump/Actions/LogService.ClearLog`, ) .then(() => { commit('setAllDumps', []); diff --git a/src/store/modules/Logs/EventLogStore.js b/src/store/modules/Logs/EventLogStore.js index f7b2ead6..f302dffb 100644 --- a/src/store/modules/Logs/EventLogStore.js +++ b/src/store/modules/Logs/EventLogStore.js @@ -42,7 +42,9 @@ const EventLogStore = { actions: { async getEventLogData({ commit }) { return await api - .get('/redfish/v1/Systems/system/LogServices/EventLog/Entries') + .get( + `${await this.dispatch('global/getSystemPath')}/LogServices/EventLog/Entries`, + ) .then(({ data: { Members = [] } = {} }) => { const eventLogs = Members.map((log) => { const { @@ -79,7 +81,7 @@ const EventLogStore = { async deleteAllEventLogs({ dispatch }, data) { return await api .post( - '/redfish/v1/Systems/system/LogServices/EventLog/Actions/LogService.ClearLog', + `${await this.dispatch('global/getSystemPath')}/LogServices/EventLog/Actions/LogService.ClearLog`, ) .then(() => dispatch('getEventLogData')) .then(() => i18n.tc('pageEventLogs.toast.successDelete', data.length)) @@ -218,6 +220,22 @@ const EventLogStore = { throw new Error(i18n.t('pageEventLogs.toast.errorLogStatusUpdate')); }); }, + async downloadEntry(_, uri) { + return await api + .get(uri) + .then((response) => { + const blob = new Blob([response.data], { + type: response.headers['content-type'], + }); + return blob; + }) + .catch((error) => { + console.log(error); + throw new Error( + i18n.t('pageEventLogs.toast.errorDownloadEventEntry'), + ); + }); + }, }, }; diff --git a/src/store/modules/Logs/PostCodeLogsStore.js b/src/store/modules/Logs/PostCodeLogsStore.js index 7648b13c..7bd1410f 100644 --- a/src/store/modules/Logs/PostCodeLogsStore.js +++ b/src/store/modules/Logs/PostCodeLogsStore.js @@ -16,7 +16,9 @@ const PostCodeLogsStore = { actions: { async getPostCodesLogData({ commit }) { return await api - .get('/redfish/v1/Systems/system/LogServices/PostCodes/Entries') + .get( + `${await this.dispatch('global/getSystemPath')}/LogServices/PostCodes/Entries`, + ) .then(({ data: { Members = [] } = {} }) => { const postCodeLogs = Members.map((log) => { const { Created, MessageArgs, AdditionalDataURI } = log; @@ -37,7 +39,7 @@ const PostCodeLogsStore = { async deleteAllPostCodeLogs({ dispatch }, data) { return await api .post( - '/redfish/v1/Systems/system/LogServices/PostCodes/Actions/LogService.ClearLog', + `${await this.dispatch('global/getSystemPath')}/LogServices/PostCodes/Actions/LogService.ClearLog`, ) .then(() => dispatch('getPostCodesLogData')) .then(() => diff --git a/src/store/modules/Operations/BootSettingsStore.js b/src/store/modules/Operations/BootSettingsStore.js index 1f5a628f..89598456 100644 --- a/src/store/modules/Operations/BootSettingsStore.js +++ b/src/store/modules/Operations/BootSettingsStore.js @@ -32,7 +32,7 @@ const BootSettingsStore = { actions: { async getBootSettings({ commit }) { return await api - .get('/redfish/v1/Systems/system') + .get(`${await this.dispatch('global/getSystemPath')}`) .then(({ data: { Boot } }) => { commit( 'setBootSourceOptions', @@ -43,7 +43,10 @@ const BootSettingsStore = { }) .catch((error) => console.log(error)); }, - saveBootSettings({ commit, dispatch }, { bootSource, overrideEnabled }) { + async saveBootSettings( + { commit, dispatch }, + { bootSource, overrideEnabled }, + ) { const data = { Boot: {} }; data.Boot.BootSourceOverrideTarget = bootSource; @@ -56,7 +59,7 @@ const BootSettingsStore = { } return api - .patch('/redfish/v1/Systems/system', data) + .patch(`${await this.dispatch('global/getSystemPath')}`, data) .then((response) => { // If request success, commit the values commit('setBootSource', data.Boot.BootSourceOverrideTarget); diff --git a/src/store/modules/Operations/ControlStore.js b/src/store/modules/Operations/ControlStore.js index e76063ba..320df6f9 100644 --- a/src/store/modules/Operations/ControlStore.js +++ b/src/store/modules/Operations/ControlStore.js @@ -51,7 +51,7 @@ const ControlStore = { actions: { async getLastPowerOperationTime({ commit }) { return await api - .get('/redfish/v1/Systems/system') + .get(`${await this.dispatch('global/getSystemPath')}`) .then((response) => { const lastReset = response.data.LastResetTime; if (lastReset) { @@ -61,9 +61,9 @@ const ControlStore = { }) .catch((error) => console.log(error)); }, - getLastBmcRebootTime({ commit }) { + async getLastBmcRebootTime({ commit }) { return api - .get('/redfish/v1/Managers/bmc') + .get(`${await this.dispatch('global/getBmcPath')}`) .then((response) => { const lastBmcReset = response.data.LastResetTime; const lastBmcRebootTime = new Date(lastBmcReset); @@ -71,11 +71,13 @@ const ControlStore = { }) .catch((error) => console.log(error)); }, - async rebootBmc({ dispatch }) { + async rebootBmc() { const data = { ResetType: 'GracefulRestart' }; return await api - .post('/redfish/v1/Managers/bmc/Actions/Manager.Reset', data) - .then(() => dispatch('getLastBmcRebootTime')) + .post( + `${await this.dispatch('global/getBmcPath')}/Actions/Manager.Reset`, + data, + ) .then(() => i18n.t('pageRebootBmc.toast.successRebootStart')) .catch((error) => { console.log(error); @@ -117,10 +119,13 @@ const ControlStore = { commit('setOperationInProgress', false); dispatch('getLastPowerOperationTime'); }, - serverPowerChange({ commit }, data) { + async serverPowerChange({ commit }, data) { commit('setOperationInProgress', true); api - .post('/redfish/v1/Systems/system/Actions/ComputerSystem.Reset', data) + .post( + `${await this.dispatch('global/getSystemPath')}/Actions/ComputerSystem.Reset`, + data, + ) .catch((error) => { console.log(error); commit('setOperationInProgress', false); diff --git a/src/store/modules/Operations/FactoryResetStore.js b/src/store/modules/Operations/FactoryResetStore.js index 395cae19..84a8f08a 100644 --- a/src/store/modules/Operations/FactoryResetStore.js +++ b/src/store/modules/Operations/FactoryResetStore.js @@ -6,9 +6,12 @@ const FactoryResetStore = { actions: { async resetToDefaults() { return await api - .post('/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults', { - ResetType: 'ResetAll', - }) + .post( + `${await this.dispatch('global/getBmcPath')}/Actions/Manager.ResetToDefaults`, + { + ResetType: 'ResetAll', + }, + ) .then(() => i18n.t('pageFactoryReset.toast.resetToDefaultsSuccess')) .catch((error) => { console.log('Factory Reset: ', error); @@ -19,7 +22,9 @@ const FactoryResetStore = { }, async resetBios() { return await api - .post('/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios') + .post( + `${await this.dispatch('global/getSystemPath')}/Bios/Actions/Bios.ResetBios`, + ) .then(() => i18n.t('pageFactoryReset.toast.resetBiosSuccess')) .catch((error) => { console.log('Factory Reset: ', error); diff --git a/src/store/modules/Operations/FirmwareStore.js b/src/store/modules/Operations/FirmwareStore.js index 7dce2316..ca3ed523 100644 --- a/src/store/modules/Operations/FirmwareStore.js +++ b/src/store/modules/Operations/FirmwareStore.js @@ -10,10 +10,8 @@ const FirmwareStore = { hostActiveFirmwareId: null, applyTime: null, httpPushUri: null, - tftpAvailable: false, }, getters: { - isTftpUploadAvailable: (state) => state.tftpAvailable, isSingleFileUploadEnabled: (state) => state.hostFirmware.length === 0, activeBmcFirmware: (state) => { return state.bmcFirmware.find( @@ -43,8 +41,6 @@ const FirmwareStore = { setHostFirmware: (state, firmware) => (state.hostFirmware = firmware), setApplyTime: (state, applyTime) => (state.applyTime = applyTime), setHttpPushUri: (state, httpPushUri) => (state.httpPushUri = httpPushUri), - setTftpUploadAvailable: (state, tftpAvailable) => - (state.tftpAvailable = tftpAvailable), }, actions: { async getFirmwareInformation({ dispatch }) { @@ -52,18 +48,18 @@ const FirmwareStore = { dispatch('getActiveBmcFirmware'); return await dispatch('getFirmwareInventory'); }, - getActiveBmcFirmware({ commit }) { + async getActiveBmcFirmware({ commit }) { return api - .get('/redfish/v1/Managers/bmc') + .get(`${await this.dispatch('global/getBmcPath')}`) .then(({ data: { Links } }) => { const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop(); commit('setActiveBmcFirmwareId', id); }) .catch((error) => console.log(error)); }, - getActiveHostFirmware({ commit }) { + async getActiveHostFirmware({ commit }) { return api - .get('/redfish/v1/Systems/system/Bios') + .get(`${await this.dispatch('global/getSystemPath')}/Bios`) .then(({ data: { Links } }) => { const id = Links?.ActiveSoftwareImage['@odata.id'].split('/').pop(); commit('setActiveHostFirmwareId', id); @@ -111,16 +107,9 @@ const FirmwareStore = { .then(({ data }) => { const applyTime = data.HttpPushUriOptions.HttpPushUriApplyTime.ApplyTime; - const allowableActions = - data?.Actions?.['#UpdateService.SimpleUpdate']?.[ - 'TransferProtocol@Redfish.AllowableValues' - ]; commit('setApplyTime', applyTime); const httpPushUri = data.HttpPushUri; commit('setHttpPushUri', httpPushUri); - if (allowableActions?.includes('TFTP')) { - commit('setTftpUploadAvailable', true); - } }) .catch((error) => console.log(error)); }, @@ -134,21 +123,6 @@ const FirmwareStore = { throw new Error(i18n.t('pageFirmware.toast.errorUpdateFirmware')); }); }, - async uploadFirmwareTFTP(fileAddress) { - const data = { - TransferProtocol: 'TFTP', - ImageURI: fileAddress, - }; - return await api - .post( - '/redfish/v1/UpdateService/Actions/UpdateService.SimpleUpdate', - data, - ) - .catch((error) => { - console.log(error); - throw new Error(i18n.t('pageFirmware.toast.errorUpdateFirmware')); - }); - }, async switchBmcFirmwareAndReboot({ getters }) { const backupLocation = getters.backupBmcFirmware.location; const data = { @@ -159,7 +133,7 @@ const FirmwareStore = { }, }; return await api - .patch('/redfish/v1/Managers/bmc', data) + .patch(`${await this.dispatch('global/getBmcPath')}`, data) .catch((error) => { console.log(error); throw new Error(i18n.t('pageFirmware.toast.errorSwitchImages')); diff --git a/src/store/modules/Operations/KeyClearStore.js b/src/store/modules/Operations/KeyClearStore.js index 78804e75..9e5e875e 100644 --- a/src/store/modules/Operations/KeyClearStore.js +++ b/src/store/modules/Operations/KeyClearStore.js @@ -10,7 +10,7 @@ const KeyClearStore = { }; return await api .patch( - '/redfish/v1/Systems/system/Bios/Settings', + `${await this.dispatch('global/getSystemPath')}/Bios/Settings`, selectedKeyForClearing, ) .then(() => i18n.t('pageKeyClear.toast.selectedKeyClearedSuccess')) diff --git a/src/store/modules/Operations/VirtualMediaStore.js b/src/store/modules/Operations/VirtualMediaStore.js index 1d27e215..9688d9c6 100644 --- a/src/store/modules/Operations/VirtualMediaStore.js +++ b/src/store/modules/Operations/VirtualMediaStore.js @@ -49,7 +49,7 @@ const VirtualMediaStore = { } return await api - .get('/redfish/v1/Managers/bmc/VirtualMedia') + .get(`${await this.dispatch('global/getBmcPath')}/VirtualMedia`) .then((response) => response.data.Members.map( (virtualMedia) => virtualMedia['@odata.id'], @@ -95,7 +95,7 @@ const VirtualMediaStore = { async mountImage(_, { id, data }) { return await api .post( - `/redfish/v1/Managers/bmc/VirtualMedia/${id}/Actions/VirtualMedia.InsertMedia`, + `${await this.dispatch('global/getBmcPath')}/VirtualMedia/${id}/Actions/VirtualMedia.InsertMedia`, data, ) .catch((error) => { @@ -106,7 +106,7 @@ const VirtualMediaStore = { async unmountImage(_, id) { return await api .post( - `/redfish/v1/Managers/bmc/VirtualMedia/${id}/Actions/VirtualMedia.EjectMedia`, + `${await this.dispatch('global/getBmcPath')}/VirtualMedia/${id}/Actions/VirtualMedia.EjectMedia`, ) .catch((error) => { console.log('Unmount image:', error); diff --git a/src/store/modules/SecurityAndAccess/CertificatesStore.js b/src/store/modules/SecurityAndAccess/CertificatesStore.js index 666f5fd5..5c7c36d2 100644 --- a/src/store/modules/SecurityAndAccess/CertificatesStore.js +++ b/src/store/modules/SecurityAndAccess/CertificatesStore.js @@ -1,29 +1,8 @@ import api from '@/store/api'; import i18n from '@/i18n'; -export const CERTIFICATE_TYPES = [ - { - type: 'HTTPS Certificate', - location: '/redfish/v1/Managers/bmc/NetworkProtocol/HTTPS/Certificates/', - label: i18n.t('pageCertificates.httpsCertificate'), - }, - { - type: 'LDAP Certificate', - location: '/redfish/v1/AccountService/LDAP/Certificates/', - label: i18n.t('pageCertificates.ldapCertificate'), - }, - { - type: 'TrustStore Certificate', - location: '/redfish/v1/Managers/bmc/Truststore/Certificates/', - // Web UI will show 'CA Certificate' instead of - // 'TrustStore Certificate' after user testing revealed - // the term 'TrustStore Certificate' wasn't recognized/was unfamilar - label: i18n.t('pageCertificates.caCertificate'), - }, -]; - -const getCertificateProp = (type, prop) => { - const certificate = CERTIFICATE_TYPES.find( +const getCertificateProp = (certificateTypes, type, prop) => { + const certificate = certificateTypes.find( (certificate) => certificate.type === type, ); return certificate ? certificate[prop] : null; @@ -34,10 +13,12 @@ const CertificatesStore = { state: { allCertificates: [], availableUploadTypes: [], + certificateTypes: [], }, getters: { allCertificates: (state) => state.allCertificates, availableUploadTypes: (state) => state.availableUploadTypes, + certificateTypes: (state) => state.certificateTypes, }, mutations: { setCertificates(state, certificates) { @@ -46,9 +27,40 @@ const CertificatesStore = { setAvailableUploadTypes(state, availableUploadTypes) { state.availableUploadTypes = availableUploadTypes; }, + setCertificateTypes(state, certificateTypes) { + state.certificateTypes = certificateTypes; + }, }, actions: { - async getCertificates({ commit }) { + async getCertificateTypes({ commit }) { + const certificateTypes = [ + { + type: 'HTTPS Certificate', + location: `${await this.dispatch( + 'global/getBmcPath', + )}/NetworkProtocol/HTTPS/Certificates/`, + label: i18n.t('pageCertificates.httpsCertificate'), + }, + { + type: 'LDAP Certificate', + location: '/redfish/v1/AccountService/LDAP/Certificates/', + label: i18n.t('pageCertificates.ldapCertificate'), + }, + { + type: 'TrustStore Certificate', + location: `${await this.dispatch( + 'global/getBmcPath', + )}/Truststore/Certificates/`, + // Web UI will show 'CA Certificate' instead of + // 'TrustStore Certificate' after user testing revealed + // the term 'TrustStore Certificate' wasn't recognized/was unfamilar + label: i18n.t('pageCertificates.caCertificate'), + }, + ]; + await commit('setCertificateTypes', certificateTypes); + }, + async getCertificates({ dispatch, getters, commit }) { + await dispatch('getCertificateTypes'); return await api .get('/redfish/v1/CertificateService/CertificateLocations') .then( @@ -75,14 +87,18 @@ const CertificatesStore = { return { type: Name, location: data['@odata.id'], - certificate: getCertificateProp(Name, 'label'), + certificate: getCertificateProp( + getters['certificateTypes'], + Name, + 'label', + ), issuedBy: Issuer.CommonName, issuedTo: Subject.CommonName, validFrom: new Date(ValidNotBefore), validUntil: new Date(ValidNotAfter), }; }); - const availableUploadTypes = CERTIFICATE_TYPES.filter( + const availableUploadTypes = getters['certificateTypes'].filter( ({ type }) => !certificates .map((certificate) => certificate.type) @@ -95,15 +111,23 @@ const CertificatesStore = { ); }); }, - async addNewCertificate({ dispatch }, { file, type }) { + async addNewCertificate({ dispatch, getters }, { file, type }) { return await api - .post(getCertificateProp(type, 'location'), file, { - headers: { 'Content-Type': 'application/x-pem-file' }, - }) + .post( + getCertificateProp(getters['certificateTypes'], type, 'location'), + file, + { + headers: { 'Content-Type': 'application/x-pem-file' }, + }, + ) .then(() => dispatch('getCertificates')) .then(() => i18n.t('pageCertificates.toast.successAddCertificate', { - certificate: getCertificateProp(type, 'label'), + certificate: getCertificateProp( + getters['certificateTypes'], + type, + 'label', + ), }), ) .catch((error) => { @@ -112,7 +136,7 @@ const CertificatesStore = { }); }, async replaceCertificate( - { dispatch }, + { dispatch, getters }, { certificateString, location, type }, ) { const data = {}; @@ -128,7 +152,11 @@ const CertificatesStore = { .then(() => dispatch('getCertificates')) .then(() => i18n.t('pageCertificates.toast.successReplaceCertificate', { - certificate: getCertificateProp(type, 'label'), + certificate: getCertificateProp( + getters['certificateTypes'], + type, + 'label', + ), }), ) .catch((error) => { @@ -138,13 +166,17 @@ const CertificatesStore = { ); }); }, - async deleteCertificate({ dispatch }, { type, location }) { + async deleteCertificate({ dispatch, getters }, { type, location }) { return await api .delete(location) .then(() => dispatch('getCertificates')) .then(() => i18n.t('pageCertificates.toast.successDeleteCertificate', { - certificate: getCertificateProp(type, 'label'), + certificate: getCertificateProp( + getters['certificateTypes'], + type, + 'label', + ), }), ) .catch((error) => { @@ -154,7 +186,7 @@ const CertificatesStore = { ); }); }, - async generateCsr(_, userData) { + async generateCsr({ getters }, userData) { const { certificateType, country, @@ -173,7 +205,11 @@ const CertificatesStore = { const data = {}; data.CertificateCollection = { - '@odata.id': getCertificateProp(certificateType, 'location'), + '@odata.id': getCertificateProp( + getters['certificateTypes'], + certificateType, + 'location', + ), }; data.Country = country; data.State = state; diff --git a/src/store/modules/SecurityAndAccess/PoliciesStore.js b/src/store/modules/SecurityAndAccess/PoliciesStore.js index e6bcfb96..f1e98b27 100644 --- a/src/store/modules/SecurityAndAccess/PoliciesStore.js +++ b/src/store/modules/SecurityAndAccess/PoliciesStore.js @@ -31,7 +31,7 @@ const PoliciesStore = { actions: { async getNetworkProtocolStatus({ commit }) { return await api - .get('/redfish/v1/Managers/bmc/NetworkProtocol') + .get(`${await this.dispatch('global/getBmcPath')}/NetworkProtocol`) .then((response) => { const sshProtocol = response.data.SSH.ProtocolEnabled; const ipmiProtocol = response.data.IPMI.ProtocolEnabled; @@ -42,7 +42,7 @@ const PoliciesStore = { }, async getBiosStatus({ commit }) { return await api - .get('/redfish/v1/Systems/system/Bios') + .get(`${await this.dispatch('global/getSystemPath')}/Bios`) .then((response) => { commit('setRtadEnabled', response.data.Attributes.pvm_rtad); commit('setVtpmEnabled', response.data.Attributes.pvm_vtpm); @@ -66,7 +66,10 @@ const PoliciesStore = { }, }; return await api - .patch('/redfish/v1/Managers/bmc/NetworkProtocol', ipmi) + .patch( + `${await this.dispatch('global/getBmcPath')}/NetworkProtocol`, + ipmi, + ) .then(() => { if (protocolEnabled) { return i18n.t('pagePolicies.toast.successIpmiEnabled'); @@ -92,7 +95,10 @@ const PoliciesStore = { }, }; return await api - .patch('/redfish/v1/Managers/bmc/NetworkProtocol', ssh) + .patch( + `${await this.dispatch('global/getBmcPath')}/NetworkProtocol`, + ssh, + ) .then(() => { if (protocolEnabled) { return i18n.t('pagePolicies.toast.successSshEnabled'); @@ -113,7 +119,7 @@ const PoliciesStore = { async saveRtadState({ commit }, updatedRtad) { commit('setRtadEnabled', updatedRtad); return await api - .patch('/redfish/v1/Systems/system/Bios/Settings', { + .patch(`${await this.dispatch('global/getSystemPath')}/Bios/Settings`, { Attributes: { pvm_rtad: updatedRtad, }, @@ -137,7 +143,7 @@ const PoliciesStore = { async saveVtpmState({ commit }, updatedVtpm) { commit('setVtpmEnabled', updatedVtpm); return await api - .patch('/redfish/v1/Systems/system/Bios/Settings', { + .patch(`${await this.dispatch('global/getSystemPath')}/Bios/Settings`, { Attributes: { pvm_vtpm: updatedVtpm, }, diff --git a/src/store/modules/Settings/DateTimeStore.js b/src/store/modules/Settings/DateTimeStore.js index 51b722a8..9d804a7e 100644 --- a/src/store/modules/Settings/DateTimeStore.js +++ b/src/store/modules/Settings/DateTimeStore.js @@ -19,7 +19,7 @@ const DateTimeStore = { actions: { async getNtpData({ commit }) { return await api - .get('/redfish/v1/Managers/bmc/NetworkProtocol') + .get(`${await this.dispatch('global/getBmcPath')}/NetworkProtocol`) .then((response) => { const ntpServers = response.data.NTP.NTPServers; const isNtpProtocolEnabled = response.data.NTP.ProtocolEnabled; @@ -40,7 +40,10 @@ const DateTimeStore = { ntpData.NTP.NTPServers = dateTimeForm.ntpServersArray; } return await api - .patch(`/redfish/v1/Managers/bmc/NetworkProtocol`, ntpData) + .patch( + `${await this.dispatch('global/getBmcPath')}/NetworkProtocol`, + ntpData, + ) .then(async () => { if (!dateTimeForm.ntpProtocolEnabled) { const dateTimeData = { @@ -58,9 +61,12 @@ const DateTimeStore = { */ const timeoutVal = state.isNtpProtocolEnabled ? 20000 : 0; return await new Promise((resolve, reject) => { - setTimeout(() => { + setTimeout(async () => { return api - .patch(`/redfish/v1/Managers/bmc`, dateTimeData) + .patch( + `${await this.dispatch('global/getBmcPath')}`, + dateTimeData, + ) .then(() => resolve()) .catch(() => reject()); }, timeoutVal); diff --git a/src/store/modules/Settings/NetworkStore.js b/src/store/modules/Settings/NetworkStore.js index 9b016030..a249d22b 100644 --- a/src/store/modules/Settings/NetworkStore.js +++ b/src/store/modules/Settings/NetworkStore.js @@ -29,29 +29,47 @@ const NetworkStore = { state.globalNetworkSettings = data.map(({ data }) => { const { DHCPv4, + DHCPv6, HostName, IPv4Addresses, IPv4StaticAddresses, + IPv6Addresses, + IPv6StaticAddresses, LinkStatus, MACAddress, + IPv6DefaultGateway, } = data; return { defaultGateway: IPv4StaticAddresses[0]?.Gateway, //First static gateway is the default gateway + ipv6DefaultGateway: IPv6DefaultGateway, dhcpAddress: IPv4Addresses.filter( (ipv4) => ipv4.AddressOrigin === 'DHCP', ), + dhcpv6Address: IPv6Addresses.filter( + (ipv6) => + ipv6.AddressOrigin === 'SLAAC' || ipv6.AddressOrigin === 'DHCPv6', + ), dhcpEnabled: DHCPv4.DHCPEnabled, + dhcp6Enabled: DHCPv6.OperatingMode, hostname: HostName, macAddress: MACAddress, linkStatus: LinkStatus, staticAddress: IPv4StaticAddresses[0]?.Address, // Display first static address on overview page + ipv6StaticAddress: IPv6StaticAddresses[0]?.Address, useDnsEnabled: DHCPv4.UseDNSServers, useDomainNameEnabled: DHCPv4.UseDomainName, useNtpEnabled: DHCPv4.UseNTPServers, + useDnsEnabledIpv6: DHCPv6.UseDNSServers, + useDomainNameEnabledIpv6: DHCPv6.UseDomainName, + useNtpEnabledIpv6: DHCPv6.UseNTPServers, }; }); }, setNtpState: (state, ntpState) => (state.ntpState = ntpState), + setDomainNameStateIpv6: (state, domainState) => + (state.domainStateIpv6 = domainState), + setDnsStateIpv6: (state, dnsState) => (state.dnsStateIpv6 = dnsState), + setNtpStateIpv6: (state, ntpState) => (state.ntpStateIpv6 = ntpState), setSelectedInterfaceId: (state, selectedInterfaceId) => (state.selectedInterfaceId = selectedInterfaceId), setSelectedInterfaceIndex: (state, selectedInterfaceIndex) => @@ -60,7 +78,7 @@ const NetworkStore = { actions: { async getEthernetData({ commit }) { return await api - .get('/redfish/v1/Managers/bmc/EthernetInterfaces') + .get(`${await this.dispatch('global/getBmcPath')}/EthernetInterfaces`) .then((response) => response.data.Members.map( (ethernetInterface) => ethernetInterface['@odata.id'], @@ -96,7 +114,7 @@ const NetworkStore = { }; return api .patch( - `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.selectedInterfaceId}`, + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`, data, ) .then(dispatch('getEthernetData')) @@ -114,18 +132,54 @@ const NetworkStore = { ); }); }, - async saveDomainNameState({ commit, state }, domainState) { - commit('setDomainNameState', domainState); + async saveDhcp6EnabledState({ state, dispatch }, dhcpState) { const data = { - DHCPv4: { - UseDomainName: domainState, + DHCPv6: { + OperatingMode: dhcpState ? 'Enabled' : 'Disabled', }, }; + return api + .patch( + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`, + data, + ) + .then(dispatch('getEthernetData')) + .then(() => { + return i18n.t('pageNetwork.toast.successSaveNetworkSettings', { + setting: i18n.t('pageNetwork.dhcp6'), + }); + }) + .catch((error) => { + console.log(error); + throw new Error( + i18n.t('pageNetwork.toast.errorSaveNetworkSettings', { + setting: i18n.t('pageNetwork.dhcp6'), + }), + ); + }); + }, + async saveDomainNameState({ commit, state }, { domainState, ipVersion }) { + var data; + if (ipVersion === 'IPv4') { + commit('setDomainNameState', domainState); + data = { + DHCPv4: { + UseDomainName: domainState, + }, + }; + } else if (ipVersion === 'IPv6') { + commit('setDomainNameStateIpv6', domainState); + data = { + DHCPv6: { + UseDomainName: domainState, + }, + }; + } // Saving to the first interface automatically updates DHCPv4 and DHCPv6 // on all interfaces return api .patch( - `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.firstInterfaceId}`, + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.firstInterfaceId}`, data, ) .then(() => { @@ -135,7 +189,9 @@ const NetworkStore = { }) .catch((error) => { console.log(error); - commit('setDomainNameState', !domainState); + if (ipVersion === 'IPv4') commit('setDomainNameState', !domainState); + else if (ipVersion === 'IPv6') + commit('setDomainNameStateIpv6', !domainState); throw new Error( i18n.t('pageNetwork.toast.errorSaveNetworkSettings', { setting: i18n.t('pageNetwork.domainName'), @@ -143,18 +199,28 @@ const NetworkStore = { ); }); }, - async saveDnsState({ commit, state }, dnsState) { - commit('setDnsState', dnsState); - const data = { - DHCPv4: { - UseDNSServers: dnsState, - }, - }; + async saveDnsState({ commit, state }, { dnsState, ipVersion }) { + var data; + if (ipVersion === 'IPv4') { + commit('setDnsState', dnsState); + data = { + DHCPv4: { + UseDNSServers: dnsState, + }, + }; + } else if (ipVersion === 'IPv6') { + commit('setDnsStateIpv6', dnsState); + data = { + DHCPv6: { + UseDNSServers: dnsState, + }, + }; + } // Saving to the first interface automatically updates DHCPv4 and DHCPv6 // on all interfaces return api .patch( - `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.firstInterfaceId}`, + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.firstInterfaceId}`, data, ) .then(() => { @@ -164,7 +230,8 @@ const NetworkStore = { }) .catch((error) => { console.log(error); - commit('setDnsState', !dnsState); + if (ipVersion === 'IPv4') commit('setDnsState', !dnsState); + else if (ipVersion === 'IPv6') commit('setDnsStateIpv6', !dnsState); throw new Error( i18n.t('pageNetwork.toast.errorSaveNetworkSettings', { setting: i18n.t('pageNetwork.dns'), @@ -172,18 +239,28 @@ const NetworkStore = { ); }); }, - async saveNtpState({ commit, state }, ntpState) { - commit('setNtpState', ntpState); - const data = { - DHCPv4: { - UseNTPServers: ntpState, - }, - }; + async saveNtpState({ commit, state }, { ntpState, ipVersion }) { + var data; + if (ipVersion === 'IPv4') { + commit('setNtpState', ntpState); + data = { + DHCPv4: { + UseNTPServers: ntpState, + }, + }; + } else if (ipVersion === 'IPv6') { + commit('setNtpStateIpv6', ntpState); + data = { + DHCPv6: { + UseNTPServers: ntpState, + }, + }; + } // Saving to the first interface automatically updates DHCPv4 and DHCPv6 // on all interfaces return api .patch( - `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.firstInterfaceId}`, + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.firstInterfaceId}`, data, ) .then(() => { @@ -193,7 +270,8 @@ const NetworkStore = { }) .catch((error) => { console.log(error); - commit('setNtpState', !ntpState); + if (ipVersion === 'IPv4') commit('setNtpState', !ntpState); + else if (ipVersion === 'IPv6') commit('setNtpStateIpv6', !ntpState); throw new Error( i18n.t('pageNetwork.toast.errorSaveNetworkSettings', { setting: i18n.t('pageNetwork.ntp'), @@ -221,7 +299,7 @@ const NetworkStore = { const newAddress = [ipv4Form]; return api .patch( - `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.selectedInterfaceId}`, + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`, { IPv4StaticAddresses: originalAddresses.concat(newAddress) }, ) .then(dispatch('getEthernetData')) @@ -239,10 +317,41 @@ const NetworkStore = { ); }); }, + async saveIpv6Address({ dispatch, state }, ipv6Form) { + const originalAddresses = state.ethernetData[ + state.selectedInterfaceIndex + ].IPv6StaticAddresses.map((ipv6) => { + const { Address, PrefixLength } = ipv6; + return { + Address, + PrefixLength, + }; + }); + const newAddress = [ipv6Form]; + return api + .patch( + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`, + { IPv6StaticAddresses: originalAddresses.concat(newAddress) }, + ) + .then(dispatch('getEthernetData')) + .then(() => { + return i18n.t('pageNetwork.toast.successSaveNetworkSettings', { + setting: i18n.t('pageNetwork.ipv6'), + }); + }) + .catch((error) => { + console.log(error); + throw new Error( + i18n.t('pageNetwork.toast.errorSaveNetworkSettings', { + setting: i18n.t('pageNetwork.ipv6'), + }), + ); + }); + }, async editIpv4Address({ dispatch, state }, ipv4TableData) { return api .patch( - `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.selectedInterfaceId}`, + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`, { IPv4StaticAddresses: ipv4TableData }, ) .then(dispatch('getEthernetData')) @@ -260,10 +369,31 @@ const NetworkStore = { ); }); }, + async editIpv6Address({ dispatch, state }, ipv6TableData) { + return api + .patch( + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`, + { IPv6StaticAddresses: ipv6TableData }, + ) + .then(dispatch('getEthernetData')) + .then(() => { + return i18n.t('pageNetwork.toast.successSaveNetworkSettings', { + setting: i18n.t('pageNetwork.ipv6'), + }); + }) + .catch((error) => { + console.log(error); + throw new Error( + i18n.t('pageNetwork.toast.errorSaveNetworkSettings', { + setting: i18n.t('pageNetwork.ipv6'), + }), + ); + }); + }, async saveSettings({ state, dispatch }, interfaceSettingsForm) { return api .patch( - `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.selectedInterfaceId}`, + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`, interfaceSettingsForm, ) .then(dispatch('getEthernetData')) @@ -288,7 +418,7 @@ const NetworkStore = { const newDnsArray = originalAddresses.concat(newAddress); return api .patch( - `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.selectedInterfaceId}`, + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`, { StaticNameServers: newDnsArray }, ) .then(dispatch('getEthernetData')) @@ -309,7 +439,7 @@ const NetworkStore = { async editDnsAddress({ dispatch, state }, dnsTableData) { return api .patch( - `/redfish/v1/Managers/bmc/EthernetInterfaces/${state.selectedInterfaceId}`, + `${await this.dispatch('global/getBmcPath')}/EthernetInterfaces/${state.selectedInterfaceId}`, { StaticNameServers: dnsTableData }, ) .then(dispatch('getEthernetData')) diff --git a/src/store/modules/Settings/PowerPolicyStore.js b/src/store/modules/Settings/PowerPolicyStore.js index 3adaec8d..fc65381e 100644 --- a/src/store/modules/Settings/PowerPolicyStore.js +++ b/src/store/modules/Settings/PowerPolicyStore.js @@ -44,7 +44,7 @@ const PowerPolicyStore = { }, async getPowerRestoreCurrentPolicy({ commit }) { return await api - .get('/redfish/v1/Systems/system') + .get(`${await this.dispatch('global/getSystemPath')}`) .then(({ data: { PowerRestorePolicy } }) => { commit('setPowerRestoreCurrentPolicy', PowerRestorePolicy); }) @@ -54,7 +54,7 @@ const PowerPolicyStore = { const data = { PowerRestorePolicy: powerPolicy }; return await api - .patch('/redfish/v1/Systems/system', data) + .patch(`${await this.dispatch('global/getSystemPath')}`, data) .then(() => { dispatch('getPowerRestoreCurrentPolicy'); return i18n.t('pagePowerRestorePolicy.toast.successSaveSettings'); |