Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
saltStatus() {
// Various Salt event tag matchers.
let isJobEvent = helpersMixin.methods.fnmatch("salt/job/*")
let isJobNew = helpersMixin.methods.fnmatch("salt/job/*/new")
let isJobReturn = helpersMixin.methods.fnmatch("salt/job/*/ret/*")
const accessToken = localStorage.getItem("access")
let es = new EventSourcePolyfill("/api/event_stream/", {
headers: {
"Authorization": `Bearer ${accessToken}`,
},
})
es.addEventListener("open", () => {
this.$store.dispatch("updateWs")
})
es.addEventListener("message", event => {
let data = JSON.parse(event.data)
// Display only activated notifs.
if (isJobNew(data.tag) && this.notifs.published === true) {
if (data.data.fun !== 'saltutil.find_job') {
data.type = "new"
data.color = "green"
data.icon = "keyboard_tab"
fire(event, data = null) {
if (event === "initSSE") {
// start listening with a little timeout
let values = Object.values(this.vue.items);
let thingIds = values.map(element => element.thingId).join(",");
switch(this.vue.suiteAuthActive){
case true:
this.source = new EventSourcePolyfill(
`${
this.vue.connection.http_endpoint
}/api/2/things?ids=${thingIds}&fields=thingId,policyId,attributes,features,_revision`,
{
headers: {
Authorization: Api.getConfig().headers.Authorization
},
withCredentials: true
}
);
break;
case false:
this.source = new EventSourcePolyfill(
`${
this.vue.connection.http_endpoint
}/api/2/things?ids=${thingIds}&x-cr-api-token=${