Skip to content

Commit

Permalink
Lyft-specific views
Browse files Browse the repository at this point in the history
(cherry picked from commit 1a7362708cf7953c1cb61e8e3c492e3522659ea7)
(cherry picked from commit bc1e2a1)
(cherry picked from commit 7c664e4)
  • Loading branch information
mistercrunch authored and hughhhh committed Aug 14, 2018
1 parent f8b7e4a commit effa317
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions superset/views/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from . import lyft # noqa
from . import base # noqa
from . import core # noqa
from . import sql_lab # noqa
Expand Down
54 changes: 54 additions & 0 deletions superset/views/lyft.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import os
import logging
from flask import Response, request
from flask_babel import gettext as __
from flask_appbuilder import expose
from flask_appbuilder.security.decorators import has_access_api

from superset import app, appbuilder, utils
import superset.models.core as models
from superset.views.core import Superset

config = app.config
stats_logger = config.get('STATS_LOGGER')
log_this = models.Log.log_this
DAR = models.DatasourceAccessRequest


ALL_DATASOURCE_ACCESS_ERR = __(
'This endpoint requires the `all_datasource_access` permission')
DATASOURCE_MISSING_ERR = __('The datasource seems to have been deleted')
ACCESS_REQUEST_MISSING_ERR = __(
'The access requests seem to have been deleted')
USER_MISSING_ERR = __('The user seems to have been deleted')
DATASOURCE_ACCESS_ERR = __("You don't have access to this datasource")
SECRET_KEY = os.getenv("CREDENTIALS_SUPERSET_SECRET_KEY") or None


def json_success(json_msg, status=200):
return Response(json_msg, status=status, mimetype='application/json')


class Lyft(Superset):

def datasource_access(self, datasource, user=None):
if SECRET_KEY is None:
logging.error('No secret loaded')
return False

tom_request_key = request.headers.get('TOM_ACCESS_KEY')
return tom_request_key == SECRET_KEY

@has_access_api
@expose('/sql_json/', methods=['POST', 'GET'])
@log_this
def sql_json(self):
return super(Lyft, self).sql_json()


appbuilder.add_view_no_menu(Lyft)

0 comments on commit effa317

Please sign in to comment.