Esempio n. 1
0
def is_valid_alexa_skill_webhook_event(event, request):
    """Determines whether the Alexa skill webhook event is valid

    Mutates `event` by adding `webhook_request` if valid
    """
    is_valid = True
    if is_valid:
        from htk.utils.request import get_request_metadata
        event['webhook_request'] = get_request_metadata(request)
    return is_valid
Esempio n. 2
0
def is_valid_alexa_skill_webhook_event(event, request):
    """Determines whether the Alexa skill webhook event is valid

    Mutates `event` by adding `webhook_request` if valid
    """
    is_valid = True
    if is_valid:
        from htk.utils.request import get_request_metadata
        event['webhook_request'] = get_request_metadata(request)
    return is_valid
Esempio n. 3
0
def is_valid_webhook_event(event, request):
    """Determines whether the Slack webhook event has a valid token

    Mutates `event` by adding `webhook_settings` if available, and `webhook_request` if valid
    """
    token = event['token']
    expected_token = htk_setting('HTK_SLACK_WEBHOOK_TOKEN')
    is_valid = token == expected_token
    webhook_settings = get_webhook_settings(token)
    event['webhook_settings'] = webhook_settings
    if not is_valid:
        # can still be valid if it has webhook settings for this token
        is_valid = webhook_settings is not None
    else:
        # it's really invalid
        pass
    if is_valid:
        from htk.utils.request import get_request_metadata
        event['webhook_request'] = get_request_metadata(request)
    return is_valid
Esempio n. 4
0
def is_valid_webhook_event(event, request):
    """Determines whether the Slack webhook event has a valid token

    Mutates `event` by adding `webhook_settings` if available, and `webhook_request` if valid
    """
    token = event['token']
    expected_token = htk_setting('HTK_SLACK_WEBHOOK_TOKEN')
    is_valid = token == expected_token
    webhook_settings = get_webhook_settings(token)
    event['webhook_settings'] = webhook_settings
    if not is_valid:
        # can still be valid if it has webhook settings for this token
        is_valid = webhook_settings is not None
    else:
        # it's really invalid
        pass
    if is_valid:
        from htk.utils.request import get_request_metadata
        event['webhook_request'] = get_request_metadata(request)
    return is_valid
Esempio n. 5
0
def wrap_data(request, data=None):
    """Puts commonly used values into the template context dictionary, `data`
    """
    if data is None:
        data = {}

    # CSRF Token
    data.update(csrf(request))

    ##
    # meta, server, request info
    from htk.utils.request import get_request_metadata
    data['request'] = get_request_metadata(request)
    data['server'] = {
        'hostname': gethostname(),
    }

    data['site_name'] = htk_setting('HTK_SITE_NAME')

    data['meta'] = {
        'title': {
            'content': '',
            'inverted': [],
            'join_value': ' | ',
            'static_values': {},
        },
        'breadcrumbs': {
            'url_names_to_breadcrumbs': {},
        },
        'description': {
            'content': '',
            'inverted': [],
            'join_value': ' ',
            'static_values': {},
        },
        'keywords': {
            'content': '',
            'inverted': [],
            'join_value': ',',
            'static_values': {},
        },
        'site_verifications': {},
    }

    data['privacy_url_name'] = 'privacy'
    data['robots_url_name'] = 'robots'

    ##
    # Rollbar
    data['rollbar'] = {
        'env':
        settings.ROLLBAR_ENV,
        'branch':
        settings.ROLLBAR.get('branch', 'master'),
        'tokens': {
            'post_client_item': settings.ROLLBAR_TOKEN_POST_CLIENT_ITEM,
        },
        'host_blacklist':
        settings.ROLLBAR.get('host_blacklist', None),
        'host_whitelist':
        settings.ROLLBAR.get('host_whitelist', None),
        'ignored_messages':
        settings.ROLLBAR.get('ignored_messages', None),
        'ignored_messages_regexes':
        settings.ROLLBAR.get('ignored_messages_regexes', None),
        'ignored_uncaught_exception_classes':
        settings.ROLLBAR.get('ignored_uncaught_exception_classes', None),
    }

    ##
    # LESS http://lesscss.org/#usage
    asset_version = get_asset_version()
    css_ext = '%s?v=%s' % (
        htk_setting('HTK_CSS_EXTENSION'),
        asset_version,
    )
    useless = settings.ENV_DEV and request.GET.get('useless', False)
    data['css_rel'] = 'stylesheet/less' if useless else 'stylesheet'
    data['css_ext'] = 'less' if useless else css_ext
    data['asset_version'] = asset_version

    ##
    # Current Environment
    data['ENV_DEV'] = settings.ENV_DEV
    data['ENV_PROD'] = settings.ENV_PROD

    ##
    # Javascript reloader
    _javascript_reloader(request, data)

    ##
    # user
    if request.user.is_authenticated():
        user = request.user
    else:
        user = None
    data['user'] = user

    ##
    # errors
    data['errors'] = []

    return data
Esempio n. 6
0
def wrap_data(request, data=None):
    """Puts commonly used values into the template context dictionary, `data`
    """
    if data is None:
        data = {}

    # CSRF Token
    data.update(csrf(request))

    ##
    # meta, server, request info
    from htk.utils.request import get_request_metadata
    data['request'] = get_request_metadata(request)
    data['server'] = {
        'hostname' : gethostname(),
    }

    data['site_name'] = htk_setting('HTK_SITE_NAME')

    data['meta'] = {
        'title' : {
            'content' : '',
            'inverted' : [],
            'join_value' : ' | ',
            'static_values' : {},
        },
        'breadcrumbs' : {
            'url_names_to_breadcrumbs' : {},
        },
        'description' : {
            'content' : '',
            'inverted' : [],
            'join_value' : ' ',
            'static_values' : {},
         },
        'keywords' : {
            'content' : '',
            'inverted' : [],
            'join_value' : ',',
            'static_values' : {},
        },
        'site_verifications' : {},
    }

    data['privacy_url_name'] = 'privacy'
    data['robots_url_name'] = 'robots'

    ##
    # Rollbar
    data['rollbar'] = {
        'env' : settings.ROLLBAR_ENV,
        'branch' : settings.ROLLBAR.get('branch', 'master'),
        'tokens' : {
            'post_client_item' : settings.ROLLBAR_TOKEN_POST_CLIENT_ITEM,
        },
        'host_blacklist' : settings.ROLLBAR.get('host_blacklist', None),
        'host_whitelist' : settings.ROLLBAR.get('host_whitelist', None),
        'ignored_messages' : settings.ROLLBAR.get('ignored_messages', None),
        'ignored_messages_regexes' : settings.ROLLBAR.get('ignored_messages_regexes', None),
        'ignored_uncaught_exception_classes' : settings.ROLLBAR.get('ignored_uncaught_exception_classes', None),
    }

    ##
    # LESS http://lesscss.org/#usage
    asset_version = get_asset_version()
    css_ext = '%s?v=%s' % (htk_setting('HTK_CSS_EXTENSION'), asset_version,)
    useless = settings.ENV_DEV and request.GET.get('useless', False)
    data['css_rel'] = 'stylesheet/less' if useless else 'stylesheet'
    data['css_ext'] = 'less' if useless else css_ext
    data['asset_version'] = asset_version

    ##
    # Current Environment
    data['ENV_DEV'] = settings.ENV_DEV
    data['ENV_PROD'] = settings.ENV_PROD

    ##
    # Javascript reloader
    _javascript_reloader(request, data)

    ##
    # user
    if request.user.is_authenticated():
        user = request.user
    else:
        user = None
    data['user'] = user

    ##
    # errors
    data['errors'] = []

    return data