mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat: improve GSheets OAuth2 (#32048)
This commit is contained in:
@@ -67,6 +67,18 @@ class GSheetsParametersSchema(Schema):
|
||||
"field_name": "service_account_info",
|
||||
},
|
||||
)
|
||||
oauth2_client_info = EncryptedString(
|
||||
required=False,
|
||||
metadata={
|
||||
"description": "OAuth2 client information",
|
||||
"default": {
|
||||
"scope": " ".join(SCOPES),
|
||||
"authorization_request_uri": "https://accounts.google.com/o/oauth2/v2/auth",
|
||||
"token_request_uri": "https://oauth2.googleapis.com/token",
|
||||
},
|
||||
},
|
||||
allow_none=True,
|
||||
)
|
||||
|
||||
|
||||
class GSheetsParametersType(TypedDict):
|
||||
@@ -165,8 +177,22 @@ class GSheetsEngineSpec(ShillelaghEngineSpec):
|
||||
_: GSheetsParametersType,
|
||||
encrypted_extra: None | (dict[str, Any]) = None,
|
||||
) -> str:
|
||||
if encrypted_extra and "oauth2_client_info" in encrypted_extra:
|
||||
del encrypted_extra["oauth2_client_info"]
|
||||
|
||||
return "gsheets://"
|
||||
|
||||
@staticmethod
|
||||
def update_params_from_encrypted_extra(
|
||||
database: Database,
|
||||
params: dict[str, Any],
|
||||
) -> None:
|
||||
"""
|
||||
Remove `oauth2_client_info` from `encrypted_extra`.
|
||||
"""
|
||||
if "oauth2_client_info" in params.get("encrypted_extra", {}):
|
||||
del params["encrypted_extra"]["oauth2_client_info"]
|
||||
|
||||
@classmethod
|
||||
def get_parameters_from_uri(
|
||||
cls,
|
||||
@@ -210,9 +236,9 @@ class GSheetsEngineSpec(ShillelaghEngineSpec):
|
||||
# via parameters for validation
|
||||
parameters = properties.get("parameters", {})
|
||||
if parameters and parameters.get("catalog"):
|
||||
table_catalog = parameters.get("catalog", {})
|
||||
table_catalog = parameters.get("catalog") or {}
|
||||
else:
|
||||
table_catalog = properties.get("catalog", {})
|
||||
table_catalog = properties.get("catalog") or {}
|
||||
|
||||
encrypted_credentials = parameters.get("service_account_info") or "{}"
|
||||
|
||||
@@ -221,18 +247,6 @@ class GSheetsEngineSpec(ShillelaghEngineSpec):
|
||||
if isinstance(encrypted_credentials, str):
|
||||
encrypted_credentials = json.loads(encrypted_credentials)
|
||||
|
||||
if not table_catalog:
|
||||
# Allowing users to submit empty catalogs
|
||||
errors.append(
|
||||
SupersetError(
|
||||
message="Sheet name is required",
|
||||
error_type=SupersetErrorType.CONNECTION_MISSING_PARAMETERS_ERROR,
|
||||
level=ErrorLevel.WARNING,
|
||||
extra={"catalog": {"idx": 0, "name": True}},
|
||||
),
|
||||
)
|
||||
return errors
|
||||
|
||||
# We need a subject in case domain wide delegation is set, otherwise the
|
||||
# check will fail. This means that the admin will be able to add sheets
|
||||
# that only they have access, even if later users are not able to access
|
||||
|
||||
Reference in New Issue
Block a user