def _init(): flavor = os.environ.get('SETTINGS_FLAVOR', 'dev') config_path = os.environ.get('DOCKER_REGISTRY_CONFIG', 'config.yml') if not os.path.isabs(config_path): config_path = os.path.join(os.path.dirname(__file__), '../../', 'config', config_path) try: f = open(config_path) except Exception: raise exceptions.FileNotFoundError('Heads-up! File is missing: %s' % config_path) conf = Config(f.read()) if flavor: conf = conf[flavor] conf.flavor = flavor if conf.privileged_key: try: f = open(conf.privileged_key) except Exception: raise exceptions.FileNotFoundError( 'Heads-up! File is missing: %s' % conf.privileged_key) try: conf.privileged_key = rsa.PublicKey.load_pkcs1(f.read()) except Exception: raise exceptions.ConfigError('Key at %s is not a valid RSA key' % conf.privileged_key) if conf.index_endpoint: conf.index_endpoint = conf.index_endpoint.strip('/') return conf
def _init(): flavor = os.environ.get('SETTINGS_FLAVOR', 'dev') config_path = os.environ.get('DOCKER_REGISTRY_CONFIG', 'config.yml') if not os.path.isabs(config_path): config_path = os.path.join(os.path.dirname(__file__), '../../', 'config', config_path) try: f = open(config_path) except Exception: raise exceptions.FileNotFoundError( 'Heads-up! File is missing: %s' % config_path) conf = Config(f.read()) if flavor: if flavor not in conf: raise exceptions.ConfigError( 'The specified flavor (%s) is missing in your config file (%s)' % (flavor, config_path)) conf = conf[flavor] conf.flavor = flavor if conf.privileged_key: try: f = open(conf.privileged_key) except Exception: raise exceptions.FileNotFoundError( 'Heads-up! File is missing: %s' % conf.privileged_key) try: pk = f.read().split('\n') pk = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' + ''.join(pk[1:-2]) pk = [pk[i: i + 64] for i in range(0, len(pk), 64)] pk = ('-----BEGIN PUBLIC KEY-----\n' + '\n'.join(pk) + '\n-----END PUBLIC KEY-----') bio = BIO.MemoryBuffer(pk) conf.privileged_key = RSA.load_pub_key_bio(bio) except Exception: raise exceptions.ConfigError( 'Key at %s is not a valid RSA key' % conf.privileged_key) f.close() if conf.index_endpoint: conf.index_endpoint = conf.index_endpoint.strip('/') return conf
def __init__(self, config=''): try: # Config is kept as-is... self._config = config # ... save Strings, that are yaml loaded if isinstance(config, compat.basestring): self._config = yaml.load(config) except Exception as e: # Failed yaml loading? Stop here! raise exceptions.ConfigError( 'Config is not valid yaml (%s): \n%s' % (e, config))
def load(): global _config if _config is not None: return _config data = None config_path = os.environ.get('DOCKER_REGISTRY_CONFIG', 'config.yml') if not os.path.isabs(config_path): config_path = os.path.join(os.path.dirname(__file__), '../../', 'config', config_path) try: f = open(config_path) except Exception: raise exceptions.FileNotFoundError( 'Heads-up! File is missing: %s' % config_path) try: data = yaml.load(f) except Exception: raise exceptions.ConfigError( 'Config file (%s) is not valid yaml' % config_path) config = data.get('common', {}) flavor = os.environ.get('SETTINGS_FLAVOR', 'dev') config.update(data.get(flavor, {})) config['flavor'] = flavor config = convert_env_vars(config) if 'privileged_key' in config: try: f = open(config['privileged_key']) except Exception: raise exceptions.FileNotFoundError( 'Heads-up! File is missing: %s' % config['privileged_key']) try: config['privileged_key'] = rsa.PublicKey.load_pkcs1(f.read()) except Exception: raise exceptions.ConfigError( 'Key at %s is not a valid RSA key' % config['privileged_key']) _config = Config(config) return _config
def __init__(self, config=None): if config is None: config = {} if isinstance(config, compat.basestring): try: self._config = yaml.load(config) except Exception as e: # Failed yaml loading? Stop here! raise exceptions.ConfigError( 'Config is not valid yaml (%s): \n%s' % (e, config)) else: # Config is kept as-is... self._config = config
def __getattr__(self, key): # Unset keys return None if key not in self._config: return None # raise exceptions.ConfigError("No such attribute: %s" % key) result = self._config[key] # Strings starting with `_env:' get evaluated if isinstance(result, compat.basestring) and result.startswith('_env:'): result = result.split(':', 2) varname = result[1] vardefault = '' if len(result) < 3 else result[2] try: result = yaml.load(os.environ.get(varname, vardefault)) except Exception as e: raise exceptions.ConfigError( 'Config `%s` (value: `%s`) is not valid: %s' % (varname, e, result)) # Dicts are rewrapped inside a Config object if isinstance(result, dict): result = Config(result) return result
def __init__(self, path=None, config=None): # Turn on streaming support self.supports_bytes_range = True # Increase buffer size up to 640 Kb self.buffer_size = 128 * 1024 # Create default Elliptics config cfg = elliptics.Config() # The parameter which sets the time to wait for the operation complete cfg.config.wait_timeout = (config.elliptics_wait_timeout or DEFAUL_WAIT_TIMEOUT) # The parameter which sets the timeout for pinging node cfg.config.check_timeout = (config.elliptics_check_timeout or DEFAULT_CHECK_TIMEOUT) # Number of IO threads in processing pool cfg.config.io_thread_num = (config.elliptics_io_thread_num or DEFAULT_IO_THREAD_NUM) # Number of threads in network processing pool cfg.config.net_thread_num = (config.elliptics_net_thread_num or DEFAULT_NET_THREAD_NUM) # Number of IO threads in processing pool dedicated to nonblocking ops nblock_iothreads = (config.elliptics_nonblocking_io_thread_num or DEFAULT_NONBLOCKING_IO_THREAD_NUM) cfg.config.nonblocking_io_thread_num = nblock_iothreads self.groups = config.elliptics_groups or DEFAULT_GROUPS if isinstance(self.groups, types.StringTypes): self.groups = map(int, self.groups.strip('[]').split(',')) if len(self.groups) == 0: raise exceptions.ConfigError("elliptics_groups must be specified") # loglevel of elliptics logger elliptics_log_level = (config.elliptics_verbosity or DEFAULT_VERBOSITY).lower() if elliptics_log_level not in elliptics.log_level.names.keys(): raise exceptions.ConfigError( 'Invalid log level %s. Use one of %s' % (elliptics_log_level, ','.join( elliptics.log_level.names.keys()))) # path to logfile elliptics_log_file = config.elliptics_logfile or '/dev/stderr' log = elliptics.Logger( elliptics_log_file, getattr(elliptics.log_level, elliptics_log_level)) self._elliptics_node = elliptics.Node(log, cfg) self.namespace = config.elliptics_namespace or DEFAULT_NAMESPACE logger.info("Using namespace %s", self.namespace) remotes_configuration = config.elliptics_nodes if remotes_configuration is None: raise exceptions.ConfigError("elliptics_nodes must be specified") elif isinstance(remotes_configuration, (types.TupleType, types.ListType)): remotes = remotes_configuration elif isinstance(remotes_configuration, types.StringTypes): remotes = remotes_configuration.split() else: raise exceptions.ConfigError("elliptics_nodes must be list," "tuple or string") try: logger.info("Remotes %s is being added", remotes) self._elliptics_node.add_remotes(remotes) logger.info("%s remotes have been added successfully", remotes) except Exception as err: logger.error("Failed to add remotes %s: %s", remotes, err) routes = self._session.routes.addresses() if not routes: # routing table is empty, # as no remotes have been successfully added or conencted. logger.error("routes %s, %s", routes, self._session.routes) raise exceptions.ConnectionError("Unable to connect to Elliptics")