|
87 | 87 | </template> |
88 | 88 |
|
89 | 89 | <script> |
90 | | - import subscribing from '@/mixins/subscribing'; |
91 | | - import Instance from '@/services/instance'; |
92 | | - import {concatMap, debounceTime, merge, Subject, tap, timer} from '@/utils/rxjs'; |
93 | | - import AuditeventsList from '@/views/instances/auditevents/auditevents-list'; |
94 | | - import uniqBy from 'lodash/uniqBy'; |
95 | | - import moment from 'moment'; |
96 | | - import {VIEW_GROUP} from '../../index'; |
| 90 | +import subscribing from '@/mixins/subscribing'; |
| 91 | +import Instance from '@/services/instance'; |
| 92 | +import {concatMap, debounceTime, mergeWith, Subject, tap, timer} from '@/utils/rxjs'; |
| 93 | +import AuditeventsList from '@/views/instances/auditevents/auditevents-list'; |
| 94 | +import uniqBy from 'lodash/uniqBy'; |
| 95 | +import moment from 'moment'; |
| 96 | +import {VIEW_GROUP} from '../../index'; |
97 | 97 |
|
98 | | - class Auditevent { |
99 | | - constructor({timestamp, ...event}) { |
100 | | - Object.assign(this, event); |
101 | | - this.zonedTimestamp = timestamp; |
102 | | - this.timestamp = moment(timestamp); |
103 | | - } |
| 98 | +class Auditevent { |
| 99 | + constructor({timestamp, ...event}) { |
| 100 | + Object.assign(this, event); |
| 101 | + this.zonedTimestamp = timestamp; |
| 102 | + this.timestamp = moment(timestamp); |
| 103 | + } |
104 | 104 |
|
105 | | - get key() { |
106 | | - return `${this.zonedTimestamp}-${this.type}-${this.principal}`; |
107 | | - } |
| 105 | + get key() { |
| 106 | + return `${this.zonedTimestamp}-${this.type}-${this.principal}`; |
| 107 | + } |
108 | 108 |
|
109 | | - get remoteAddress() { |
110 | | - return this.data && this.data.details && this.data.details.remoteAddress || null; |
111 | | - } |
| 109 | + get remoteAddress() { |
| 110 | + return this.data && this.data.details && this.data.details.remoteAddress || null; |
| 111 | + } |
112 | 112 |
|
113 | | - get sessionId() { |
114 | | - return this.data && this.data.details && this.data.details.sessionId || null; |
115 | | - } |
| 113 | + get sessionId() { |
| 114 | + return this.data && this.data.details && this.data.details.sessionId || null; |
| 115 | + } |
116 | 116 |
|
117 | | - isSuccess() { |
118 | | - return this.type.toLowerCase().includes('success'); |
119 | | - } |
| 117 | + isSuccess() { |
| 118 | + return this.type.toLowerCase().includes('success'); |
| 119 | + } |
120 | 120 |
|
121 | | - isFailure() { |
122 | | - return this.type.toLowerCase().includes('failure'); |
123 | | - } |
| 121 | + isFailure() { |
| 122 | + return this.type.toLowerCase().includes('failure'); |
124 | 123 | } |
| 124 | +} |
125 | 125 |
|
126 | | - export default { |
127 | | - props: { |
128 | | - instance: { |
129 | | - type: Instance, |
130 | | - required: true |
131 | | - } |
| 126 | +export default { |
| 127 | + props: { |
| 128 | + instance: { |
| 129 | + type: Instance, |
| 130 | + required: true |
| 131 | + } |
| 132 | + }, |
| 133 | + mixins: [subscribing], |
| 134 | + components: {AuditeventsList}, |
| 135 | + data: () => ({ |
| 136 | + isLoading: false, |
| 137 | + error: null, |
| 138 | + events: [], |
| 139 | + filter: { |
| 140 | + after: moment().startOf('day'), |
| 141 | + type: null, |
| 142 | + principal: null |
132 | 143 | }, |
133 | | - mixins: [subscribing], |
134 | | - components: {AuditeventsList}, |
135 | | - data: () => ({ |
136 | | - isLoading: false, |
137 | | - error: null, |
138 | | - events: [], |
139 | | - filter: { |
140 | | - after: moment().startOf('day'), |
141 | | - type: null, |
142 | | - principal: null |
143 | | - }, |
144 | | - isOldAuditevents: false |
145 | | - }), |
146 | | - watch: { |
147 | | - filter: { |
148 | | - deep: true, |
149 | | - handler() { |
150 | | - this.filterChanged.next(); |
151 | | - } |
| 144 | + isOldAuditevents: false |
| 145 | + }), |
| 146 | + watch: { |
| 147 | + filter: { |
| 148 | + deep: true, |
| 149 | + handler() { |
| 150 | + this.filterChanged.next(); |
152 | 151 | } |
| 152 | + } |
| 153 | + }, |
| 154 | + methods: { |
| 155 | + formatDate(value) { |
| 156 | + return value.format(moment.HTML5_FMT.DATETIME_LOCAL); |
153 | 157 | }, |
154 | | - methods: { |
155 | | - formatDate(value) { |
156 | | - return value.format(moment.HTML5_FMT.DATETIME_LOCAL); |
157 | | - }, |
158 | | - parseDate(value) { |
159 | | - return moment(value, moment.HTML5_FMT.DATETIME_LOCAL, true); |
160 | | - }, |
161 | | - async fetchAuditevents() { |
162 | | - this.isLoading = true; |
163 | | - const response = await this.instance.fetchAuditevents(this.filter); |
164 | | - const converted = response.data.events.map(event => new Auditevent(event)); |
165 | | - converted.reverse(); |
166 | | - this.isLoading = false; |
167 | | - return converted; |
168 | | - }, |
169 | | - createSubscription() { |
170 | | - const vm = this; |
171 | | - vm.filterChanged = new Subject(); |
172 | | - vm.error = null; |
173 | | - return timer(0, 5000) |
174 | | - .pipe( |
175 | | - merge(vm.filterChanged.pipe( |
176 | | - debounceTime(250), |
177 | | - tap({ |
178 | | - next: () => vm.events = [] |
179 | | - }) |
180 | | - )), |
181 | | - concatMap(this.fetchAuditevents) |
182 | | - ) |
183 | | - .subscribe({ |
184 | | - next: events => { |
185 | | - vm.addEvents(events); |
186 | | - }, |
187 | | - error: error => { |
188 | | - console.warn('Fetching audit events failed:', error); |
189 | | - if (error.response.headers['content-type'].includes('application/vnd.spring-boot.actuator.v2')) { |
190 | | - vm.error = error; |
191 | | - } else { |
192 | | - vm.isOldAuditevents = true; |
193 | | - } |
| 158 | + parseDate(value) { |
| 159 | + return moment(value, moment.HTML5_FMT.DATETIME_LOCAL, true); |
| 160 | + }, |
| 161 | + async fetchAuditevents() { |
| 162 | + this.isLoading = true; |
| 163 | + const response = await this.instance.fetchAuditevents(this.filter); |
| 164 | + const converted = response.data.events.map(event => new Auditevent(event)); |
| 165 | + converted.reverse(); |
| 166 | + this.isLoading = false; |
| 167 | + return converted; |
| 168 | + }, |
| 169 | + createSubscription() { |
| 170 | + const vm = this; |
| 171 | + vm.filterChanged = new Subject(); |
| 172 | + vm.error = null; |
| 173 | +
|
| 174 | + return timer(0, 5000) |
| 175 | + .pipe( |
| 176 | + mergeWith(vm.filterChanged.pipe( |
| 177 | + debounceTime(250), |
| 178 | + tap({ |
| 179 | + next: () => vm.events = [] |
| 180 | + }) |
| 181 | + )), |
| 182 | + concatMap(this.fetchAuditevents) |
| 183 | + ) |
| 184 | + .subscribe({ |
| 185 | + next: events => { |
| 186 | + vm.addEvents(events); |
| 187 | + }, |
| 188 | + error: error => { |
| 189 | + console.warn('Fetching audit events failed:', error); |
| 190 | + if (error.response.headers['content-type'].includes('application/vnd.spring-boot.actuator.v2')) { |
| 191 | + vm.error = error; |
| 192 | + } else { |
| 193 | + vm.isOldAuditevents = true; |
194 | 194 | } |
195 | | - }); |
196 | | - }, |
197 | | - addEvents(events) { |
198 | | - this.events = uniqBy(this.events ? events.concat(this.events) : events, event => event.key); |
199 | | - } |
| 195 | + } |
| 196 | + }); |
200 | 197 | }, |
201 | | - install({viewRegistry}) { |
202 | | - viewRegistry.addView({ |
203 | | - name: 'instances/auditevents', |
204 | | - parent: 'instances', |
205 | | - path: 'auditevents', |
206 | | - component: this, |
207 | | - label: 'instances.auditevents.label', |
208 | | - group: VIEW_GROUP.SECURITY, |
209 | | - order: 600, |
210 | | - isEnabled: ({instance}) => instance.hasEndpoint('auditevents') |
211 | | - }); |
| 198 | + addEvents(events) { |
| 199 | + this.events = uniqBy(this.events ? events.concat(this.events) : events, event => event.key); |
212 | 200 | } |
| 201 | + }, |
| 202 | + install({viewRegistry}) { |
| 203 | + viewRegistry.addView({ |
| 204 | + name: 'instances/auditevents', |
| 205 | + parent: 'instances', |
| 206 | + path: 'auditevents', |
| 207 | + component: this, |
| 208 | + label: 'instances.auditevents.label', |
| 209 | + group: VIEW_GROUP.SECURITY, |
| 210 | + order: 600, |
| 211 | + isEnabled: ({instance}) => instance.hasEndpoint('auditevents') |
| 212 | + }); |
213 | 213 | } |
| 214 | +} |
214 | 215 | </script> |
0 commit comments