def getCacheConf(): '''Return a tuple of (cache_url, cache_dump, cache_host, cache_port, x509_host_key, x509_host_cert, x509_cert_dir)''' config.parse_arc_conf(os.environ['ARC_CONFIG'] if 'ARC_CONFIG' in os.environ else ARC_CONF) # Use cache access URL if [arex/ws/cache] is present cache_url = '' if config.check_blocks('arex/ws/cache'): arex_url = config.get_value('wsurl', 'arex/ws') if not arex_url: # Use default endpoint, but first we need hostname hostname = config.get_value('hostname', 'common') or socket.gethostname() arex_url = DEFAULT_WS_INTERFACE.replace('hostname', hostname) cache_url = '%s/cache' % arex_url cache_dump = config.get_value('cachedump', 'acix-scanner') == 'yes' cache_host = config.get_value('hostname', 'acix-scanner') or CACHE_INTERFACE cache_port = int( config.get_value('port', 'acix-scanner') or CACHE_SSL_PORT) x509_host_key = config.get_value( 'x509_host_key', ['acix-scanner', 'common']) or DEFAULT_HOST_KEY x509_host_cert = config.get_value( 'x509_host_cert', ['acix-scanner', 'common']) or DEFAULT_HOST_CERT x509_cert_dir = config.get_value( 'x509_cert_dir', ['acix-scanner', 'common']) or DEFAULT_CERTIFICATES return (cache_url, cache_dump, cache_host, cache_port, x509_host_key, x509_host_cert, x509_cert_dir)
def getARCCacheDirs(): config.parse_arc_conf(os.environ['ARC_CONFIG'] if 'ARC_CONFIG' in os.environ else ARC_CONF) cache_dirs = config.get_value('cachedir', 'arex/cache', force_list=True) # First value is cachedir, second value can be 'drain' cache_dirs = [c.split()[0] for c in cache_dirs] if cache_dirs else [] return cache_dirs
def getCacheConf(): '''Return a tuple of (cachescanners, x509_host_key, x509_host_cert, x509_cert_dir)''' config.parse_arc_conf(os.environ['ARC_CONFIG'] if 'ARC_CONFIG' in os.environ else ARC_CONF) cachescanners = config.get_value('cachescanner', 'acix-index', force_list=True) x509_host_key = config.get_value( 'x509_host_key', ['acix-scanner', 'common']) or DEFAULT_HOST_KEY x509_host_cert = config.get_value( 'x509_host_cert', ['acix-scanner', 'common']) or DEFAULT_HOST_CERT x509_cert_dir = config.get_value( 'x509_cert_dir', ['acix-scanner', 'common']) or DEFAULT_CERTIFICATES return (cachescanners, x509_host_key, x509_host_cert, x509_cert_dir)
def get_parsed_arcconf(conf_f): # handle default def_conf_f = config.arcconf_defpath() runconf_load = False if conf_f is None: if os.path.exists(def_conf_f): conf_f = def_conf_f elif def_conf_f != '/etc/arc.conf' and os.path.exists('/etc/arc.conf'): conf_f = '/etc/arc.conf' logger.warning( 'There is no arc.conf in ARC installation prefix (%s). ' 'Using /etc/arc.conf that exists.', def_conf_f) else: logger.error( 'Cannot find ARC configuration file in the default location.') return None if arcctl_runtime_config is not None: runconf_load = os.path.exists(arcctl_runtime_config) else: logger.debug( 'Custom ARC configuration file location used. Runtime configuration will not be used.' ) try: logger.debug('Getting ARC configuration (config file: %s)', conf_f) if runconf_load: arcconf_mtime = os.path.getmtime(conf_f) default_mtime = os.path.getmtime(config.defaults_defpath()) runconf_mtime = os.path.getmtime(arcctl_runtime_config) if runconf_mtime < arcconf_mtime or runconf_mtime < default_mtime: runconf_load = False if runconf_load: logger.debug('Loading cached parsed configuration from %s', arcctl_runtime_config) config.load_run_config(arcctl_runtime_config) else: logger.debug( 'Parsing configuration options from %s (with defaults in %s)', conf_f, config.defaults_defpath()) config.parse_arc_conf(conf_f) if arcctl_runtime_config is not None: config.save_run_config(arcctl_runtime_config) arcconfig = config arcconfig.conf_f = conf_f except IOError: logger.error('Failed to open ARC configuration file %s', conf_f) arcconfig = None return arcconfig
def get_parsed_arcconf(conf_f): """Return parsed arc.conf (taking into account defaults and cached running config if applicable""" # handle default def_conf_f = config.arcconf_defpath() runconf_load = False # if not overrided by command line --config argument (passed as a parameter to this function) if conf_f is None: # check location is defined by ARC_CONFIG if 'ARC_CONFIG' in os.environ: conf_f = os.environ['ARC_CONFIG'] logger.debug('Will use ARC configuration file %s as defined by ARC_CONFIG environmental variable', conf_f) if not os.path.exists(conf_f): logger.error('Cannot find ARC configuration file %s (defined by ARC_CONFIG environmental variable)', conf_f) return None # use installation prefix location elif os.path.exists(def_conf_f): conf_f = def_conf_f runconf_load = True # or fallback to /etc/arc.conf elif def_conf_f != '/etc/arc.conf' and os.path.exists('/etc/arc.conf'): conf_f = '/etc/arc.conf' logger.warning('There is no arc.conf in ARC installation prefix (%s). ' 'Using /etc/arc.conf that exists.', def_conf_f) runconf_load = True else: if arcctl_server_mode(): logger.error('Cannot find ARC configuration file in the default location.') return None if runconf_load: if arcctl_runtime_config is None: runconf_load = False else: runconf_load = os.path.exists(arcctl_runtime_config) else: logger.debug('Custom ARC configuration file location is specified. Ignoring cached runtime configuration usage.') try: logger.debug('Getting ARC configuration (config file: %s)', conf_f) if runconf_load: arcconf_mtime = os.path.getmtime(conf_f) default_mtime = os.path.getmtime(config.defaults_defpath()) runconf_mtime = os.path.getmtime(arcctl_runtime_config) if runconf_mtime < arcconf_mtime or runconf_mtime < default_mtime: runconf_load = False if runconf_load: logger.debug('Loading cached parsed configuration from %s', arcctl_runtime_config) config.load_run_config(arcctl_runtime_config) else: logger.debug('Parsing configuration options from %s (with defaults in %s)', conf_f, config.defaults_defpath()) config.parse_arc_conf(conf_f) if arcctl_runtime_config is not None: config.save_run_config(arcctl_runtime_config) arcconfig = config arcconfig.conf_f = conf_f except IOError: if arcctl_server_mode(): logger.error('Failed to open ARC configuration file %s', conf_f) else: logger.debug('arcctl is working in config-less mode relying on defaults only') arcconfig = None return arcconfig