open-vault/ui/app/services/csp-event.js
Hamid Ghaf 27bb03bbc0
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

37 lines
824 B
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
/*eslint-disable no-constant-condition*/
import { computed } from '@ember/object';
import Service from '@ember/service';
import { task, waitForEvent } from 'ember-concurrency';
export default Service.extend({
events: computed(function () {
return [];
}),
connectionViolations: computed('events.@each.violatedDirective', function () {
return this.events.filter((e) => e.violatedDirective.startsWith('connect-src'));
}),
attach() {
this.monitor.perform();
},
remove() {
this.monitor.cancelAll();
},
monitor: task(function* () {
this.events.clear();
while (true) {
const event = yield waitForEvent(window.document, 'securitypolicyviolation');
this.events.addObject(event);
}
}),
});