def __init__(self, api_key, cache_file_name=None): auth_header = {'Authorization': 'Bearer {0}'.format(api_key)} self._requests = MultiRequest(default_headers=auth_header, max_requests=12, rate_limit=30) # Create an ApiCache if instructed to self._cache = ApiCache(cache_file_name) if cache_file_name else None
def __init__(self, cache_file_name=None): """Establishes basic HTTP params and loads a cache. Args: cache_file_name: String file name of cache. """ # TODO - lookup request rate limit # By observation, ShadowServer can be quite slow, so give it 90 seconds before it times out. self._requests = MultiRequest(max_requests=2, req_timeout=90.0) # Create an ApiCache if instructed to self._cache = ApiCache(cache_file_name) if cache_file_name else None
def __init__(self, api_key, resources_per_req=25, cache_file_name=None): """Establishes basic HTTP params and loads a cache. Args: api_key: VirusTotal API key resources_per_req: Maximum number of resources (hashes, URLs) to be send in a single request cache_file_name: String file name of cache. """ self._api_key = api_key self._resources_per_req = resources_per_req self._requests = MultiRequest() # Create an ApiCache if instructed to self._cache = ApiCache(cache_file_name) if cache_file_name else None
def __init__(self, cache_file_name=None, update_cache=True): """Establishes basic HTTP params and loads a cache. Args: cache_file_name: String file name of cache. update_cache: Determines whether cache should be written out back to the disk when closing it. Default is `True`. """ # TODO - lookup request rate limit # By observation, ShadowServer can be quite slow, so give it 90 seconds before it times out. self._requests = MultiRequest(max_requests=2, req_timeout=90.0) # Create an ApiCache if instructed to self._cache = ApiCache(cache_file_name, update_cache) if cache_file_name else None
def _open_cache(self, initial_contents=None): """Creates an ApiCache object, mocking the contents of the cache on disk. Args: initial_contents: A dict containing the initial contents of the cache Returns: ApiCache """ if not initial_contents: initial_contents = {} file_contents = simplejson.dumps(initial_contents) mock_read = mock_open(read_data=file_contents) with patch('__builtin__.open', mock_read, create=True): api_cache = ApiCache(self._file_name) return api_cache
def _open_cache(self, initial_contents=None, update_cache=True): """Creates an ApiCache object, mocking the contents of the cache on disk. Args: initial_contents: A dict containing the initial contents of the cache update_cache: Specifies whether ApiCache should write out the cache file when closing it Returns: ApiCache """ if not initial_contents: initial_contents = {} file_contents = simplejson.dumps(initial_contents) mock_read = mock_open(read_data=file_contents) with patch('__builtin__.open', mock_read, create=True): api_cache = ApiCache(self._file_name, update_cache=update_cache) return api_cache
def __init__(self, api_key, resources_per_req=25, cache_file_name=None, update_cache=True, req_timeout=None): """Establishes basic HTTP params and loads a cache. Args: api_key: VirusTotal API key resources_per_req: Maximum number of resources (hashes, URLs) to be send in a single request cache_file_name: String file name of cache. update_cache: Determines whether cache should be written out back to the disk when closing it. Default is `True`. req_timeout: Maximum number of seconds to wait without reading a response byte before deciding an error has occurred. Default is None. """ self._api_key = api_key self._resources_per_req = resources_per_req self._requests = MultiRequest(req_timeout=req_timeout) # Create an ApiCache if instructed to self._cache = ApiCache(cache_file_name, update_cache) if cache_file_name else None
def __init__(self, api_key, cache_file_name=None, update_cache=True, req_timeout=None): """Establishes basic HTTP params and loads a cache. Args: api_key: VirusTotal API key cache_file_name: String file name of cache. update_cache: Determines whether cache should be written out back to the disk when closing it. Default is `True`. req_timeout: Maximum number of seconds to wait without reading a response byte before deciding an error has occurred. Default is None. """ self._requests = MultiRequest(req_timeout=req_timeout, default_headers={'x-apikey': api_key}, drop_404s=True) # Create an ApiCache if instructed to self._cache = ApiCache(cache_file_name, update_cache) if cache_file_name else None
def __init__(self, api_key, resources_per_req=25, cache_file_name=None, update_cache=True): """Establishes basic HTTP params and loads a cache. Args: api_key: VirusTotal API key resources_per_req: Maximum number of resources (hashes, URLs) to be send in a single request cache_file_name: String file name of cache. update_cache: Determines whether cache should be written out back to the disk when closing it. Default is `True`. """ self._api_key = api_key self._resources_per_req = resources_per_req self._requests = MultiRequest() # Create an ApiCache if instructed to self._cache = ApiCache(cache_file_name, update_cache) if cache_file_name else None