|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
import hashlib
|
|
|
|
|
import json
|
|
|
|
|
import shlex
|
|
|
|
|
from enum import Enum
|
|
|
|
|
|
|
|
|
@ -72,8 +74,38 @@ class NagObject:
|
|
|
|
|
wrap(dir[1], ws_base).strip().strip('\\\n').strip())
|
|
|
|
|
return string + '}\n'
|
|
|
|
|
|
|
|
|
|
def from_object(self, object: dict) -> None:
|
|
|
|
|
self.m_type.value = object['type']
|
|
|
|
|
self.m_config_file = object['config_file']
|
|
|
|
|
self.m_directives = object['directives']
|
|
|
|
|
self.m_line_no = object['line_number']
|
|
|
|
|
|
|
|
|
|
def to_object(self) -> dict:
|
|
|
|
|
object = {
|
|
|
|
|
'type': self.m_type.value,
|
|
|
|
|
'config_file': self.m_config_file,
|
|
|
|
|
'directives': self.m_directives,
|
|
|
|
|
'line_number': self.m_line_no
|
|
|
|
|
}
|
|
|
|
|
return object
|
|
|
|
|
|
|
|
|
|
def from_json(self, string: str) -> None:
|
|
|
|
|
self.from_object(json.loads(string))
|
|
|
|
|
|
|
|
|
|
def to_json(self) -> str:
|
|
|
|
|
return json.dumps(self.to_object)
|
|
|
|
|
|
|
|
|
|
def get_type(self) -> NagObjectType:
|
|
|
|
|
return self.m_type
|
|
|
|
|
|
|
|
|
|
def get_directives(self) -> list[list[str]]:
|
|
|
|
|
return self.m_directives
|
|
|
|
|
|
|
|
|
|
def get_config_hash(self) -> int:
|
|
|
|
|
hash = hashlib.sha256()
|
|
|
|
|
hash.update(self.m_config_file.encode('utf-8'))
|
|
|
|
|
digest = hash.hexdigest()
|
|
|
|
|
return int(digest,16) * 1000000
|
|
|
|
|
|
|
|
|
|
def get_id(self) -> int:
|
|
|
|
|
return self.get_config_hash() + self.m_line_no
|
|
|
|
|