def wrapper(*args, **kwargs): get_logger('Flask').debug( f'Request args: {request.get_json() or request.form}') payload = { 'application/json': lambda: request.get_json(), 'application/x-www-form-urlencoded': lambda: json.loads(request.form['payload']) if 'payload' in request.form else request.form, }[request.headers.environ.get('CONTENT_TYPE')]() if payload['token'] not in current_app.slack_verification_tokens: message = 'Invalid slack verification token' get_logger('Flask').error(message) raise UnauthorizedException(message=message) return func(*args, **kwargs)
def handle_local_exception(error): logger = get_logger('Flask') response = jsonify( {'error': error.message if error.message else repr(error)}) response.status_code = HTTPStatus.INTERNAL_SERVER_ERROR logger.error(response.data) return response
def __init__(self, strand_api_client): self.strand_api_client = strand_api_client self.logger = get_logger('StrandApiClientWrapper') self.standard_retrier = Retrying( reraise=True, wait=wait_fixed(2), stop=stop_after_attempt(5), after=after_log(logger=self.logger, log_level=self.logger.getEffectiveLevel()), retry=retry_if_exception_type(StrandApiClientException))
def __init__(self, SlackClientClass): self.SlackClientClass = SlackClientClass self.logger = get_logger('SlackClientWrapper') self.standard_retrier = Retrying( reraise=True, wait=wait_fixed(2), stop=stop_after_attempt(5), after=after_log(logger=self.logger, log_level=self.logger.getEffectiveLevel()), retry=(retry_if_exception_type(ConnectionError)))
def handle_validation_exception(error): logger = get_logger('Flask') response = jsonify({'error': error.messages}) response.status_code = HTTPStatus.BAD_REQUEST logger.error(response.data) return response
def __init__(self, **kwargs): self.logger = get_logger('TestCoreApiClient')
def __init__(self, token, *args, **kwargs): self.token = token self.logger = get_logger('TestSlackClient')
def __init__(self, slack_client_wrapper=None, strand_api_client_wrapper=None): self.slack_client_wrapper = slack_client_wrapper self.strand_api_client_wrapper = strand_api_client_wrapper self.logger = get_logger(self.__class__.__name__)
def log_test_start(): logger = get_logger('Fixtures') logger.info('******** TEST START ********') yield logger.info('******** TEST END ********')
def __init__(self): self.logger = get_logger(self.__class__.__name__)