Add support for diff and deploy for GTS
This commit is contained in:
		@@ -11,12 +11,7 @@ class Instance:
 | 
				
			|||||||
        self.reject_reports = False
 | 
					        self.reject_reports = False
 | 
				
			||||||
        self.id = None
 | 
					        self.id = None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        """Remote blocks and local blocks are parsed differently"""
 | 
					        self.parse_block(instance_dict)
 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            instance_dict["id"]
 | 
					 | 
				
			||||||
            self.parse_remote_block(instance_dict)
 | 
					 | 
				
			||||||
        except KeyError:
 | 
					 | 
				
			||||||
            self.parse_local_block(instance_dict)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __str__(self):
 | 
					    def __str__(self):
 | 
				
			||||||
        return f"{self.domain}: {self.severity}"
 | 
					        return f"{self.domain}: {self.severity}"
 | 
				
			||||||
@@ -36,10 +31,10 @@ class Instance:
 | 
				
			|||||||
            exportable[key] = getattr(self, key)
 | 
					            exportable[key] = getattr(self, key)
 | 
				
			||||||
        return exportable
 | 
					        return exportable
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def parse_remote_block(self, instance_dict):
 | 
					    def parse_block(self, instance_dict):
 | 
				
			||||||
        # this specifies possible properties and default values if not found on the remote source. If a default is None
 | 
					        # 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
 | 
					        # the value is required and the parse will fail
 | 
				
			||||||
        properties_and_defaults = [("domain", None), ("id", None), ("severity", "suspend"), ("public_comment", ""),
 | 
					        properties_and_defaults = [("domain", None), ("severity", "suspend"), ("public_comment", ""),
 | 
				
			||||||
                                   ("private_comment", ""), ("obfuscate", False), ("reject_media", True),
 | 
					                                   ("private_comment", ""), ("obfuscate", False), ("reject_media", True),
 | 
				
			||||||
                                   ("reject_reports", True)]
 | 
					                                   ("reject_reports", True)]
 | 
				
			||||||
        for key, default in properties_and_defaults:
 | 
					        for key, default in properties_and_defaults:
 | 
				
			||||||
@@ -49,29 +44,7 @@ class Instance:
 | 
				
			|||||||
                if default is not None:
 | 
					                if default is not None:
 | 
				
			||||||
                    setattr(self, key, default)
 | 
					                    setattr(self, key, default)
 | 
				
			||||||
                else:
 | 
					                else:
 | 
				
			||||||
                    raise KeyError(f"The key {key} was not in the remote servers response.")
 | 
					                    raise KeyError(f"The key {key} was not in the instance_dict response.")
 | 
				
			||||||
 | 
					 | 
				
			||||||
    def parse_local_block(self, instance_dict):
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            self.name = instance_dict["name"]
 | 
					 | 
				
			||||||
        except KeyError:
 | 
					 | 
				
			||||||
            pass
 | 
					 | 
				
			||||||
        self.domain = instance_dict["domain"]
 | 
					 | 
				
			||||||
        self.severity = instance_dict["severity"]
 | 
					 | 
				
			||||||
        self.public_comment = instance_dict["public_comment"]
 | 
					 | 
				
			||||||
        self.private_comment = instance_dict["private_comment"]
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            self.obfuscate = instance_dict["obfuscate"]
 | 
					 | 
				
			||||||
        except KeyError:
 | 
					 | 
				
			||||||
            pass
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            self.reject_media = instance_dict["reject_media"]
 | 
					 | 
				
			||||||
        except KeyError:
 | 
					 | 
				
			||||||
            pass
 | 
					 | 
				
			||||||
        try:
 | 
					 | 
				
			||||||
            self.reject_reports = instance_dict["reject_reports"]
 | 
					 | 
				
			||||||
        except KeyError:
 | 
					 | 
				
			||||||
            pass
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def apply(self, server, token, block_id=None):
 | 
					    def apply(self, server, token, block_id=None):
 | 
				
			||||||
        """Applies instance block on the remote server"""
 | 
					        """Applies instance block on the remote server"""
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user