diff options
author | Sukanya Pandey <sukapan1@in.ibm.com> | 2020-12-02 16:34:09 +0300 |
---|---|---|
committer | Derick Montague <derick.montague@ibm.com> | 2020-12-16 02:12:18 +0300 |
commit | 34efde291781c01c78e4363d919cdf4d5c90ae43 (patch) | |
tree | 02463d010d1ecafec1ec423638cac99d04f768e7 /src/store | |
parent | 8f030bac11637fcd0a005907b558d7accbff68bd (diff) | |
download | webui-vue-34efde291781c01c78e4363d919cdf4d5c90ae43.tar.xz |
Add client sessions page
- This page will show the list of sessions that are
currently connected to the BMC.
APIs used:
- To get all the sessions API used is
`/redfish/v1/SessionService/Sessions`
- To delete the sessions API used is
`/redfish/v1/SessionService/Sessions/<session id>`
Signed-off-by: Sukanya Pandey <sukapan1@in.ibm.com>
Change-Id: Ia81f62cbbea749809b9b7f7e62356cfe2db7fc18
Diffstat (limited to 'src/store')
-rw-r--r-- | src/store/index.js | 2 | ||||
-rw-r--r-- | src/store/modules/AccessControl/ClientSessionsStore.js | 80 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/store/index.js b/src/store/index.js index b4a77d82..151eb68c 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -3,6 +3,7 @@ import Vuex from 'vuex'; import GlobalStore from './modules/GlobalStore'; import AuthenticationStore from './modules/Authentication/AuthenticanStore'; +import ClientSessions from './modules/AccessControl/ClientSessionsStore'; import LdapStore from './modules/AccessControl/LdapStore'; import LocalUserManagementStore from './modules/AccessControl/LocalUserMangementStore'; import SslCertificatesStore from './modules/AccessControl/SslCertificatesStore'; @@ -36,6 +37,7 @@ export default new Vuex.Store({ modules: { global: GlobalStore, authentication: AuthenticationStore, + clientSessions: ClientSessions, dateTime: DateTimeStore, ldap: LdapStore, localUsers: LocalUserManagementStore, diff --git a/src/store/modules/AccessControl/ClientSessionsStore.js b/src/store/modules/AccessControl/ClientSessionsStore.js new file mode 100644 index 00000000..a09f766e --- /dev/null +++ b/src/store/modules/AccessControl/ClientSessionsStore.js @@ -0,0 +1,80 @@ +import api, { getResponseCount } from '@/store/api'; +import i18n from '@/i18n'; + +const ClientSessionsStore = { + namespaced: true, + state: { + allConnections: [], + }, + getters: { + allConnections: (state) => state.allConnections, + }, + mutations: { + setAllConnections: (state, allConnections) => + (state.allConnections = allConnections), + }, + actions: { + async getClientSessionsData({ commit }) { + return await api + .get('/redfish/v1/SessionService/Sessions') + .then((response) => + response.data.Members.map((sessionLogs) => sessionLogs['@odata.id']) + ) + .then((sessionUris) => + api.all(sessionUris.map((sessionUri) => api.get(sessionUri))) + ) + .then((sessionUris) => { + const allConnectionsData = sessionUris.map((sessionUri) => { + return { + clientID: sessionUri.data?.Id, + username: sessionUri.data?.UserName, + ipAddress: sessionUri.data?.Oem?.OpenBMC.ClientID.slice(2), + uri: sessionUri.data['@odata.id'], + }; + }); + commit('setAllConnections', allConnectionsData); + }) + .catch((error) => { + console.log('Client Session Data:', error); + }); + }, + async disconnectSessions({ dispatch }, uris = []) { + const promises = uris.map((uri) => + api.delete(uri).catch((error) => { + console.log(error); + return error; + }) + ); + return await api + .all(promises) + .then((response) => { + dispatch('getClientSessionsData'); + return response; + }) + .then( + api.spread((...responses) => { + const { successCount, errorCount } = getResponseCount(responses); + const toastMessages = []; + + if (successCount) { + const message = i18n.tc( + 'pageClientSessions.toast.successDelete', + successCount + ); + toastMessages.push({ type: 'success', message }); + } + + if (errorCount) { + const message = i18n.tc( + 'pageClientSessions.toast.errorDelete', + errorCount + ); + toastMessages.push({ type: 'error', message }); + } + return toastMessages; + }) + ); + }, + }, +}; +export default ClientSessionsStore; |