Fix #3066: Superset Auth Fixed (#3156)

This commit is contained in:
Mayur Singal 2022-03-05 01:32:51 +05:30 committed by GitHub
parent ad341e8259
commit cd6b28df1a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 13 deletions

View File

@ -58,7 +58,13 @@ class SupersetAuthenticationProvider(AuthenticationProvider):
def __init__(self, config: SupersetConfig):
self.config = config
client_config = ClientConfig(base_url=config.url, api_version="api/v1")
client_config = ClientConfig(
base_url=config.url,
api_version="api/v1",
auth_token=lambda: ("no_token", 0),
auth_header="Authorization",
allow_redirects=True,
)
self.client = REST(client_config)
super().__init__()
@ -69,7 +75,8 @@ class SupersetAuthenticationProvider(AuthenticationProvider):
def auth_token(self) -> str:
login_request = self._login_request()
login_response = self.client.post("/security/login", login_request)
return login_response["access_token"]
self.generated_auth_token = login_response["access_token"]
self.expiry = 0
def _login_request(self) -> str:
auth_request = {
@ -80,6 +87,10 @@ class SupersetAuthenticationProvider(AuthenticationProvider):
}
return json.dumps(auth_request)
def get_access_token(self):
self.auth_token()
return (self.generated_auth_token, self.expiry)
class SupersetAPIClient:
"""
@ -95,7 +106,7 @@ class SupersetAPIClient:
client_config = ClientConfig(
base_url=config.url,
api_version="api/v1",
auth_token=f"{self._auth_provider.auth_token()}",
auth_token=lambda: self._auth_provider.get_access_token(),
auth_header="Authorization",
allow_redirects=True,
)

View File

@ -278,17 +278,18 @@ class SupersetSource(Source[Entity]):
entity=Lineage_Dashboard,
fqdn=f"{self.config.service_name}.{dashboard['id']}",
)
lineage = AddLineageRequest(
edge=EntitiesEdge(
fromEntity=EntityReference(
id=from_entity.id.__root__, type="table"
),
toEntity=EntityReference(
id=to_entity.id.__root__, type="dashboard"
),
if from_entity and to_entity:
lineage = AddLineageRequest(
edge=EntitiesEdge(
fromEntity=EntityReference(
id=from_entity.id.__root__, type="table"
),
toEntity=EntityReference(
id=to_entity.id.__root__, type="dashboard"
),
)
)
)
yield lineage
yield lineage
except Exception as err:
logger.debug(traceback.print_exc())