-
Notifications
You must be signed in to change notification settings - Fork 26
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
superset-cli does not work with superset 3.0.0 #244
Comments
setting |
Sample command along with logs from
|
Having exactly the same issue, I believe it's to do with redirects. I've had some success getting it to at least auth with JWT by ensuring there's no redirect for the trailing # auth/superset.py
...
class SupersetJWTAuth(TokenAuth): # pylint: disable=abstract-method
...
- response = self.session.get(
- self.baseurl / "api/v1/security/csrf_token/", # type: ignore
- headers={"Authorization": f"Bearer {jwt}"},
- )
+ url = str(self.baseurl / "api/v1/security/csrf_token/")
+ url = str(url).endswith("/") and str(url) or str(url) + "/"
+ response = self.session.get(
+ url, # type: ignore
+ headers={"Authorization": f"Bearer {jwt}"},
+ )
... This avoids the redirect due to That gets me a bit farther, but it then bombs at the next hurdle due to an https request getting redirected to http by superset, I'm not sure if this then is a superset issue instead of superset-cli. Logs before change:
Logs after change:
Ok, so it's more redirect stuff (see the 301). Keep changing stuff to not redirect: # api/clients/superset.py
...
def get_resources(self, resource_name: str, **kwargs: Any) -> List[Any]:
...
url = self.baseurl / "api/v1" / resource_name / "" % {"q": query}
+ url = str(url)
+ url = url.replace("?", "/?").replace("//?", "/?")
...
...
def create_resource(self, resource_name: str, **kwargs: Any) -> Any:
"""
Create a resource.
"""
url = self.baseurl / "api/v1" / resource_name / ""
+ url = str(url)
+ url = url.endswith("/") and url or url + "/"
... Lots after this change (sync seems to work 🎉 ):
This is obviously the wrong solution, it should work with redirects, but at least this shows that that is where the issue is. See here for linked superset issue: apache/superset#25359 |
I've had success patching issues to connect to my Superset instance. There central fix was to modify the Can PR this as is, but I'm guessing you would wanna implement it cleaner: class UsernamePasswordAuth(Auth): # pylint: disable=too-few-public-methods
"""
Auth to Superset via username/password.
"""
def __init__(self, baseurl: URL, username: str, password: Optional[str] = None):
super().__init__()
self.csrf_token: Optional[str] = None
self.baseurl = baseurl
self.username = username
self.password = password
self.token = None
self.auth()
def get_headers(self) -> Dict[str, str]:
headers = {}
if self.token:
headers["Authorization"] = f"Bearer {self.token}"
if self.csrf_token:
headers["X-CSRFToken"] = self.csrf_token
return headers
def auth(self) -> None:
self._login_and_store_csrf()
self._fetch_and_store_token()
def _login_and_store_csrf(self) -> None:
"""
Login to get CSRF token and set cookies.
"""
data = {"username": self.username, "password": self.password}
response = self.session.get(self.baseurl / "login/")
soup = BeautifulSoup(response.text, "html.parser")
input_ = soup.find("input", {"id": "csrf_token"})
csrf_token = input_["value"] if input_ else None
if csrf_token:
self.session.headers["X-CSRFToken"] = csrf_token
data["csrf_token"] = csrf_token
self.csrf_token = csrf_token
# set cookies
self.session.post(self.baseurl / "login/", data=data)
def _fetch_and_store_token(self) -> None:
"""
Fetch the JWT token to use for headers
"""
data = {
"username": self.username,
"password": self.password,
"provider":"db",
"refresh":True,
}
api_login_url = self.baseurl / "api/v1/security/login"
response = self.session.post(api_login_url, json=data)
self.token = response.json()['access_token'] Note I did originally see similar issues with redirects to the trailing slash url and did make some tweaks to that but I'm not certain they're critical. Possibly. The missing Auth header was the key issue I discovered. |
Looks like
import-assets
andsync
commands insuperset-cli (0.2.8)
do not work with superset version3.0.0
Tried it with both basic authentication and jwt. Works with 2.1.0 but fails on 3.0.0.
Sample command:
superset-cli --jwt-token {jwt_token} --loglevel debug {HOST} sync native ./
The error
When using jwt-token, line 736 in superset.py returns a response object that contains HTML (authentication failed) so it fails in line 742 when trying to extract json
When using basic auth it fails even earlier
The text was updated successfully, but these errors were encountered: