Switch ipresolver to always be defined in the storage context
We now use a no-op IP resolver instead of an IF check Fixes https://jira.prod.coreos.systems/browse/QS-38
This commit is contained in:
parent
5dfa46ed56
commit
8194f5cf72
3 changed files with 27 additions and 3 deletions
|
@ -4,6 +4,7 @@ from storage.fakestorage import FakeStorage
|
|||
from storage.distributedstorage import DistributedStorage
|
||||
from storage.swift import SwiftStorage
|
||||
from storage.downloadproxy import DownloadProxy
|
||||
from util.ipresolver import NoopIPResolver
|
||||
|
||||
STORAGE_DRIVER_CLASSES = {
|
||||
'LocalStorage': LocalStorage,
|
||||
|
@ -33,7 +34,7 @@ class StorageContext(object):
|
|||
self.metric_queue = metric_queue
|
||||
self.chunk_cleanup_queue = chunk_cleanup_queue
|
||||
self.config_provider = config_provider
|
||||
self.ip_resolver = ip_resolver
|
||||
self.ip_resolver = ip_resolver or NoopIPResolver()
|
||||
|
||||
|
||||
class Storage(object):
|
||||
|
|
|
@ -622,7 +622,7 @@ class CloudFrontedS3Storage(S3Storage):
|
|||
|
||||
resolved_ip_info = None
|
||||
logger.debug('Got direct download request for path "%s" with IP "%s"', path, request_ip)
|
||||
if request_ip is not None and self._context.ip_resolver is not None:
|
||||
if request_ip is not None:
|
||||
# Lookup the IP address in our resolution table and determine whether it is under AWS.
|
||||
# If it is, then return an S3 signed URL, since we are in-network.
|
||||
resolved_ip_info = self._context.ip_resolver.resolve_ip(request_ip)
|
||||
|
|
|
@ -2,6 +2,9 @@ import logging
|
|||
import json
|
||||
import requests
|
||||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
from six import add_metaclass
|
||||
|
||||
from cachetools import ttl_cache, lru_cache
|
||||
from collections import namedtuple, defaultdict
|
||||
from netaddr import IPNetwork, IPAddress, IPSet, AddrFormatError
|
||||
|
@ -9,6 +12,8 @@ from netaddr import IPNetwork, IPAddress, IPSet, AddrFormatError
|
|||
import geoip2.database
|
||||
import geoip2.errors
|
||||
|
||||
from util.abchelpers import nooper
|
||||
|
||||
ResolvedLocation = namedtuple('ResolvedLocation', ['provider', 'region', 'service', 'sync_token'])
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -28,7 +33,25 @@ def update_resolver_datafiles():
|
|||
f.write(response.text)
|
||||
logger.debug('Successfully wrote %s', filename)
|
||||
|
||||
class IPResolver(object):
|
||||
|
||||
@add_metaclass(ABCMeta)
|
||||
class IPResolverInterface(object):
|
||||
""" Helper class for resolving information about an IP address. """
|
||||
@abstractmethod
|
||||
def resolve_ip(self, ip_address):
|
||||
""" Attempts to return resolved information about the specified IP Address. If such an attempt
|
||||
fails, returns None.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@nooper
|
||||
class NoopIPResolver(IPResolverInterface):
|
||||
""" No-op version of the security scanner API. """
|
||||
pass
|
||||
|
||||
|
||||
class IPResolver(IPResolverInterface):
|
||||
def __init__(self, app):
|
||||
self.app = app
|
||||
self.geoip_db = geoip2.database.Reader('util/ipresolver/GeoLite2-Country.mmdb')
|
||||
|
|
Reference in a new issue