1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
import api, { getResponseCount } from '@/store/api';
import i18n from '@/i18n';
const SessionsStore = {
namespaced: true,
state: {
allConnections: [],
},
getters: {
allConnections: (state) => state.allConnections,
},
mutations: {
setAllConnections: (state, allConnections) =>
(state.allConnections = allConnections),
},
actions: {
async getSessionsData({ 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?.Oem?.OpenBMC.ClientID,
username: sessionUri.data?.UserName,
ipAddress: sessionUri.data?.ClientOriginIPAddress,
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('getSessionsData');
return response;
})
.then(
api.spread((...responses) => {
const { successCount, errorCount } = getResponseCount(responses);
const toastMessages = [];
if (successCount) {
const message = i18n.tc(
'pageSessions.toast.successDelete',
successCount
);
toastMessages.push({ type: 'success', message });
}
if (errorCount) {
const message = i18n.tc(
'pageSessions.toast.errorDelete',
errorCount
);
toastMessages.push({ type: 'error', message });
}
return toastMessages;
})
);
},
},
};
export default SessionsStore;
|