-
Notifications
You must be signed in to change notification settings - Fork 14.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added access check + Druid in endpoint #1224
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,10 @@ | |
log_this = models.Log.log_this | ||
can_access = utils.can_access | ||
QueryStatus = models.QueryStatus | ||
DRUID_TIME_GRAINS = [ | ||
'all', '5 seconds', '30 seconds', '1 minute', | ||
'5 minutes', '1 hour', '6 hour', '1 day', '7 days' | ||
] | ||
|
||
|
||
class BaseCaravelView(BaseView): | ||
|
@@ -1297,6 +1301,7 @@ def exploreV2(self, datasource_type, datasource_id, slice_id=None): | |
"datasources": [(d.id, d.full_name) for d in datasources], | ||
"datasource_id": datasource_id, | ||
"datasource_type": datasource_type, | ||
"datasource_class": datasource_class.__name__, | ||
"user_id": g.user.get_id() if g.user else None, | ||
"viz": json.loads(viz_obj.get_json()) | ||
} | ||
|
@@ -1942,8 +1947,6 @@ def csv(self, client_id): | |
@expose("/fetch_datasource_metadata") | ||
@log_this | ||
def fetch_datasource_metadata(self): | ||
# TODO: check permissions | ||
# TODO: check if datasource exits | ||
session = db.session | ||
datasource_type = request.args.get('datasource_type') | ||
datasource_class = SourceRegistry.sources[datasource_type] | ||
|
@@ -1952,17 +1955,34 @@ def fetch_datasource_metadata(self): | |
.filter_by(id=request.args.get('datasource_id')) | ||
.first() | ||
) | ||
# SUPPORT DRUID | ||
# TODO: move this logic to the model (maybe) | ||
datasource_grains = datasource.database.grains() | ||
grain_names = [str(grain.name) for grain in datasource_grains] | ||
|
||
# Check if datasource exists | ||
if not datasource: | ||
return json_error_response(DATASOURCE_MISSING_ERR) | ||
# Check permission for datasource | ||
if not self.datasource_access(datasource): | ||
return json_error_response(DATASOURCE_ACCESS_ERR) | ||
|
||
time_columns = [] | ||
grains_choices = [] | ||
datasource_class_name = datasource_class.__name__ | ||
if datasource_class_name == 'SqlaTable': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please use |
||
time_columns = datasource.dttm_cols | ||
grains = datasource.database.grains() | ||
grains_choices = [grain.name for grain in grains] | ||
elif datasource_class_name == 'DruidDatasource': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please implement |
||
time_columns = DRUID_TIME_GRAINS | ||
grains_choices = ['now'] | ||
|
||
form_data = { | ||
"dttm_cols": datasource.dttm_cols, | ||
"time_grains": grain_names, | ||
"groupby_cols": datasource.groupby_column_names, | ||
"metrics": datasource.metrics_combo, | ||
"filter_cols": datasource.filterable_column_names, | ||
} | ||
"datasource_class": datasource_class_name, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use datasource_type instead of datasource_class here |
||
"time_columns": time_columns, | ||
"time_grains": grains_choices, | ||
"groupby_cols": datasource.groupby_column_names, | ||
"metrics": datasource.metrics_combo, | ||
"filter_cols": datasource.filterable_column_names, | ||
} | ||
|
||
return Response( | ||
json.dumps(form_data), mimetype="application/json") | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it belongs to models, DruidDatasource class