forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(cherry picked from commit 9b3420c8ef51739206282514ca4a69fb01a2066f) (cherry picked from commit 2df0fb8d286616cd4d5b9f582d337c726edd1d7a) (cherry picked from commit 2829ead) (cherry picked from commit ac9dbef)
- Loading branch information
1 parent
189f5d8
commit 0c32389
Showing
3 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from . import lyft # noqa | ||
from . import base # noqa | ||
from . import api # noqa | ||
from . import core # noqa | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
from flask import g, request, Response | ||
from flask_appbuilder import expose | ||
|
||
from superset import app, appbuilder, security_manager | ||
from superset.exceptions import SupersetException | ||
import superset.models.core as models | ||
from superset.views.core import Superset | ||
from .base import json_error_response | ||
|
||
config = app.config | ||
stats_logger = config.get('STATS_LOGGER') | ||
log_this = models.Log.log_this | ||
DAR = models.DatasourceAccessRequest | ||
|
||
|
||
class UserDontExistException(SupersetException): | ||
pass | ||
|
||
|
||
def json_success(json_msg, status=200): | ||
return Response(json_msg, status=status, mimetype='application/json') | ||
|
||
|
||
class Lyft(Superset): | ||
@staticmethod | ||
def authorize(): | ||
"""Provides access if token, impersonates if specified""" | ||
if not security_manager.has_tom_key(): | ||
raise SupersetException('Wrong key') | ||
|
||
email = request.headers.get('IMPERSONATE') | ||
if email: | ||
user = security_manager.find_user(email=email) | ||
if not user: | ||
raise UserDontExistException('Email to impersonate not found') | ||
g.user = user | ||
|
||
@expose('/sql_json/', methods=['POST', 'GET']) | ||
@log_this | ||
def sql_json(self): | ||
try: | ||
Lyft.authorize() | ||
except UserDontExistException as e: | ||
return json_error_response('{}'.format(e), status=412) | ||
except SupersetException as e: | ||
return json_error_response('{}'.format(e)) | ||
return self.sql_json_call(request) | ||
|
||
|
||
appbuilder.add_view_no_menu(Lyft) |