Allow missing values of remote block for GTS support
This commit is contained in:
parent
569cff0957
commit
27168a2a6e
@ -37,14 +37,19 @@ class Instance:
|
||||
return exportable
|
||||
|
||||
def parse_remote_block(self, instance_dict):
|
||||
self.domain = instance_dict["domain"]
|
||||
self.id = instance_dict["id"]
|
||||
self.severity = instance_dict["severity"]
|
||||
self.public_comment = instance_dict["public_comment"]
|
||||
self.private_comment = instance_dict["private_comment"]
|
||||
self.obfuscate = instance_dict["obfuscate"]
|
||||
self.reject_media = instance_dict["reject_media"]
|
||||
self.reject_reports = instance_dict["reject_reports"]
|
||||
# this specifies possible properties and default values if not found on the remote source. If a default is None
|
||||
# the value is required and the parse will fail
|
||||
properties_and_defaults = [("domain", None), ("id", None), ("severity", "suspend"), ("public_comment", ""),
|
||||
("private_comment", ""), ("obfuscate", False), ("reject_media", True),
|
||||
("reject_reports", True)]
|
||||
for key, default in properties_and_defaults:
|
||||
try:
|
||||
setattr(self, key, instance_dict[key])
|
||||
except KeyError:
|
||||
if default is not None:
|
||||
setattr(self, key, default)
|
||||
else:
|
||||
raise KeyError(f"The key {key} was not in the remote servers response.")
|
||||
|
||||
def parse_local_block(self, instance_dict):
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user