def setup(self): try: config = self.container.config[constants.CONFIG_KEY] except KeyError: raise ConfigurationError('`{}` config key not found'.format( constants.CONFIG_KEY)) self.version = config.get('BAYEUX_VERSION', self.version) self.minimum_version = config.get('BAYEUX_MINIMUM_VERSION', self.minimum_version) self.api_version = config.get('API_VERSION', self.api_version) try: self.username = config['USERNAME'] self.password = config['PASSWORD'] self.security_token = config['SECURITY_TOKEN'] self.sandbox = config['SANDBOX'] except KeyError as exc: raise ConfigurationError( '`{}` configuration does not contain mandatory ' '`{}` key'.format(constants.CONFIG_KEY, exc.args[0])) from exc self.replay_enabled = config.get('PUSHTOPIC_REPLAY_ENABLED', False) if self.replay_enabled: self._setup_replay_storage(config)
def get_service_name(service_cls): service_name = getattr(service_cls, 'name', None) if service_name is None: raise ConfigurationError( 'Service class must define a `name` attribute ({}.{})'.format( service_cls.__module__, service_cls.__name__)) if not isinstance(service_name, six.string_types): raise ConfigurationError( 'Service name attribute must be a string ({}.{}.name)'.format( service_cls.__module__, service_cls.__name__)) return service_name
def parse_address(address_string): address_re = re.compile(r'^((?P<address>[^:]+):)?(?P<port>\d+)$') match = address_re.match(address_string) if match is None: raise ConfigurationError( 'Misconfigured bind address `{}`. ' 'Should be `[address:]port`'.format(address_string)) address = match.group('address') or '' port = int(match.group('port')) return BindAddress(address, port)
def setup(self): try: config = self.container.config[constants.CONFIG_KEY] except KeyError: raise ConfigurationError( '`{}` config key not found'.format(constants.CONFIG_KEY)) token = config.get('TOKEN') clients = config.get('BOTS') if token: self.clients[constants.DEFAULT_BOT_NAME] = SlackClient(token) if clients: for bot_name, token in clients.items(): self.clients[bot_name] = SlackClient(token) if not self.clients: raise ConfigurationError( 'At least one token must be provided in `{}` config' .format(constants.CONFIG_KEY))
def _setup_replay_storage(self, config): try: redis_uri = config['PUSHTOPIC_REPLAY_REDIS_URI'] except KeyError: raise ConfigurationError( '`{}` must have `PUSHTOPIC_REPLAY_REDIS_URI` defined if ' '`PUSHTOPIC_REPLAY_ENABLED` is set to `True`'.format( constants.CONFIG_KEY)) self.replay_storage = redis.StrictRedis.from_url(redis_uri) self.replay_storage_ttl = config.get('PUSHTOPIC_REPLAY_TTL', self.replay_storage_ttl)
def setup(self): if not self.events and not self.keys: error_message = ( 'Provide either `events` or `keys` to get notifications') log.error(error_message) raise ConfigurationError(error_message) self._redis_uri = self.container.config['REDIS_URIS'][ self.uri_config_key] redis_config = self.container.config.get('REDIS', {}) self._notification_events = redis_config.get('notification_events') super().setup()
def env_var_constructor(loader, node, raw=False): raw_value = loader.construct_scalar(node) # detect and error on recursive environment variables if not has_regex_module and RECURSIVE_ENV_VAR_MATCHER.match( raw_value): # pragma: no cover raise ConfigurationError( "Nested environment variable lookup requires the `regex` module") value = ENV_VAR_MATCHER.sub(_replace_env_var, raw_value) if value == raw_value: return value # avoid recursion return value if raw else yaml.safe_load(value)
def setup(self): if not self.events and not self.keys: error_message = 'Provide either `events` or `keys` to get notifications' log.error(error_message) raise ConfigurationError(error_message) self._redis_uri = self.container.config['REDIS_URIS'][self.uri_config_key] redis_config = self.container.config.get('REDIS', {}) self._notification_events = redis_config.get('notification_events') self._backoff_factor = redis_config.get( 'pubsub_backoff_factor', DEFAULT_BACKOFF_FACTOR ) super().setup()
def setup(self): try: config = self.container.config[constants.CONFIG_KEY] except KeyError: raise ConfigurationError('`{}` config key not found'.format( constants.CONFIG_KEY)) if self.bot_name: try: token = config['BOTS'][self.bot_name] except KeyError: raise ConfigurationError( 'No token for `{}` bot in `{}` config'.format( self.bot_name, constants.CONFIG_KEY)) else: token = (config.get('BOTS', {}).get(constants.DEFAULT_BOT_NAME) or config.get('TOKEN')) if not token: raise ConfigurationError('No token provided by `{}` config'.format( constants.CONFIG_KEY)) self.client = SlackClient(token)
def setup(self): try: config = self.container.config[constants.CONFIG_KEY] except KeyError: raise ConfigurationError( '`{}` config key not found'.format(constants.CONFIG_KEY)) try: username = config['USERNAME'] password = config['PASSWORD'] security_token = config['SECURITY_TOKEN'] sandbox = config['SANDBOX'] except KeyError as exc: raise ConfigurationError( '`{}` configuration does not contain mandatory ' '`{}` key'.format(constants.CONFIG_KEY, exc.args[0]) ) from exc api_version = config.get('API_VERSION', constants.DEFAULT_API_VERSION) self.client = get_client( username, password, security_token, sandbox=sandbox, api_version=api_version)
def setup(self): structlog_config = self.container.config.get(STRUCTLOG_CONFIG_KEY, {}) self.processor_name = structlog_config.get(PROCESSOR_NAME_KEY, JSON_PROCESSOR) if self.processor_name not in SUPPORTED_PROCESSORS: raise ConfigurationError( "Invalid `{processor_key}` provided. Valid ones are: {supported}." .format( processor_key=PROCESSOR_NAME_KEY, supported=SUPPORTED_PROCESSORS, )) self.processor_options = structlog_config.get(PROCESSOR_OPTIONS_KEY, {}) self.include_worker_name = structlog_config.get( INCLUDE_WORKER_NAME_KEY, True) self.include_log_transaction_id = structlog_config.get( INCLUDE_LOG_TRANSACTION_ID_KEY, True) self.extra_params = structlog_config.get(PARAMETERS_KEY, {})
def _setup_connection(self): if self.connection is not None: try: self.connection.close() except (socket.error, IOError): # pragma: no cover # If the socket has been closed, an IOError is raised, ignore # it and assume the connection is already closed. pass amqp_uri = self.provider.container.config[AMQP_URI_CONFIG_KEY] ssl = self.provider.container.config.get(AMQP_SSL_CONFIG_KEY) self.heartbeat = self.provider.container.config.get( HEARTBEAT_CONFIG_KEY, None # default to not enable heartbeat ) if self.heartbeat is not None and self.heartbeat < 0: raise ConfigurationError("value for '%s' can not be negative" % HEARTBEAT_CONFIG_KEY) self.connection = Connection(amqp_uri, ssl=ssl, heartbeat=self.heartbeat)
def setup(config): serializers = deepcopy(config.get(SERIALIZERS_CONFIG_KEY, {})) for name, kwargs in serializers.items(): encoder = import_from_path(kwargs.pop('encoder')) decoder = import_from_path(kwargs.pop('decoder')) kombu.serialization.register(name, encoder=encoder, decoder=decoder, **kwargs) serializer = config.get(SERIALIZER_CONFIG_KEY, DEFAULT_SERIALIZER) accept = config.get(ACCEPT_CONFIG_KEY, [serializer]) for name in [serializer] + accept: try: kombu.serialization.registry.name_to_type[name] except KeyError: raise ConfigurationError( 'Please register a serializer for "{}" format'.format(name)) return serializer, accept
def setup(self): secret = config.get("JWT_SECRET") if not secret: raise ConfigurationError("Not found `JWT_SECRET`.") self.secret = secret