Added Login, TTS Login, Policies

This commit is contained in:
Tom
2024-10-25 19:09:34 +00:00
parent 0c7fbf1cb9
commit 65f4172bc2
10 changed files with 275 additions and 40 deletions

View File

@ -1,6 +1,5 @@
import { Injectable } from '@angular/core';
import { DatePipe } from '@angular/common';
import { Subscription } from 'rxjs';
import { HermesSocketService } from './hermes-socket.service';
import EventService from './shared/services/EventService';
@ -39,6 +38,15 @@ export class HermesClientService {
return this.listen();
}
public disconnect() {
if (!this.connected)
return;
this.socket.close();
this.connected = false;
this.events.emit('tts_logoff', null);
}
private send(op: number, data: any) {
if (op != 0)
console.log("TX:", data);
@ -61,6 +69,54 @@ export class HermesClientService {
});
}
public createPolicy(groupId: string, path: string, usage: number, timespan: number) {
if (!this.logged_in)
return;
this.send(3, {
request_id: null,
type: "create_policy",
data: {
groupId, path, count: usage, span: timespan
},
});
}
public deletePolicy(id: string) {
if (!this.logged_in)
return;
this.send(3, {
request_id: null,
type: "delete_policy",
data: {
id
},
});
}
public fetchPolicies() {
if (!this.logged_in)
return;
this.send(3, {
request_id: null,
type: "get_policies",
data: null,
});
}
public fetchPermissionsAndGroups() {
if (!this.logged_in)
return;
this.send(3, {
request_id: null,
type: "get_permissions",
data: null,
});
}
public heartbeat() {
const date = new Date()
this.send(0, {
@ -75,6 +131,19 @@ export class HermesClientService {
this.subscriptions[code].push(action);
}
public updatePolicy(id: string, groupId: string, path: string, usage: number, timespan: number) {
if (!this.logged_in)
return;
this.send(3, {
request_id: null,
type: "update_policy",
data: {
id, groupId, path, count: usage, span: timespan
},
});
}
private listen() {
return this.socket.subscribe({
next: (message: any) => {