forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
03b8d8f
commit 506504d
Showing
10 changed files
with
209 additions
and
48 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
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 was deleted.
Oops, something went wrong.
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
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,16 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. |
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,120 @@ | ||
import logging | ||
import boto3 | ||
|
||
|
||
import simplejson as json | ||
from flask import Response, request | ||
from flask_appbuilder.api import expose, protect, safe | ||
from flask_appbuilder.security.decorators import permission_name | ||
|
||
from superset import app | ||
from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP | ||
|
||
from superset.extensions import event_logger | ||
|
||
from superset.utils import core as utils | ||
from superset.views.base import json_success | ||
from superset.views.base_api import BaseSupersetApi, statsd_metrics, requires_json | ||
from superset.sfrestapi.schemas import SFRestAPIListBucketSchema | ||
|
||
# config = app.config | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class SFRestAPI(BaseSupersetApi): | ||
class_permission_name = "AdvancedDataType" | ||
method_permission_name = MODEL_API_RW_METHOD_PERMISSION_MAP | ||
|
||
resource_name = "sfrestapi" | ||
allow_browser_login = True | ||
openapi_spec_tag = "SF Rest API" | ||
openapi_spec_component_schemas = (SFRestAPIListBucketSchema,) | ||
|
||
@expose("/list-s3-buckets", methods=("GET",)) | ||
@protect() | ||
@safe | ||
@statsd_metrics | ||
@event_logger.log_this | ||
def get(self) -> Response: | ||
"""List all Buckets in account | ||
--- | ||
get: | ||
summary: Get the list of all buckets in account. | ||
description: >- | ||
List of All S3 Buckets as an array | ||
responses: | ||
200: | ||
description: Returns the list of all buckets in account. | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/SFRestAPIListBucketSchema' | ||
400: | ||
$ref: '#/components/responses/400' | ||
401: | ||
$ref: '#/components/responses/401' | ||
403: | ||
$ref: '#/components/responses/403' | ||
500: | ||
$ref: '#/components/responses/500' | ||
""" | ||
|
||
logger.info("============================================================") | ||
s3 = boto3.client("s3") | ||
response = s3.list_buckets() | ||
buckets = [] | ||
for bucket in response["Buckets"]: | ||
buckets.append(bucket["Name"]) | ||
return json_success( | ||
json.dumps( | ||
{"buckets": buckets}, | ||
default=utils.json_iso_dttm_ser, | ||
ignore_nan=True, | ||
), | ||
200, | ||
) | ||
|
||
@expose("/test-post", methods=("POST",)) | ||
@statsd_metrics | ||
@requires_json | ||
@event_logger.log_this | ||
@protect() | ||
def test_post(self) -> Response: | ||
"""Estimate the SQL query execution cost. | ||
--- | ||
post: | ||
summary: Estimate the SQL query execution cost | ||
requestBody: | ||
description: SQL query and params | ||
required: true | ||
content: | ||
application/json: | ||
schema: | ||
$ref: '#/components/schemas/EstimateQueryCostSchema' | ||
responses: | ||
200: | ||
description: Query estimation result | ||
content: | ||
application/json: | ||
schema: | ||
type: object | ||
properties: | ||
result: | ||
type: object | ||
400: | ||
$ref: '#/components/responses/400' | ||
401: | ||
$ref: '#/components/responses/401' | ||
403: | ||
$ref: '#/components/responses/403' | ||
500: | ||
$ref: '#/components/responses/500' | ||
""" | ||
return json_success( | ||
json.dumps( | ||
{"request": request.json}, | ||
default=utils.json_iso_dttm_ser, | ||
ignore_nan=True, | ||
), | ||
200, | ||
) |
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,4 @@ | ||
from marshmallow import fields, Schema | ||
|
||
class SFRestAPIListBucketSchema(Schema): | ||
buckets = fields.List(fields.String()) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.