class GetElements(Plugin): def __init__(self, metadata, resolver, logger, config, args): super().__init__(metadata, resolver, logger, config, args) # self.metadata: Any metadata from the configuration for the set. # self.resolver: Configured instance of berserker_resolver. # If args.berserk is set, then berserker_ips will # be used as well to resolve hostnames. # self.logger: The logger instantiated for this plugin. # self.config: Loaded configuration file. # self.args: Any parsed command line args. # An example of how to instantiate FileRetriever class. self.url = 'url' in metadata and metadata['url'] or DEFAULT_JSON_URL self.cache_file = 'cache_file' in metadata and metadata['cache_file'] or None self.file_retriever = FileRetriever(self.logger, self.url, self.cache_file) # The one required method, must return the list of elements generated by # the call to the plugin. def get_elements(self): # Also has a 'get_json()' method. data = self.file_retriever.get() if data: elements = data.split() return elements return False
class GetElements(Plugin): def __init__(self, metadata, resolver, logger, config, args): super().__init__(metadata, resolver, logger, config, args) self.url = 'url' in metadata and metadata[ 'url'] or CLOUDFLARE_IP_RANGES_DEFAULT_JSON_URL self.cache_file = 'cache_file' in metadata and metadata[ 'cache_file'] or None self.file_retriever = FileRetriever(self.logger, self.url, self.cache_file) def get_elements(self): cloudflare_ips = self.get_cloudflare_ips_for_types() return cloudflare_ips def get_cloudflare_ips_for_types(self): data = self.file_retriever.get() if data: elements = data.split() return elements return False