Skip to content

Commit

Permalink
Update for apache-superset 0.37.0 (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga authored Sep 10, 2020
1 parent ef4edfa commit 26b183f
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 86 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ OAUTH_PROVIDERS = [
'icon': 'fa-rebel',
'token_key': 'access_token',
'remote_app': {
'consumer_key': 'consumer key goes here',
'consumer_secret': 'consumer secret goes here',
'base_url': 'https://stage-api.ona.io/',
'client_id': 'consumer key goes here',
'client_secret': 'consumer secret goes here',
'api_base_url': 'https://stage-api.ona.io/',
'access_token_url': 'https://stage-api.ona.io/o/token/',
'authorize_url': 'https://stage-api.ona.io/o/authorize/'
}
Expand Down Expand Up @@ -73,9 +73,9 @@ OAUTH_PROVIDERS = [
'icon': 'fa-eercast',
'token_key': 'access_token',
'remote_app': {
'consumer_key': 'consumer key goes here',
'consumer_secret': 'consumer secret goes here'
'base_url': 'https://stage-api.ona.io/',
'client_id': 'consumer key goes here',
'client_secret': 'consumer secret goes here'
'api_base_url': 'https://stage-api.ona.io/',
'access_token_url': 'https://stage-api.ona.io/o/token/',
'authorize_url': 'https://stage-api.ona.io/o/authorize/',
# the redirect url is set below, it needs to be on the same domain as superset
Expand Down
126 changes: 72 additions & 54 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,135 +4,153 @@
#
# pip-compile --output-file=requirements/dev.txt requirements/dev.in
#
aiohttp==3.6.2 # via slackclient
alembic==1.4.2 # via flask-migrate
amqp==2.6.0 # via kombu
apache-superset==0.36.0 # via superset-patchup
apispec[yaml]==1.3.3 # via flask-appbuilder
amqp==2.6.1 # via kombu
apache-superset==0.37.0 # via superset-patchup
apispec[yaml]==3.3.2 # via flask-appbuilder
appdirs==1.4.4 # via black, virtualenv
astroid==2.4.1 # via pylint, pylint-flask
attrs==19.3.0 # via black, jsonschema, pytest
astroid==2.4.2 # via pylint, pylint-flask
async-timeout==3.0.1 # via aiohttp
attrs==20.1.0 # via aiohttp, jsonschema, pytest
authlib==0.14.3 # via superset-patchup
babel==2.8.0 # via flask-babel
backcall==0.1.0 # via ipython
backcall==0.2.0 # via ipython
backoff==1.10.0 # via apache-superset
billiard==3.6.3.0 # via celery
black==19.10b0 # via -r requirements/dev.in
black==20.8b1 # via -r requirements/dev.in
bleach==3.1.5 # via apache-superset
brotli==1.0.7 # via flask-compress
celery==4.4.4 # via apache-superset
cffi==1.14.0 # via cryptography
brotli==1.0.9 # via flask-compress
cachelib==0.1.1 # via apache-superset
celery==4.4.7 # via apache-superset
certifi==2020.6.20 # via requests
cffi==1.14.2 # via cryptography
chardet==3.0.4 # via aiohttp, requests
click==7.1.2 # via apache-superset, black, flask, flask-appbuilder, pip-tools
colorama==0.4.3 # via apache-superset, flask-appbuilder
contextlib2==0.6.0.post1 # via apache-superset
coverage==5.1 # via -r requirements/dev.in
croniter==0.3.32 # via apache-superset
cryptography==2.9.2 # via apache-superset
coverage==5.2.1 # via -r requirements/dev.in
croniter==0.3.34 # via apache-superset
cryptography==3.1 # via apache-superset, authlib
dataclasses==0.6 # via apache-superset, black
decorator==4.4.2 # via ipython, retry, traitlets
defusedxml==0.6.0 # via python3-openid
distlib==0.3.0 # via virtualenv
dnspython==1.16.0 # via email-validator
distlib==0.3.1 # via virtualenv
dnspython==2.0.0 # via email-validator
email-validator==1.1.1 # via flask-appbuilder
filelock==3.0.12 # via tox, virtualenv
flake8==3.8.2 # via -r requirements/dev.in
flask-appbuilder==2.3.4 # via apache-superset
flake8==3.8.3 # via -r requirements/dev.in
flask-appbuilder==3.0.1 # via apache-superset
flask-babel==1.0.0 # via flask-appbuilder
flask-caching==1.9.0 # via apache-superset
flask-compress==1.5.0 # via apache-superset
flask-jwt-extended==3.24.1 # via flask-appbuilder
flask-login==0.4.1 # via flask-appbuilder
flask-migrate==2.5.3 # via apache-superset
flask-openid==1.2.5 # via flask-appbuilder
flask-sqlalchemy==2.4.3 # via flask-appbuilder, flask-migrate
flask-sqlalchemy==2.4.4 # via flask-appbuilder, flask-migrate
flask-talisman==0.7.0 # via apache-superset
flask-testing==0.8.0 # via -r requirements/dev.in
flask-wtf==0.14.3 # via apache-superset, flask-appbuilder
flask==1.1.2 # via apache-superset, flask-appbuilder, flask-babel, flask-caching, flask-compress, flask-jwt-extended, flask-login, flask-migrate, flask-openid, flask-sqlalchemy, flask-testing, flask-wtf
future==0.18.2 # via superset-patchup
geographiclib==1.50 # via geopy
geopy==1.22.0 # via apache-superset
geopy==2.0.0 # via apache-superset
gunicorn==20.0.4 # via apache-superset
humanize==2.4.0 # via apache-superset
idna==2.9 # via email-validator
ipdb==0.13.2 # via -r requirements/dev.in
humanize==2.6.0 # via apache-superset
idna-ssl==1.1.0 # via aiohttp
idna==2.10 # via email-validator, idna-ssl, requests, yarl
importlib-metadata==1.7.0 # via flake8, jsonschema, kombu, markdown, pluggy, pytest, tox, virtualenv
importlib-resources==3.0.0 # via virtualenv
iniconfig==1.0.1 # via pytest
ipdb==0.13.3 # via -r requirements/dev.in
ipython-genutils==0.2.0 # via traitlets
ipython==7.15.0 # via ipdb
ipython==7.16.1 # via ipdb
isodate==0.6.0 # via apache-superset
isort==4.3.21 # via -r requirements/dev.in, pylint
isort==5.4.2 # via -r requirements/dev.in, pylint
itsdangerous==1.1.0 # via flask, flask-wtf
jedi==0.17.0 # via ipython
jedi==0.17.2 # via ipython
jinja2==2.11.2 # via flask, flask-babel
jsonschema==3.2.0 # via flask-appbuilder
kombu==4.6.10 # via celery
kombu==4.6.11 # via celery
lazy-object-proxy==1.4.3 # via astroid
mako==1.1.3 # via alembic
markdown==3.2.2 # via apache-superset
markupsafe==1.1.1 # via jinja2, mako, wtforms
marshmallow-enum==1.5.1 # via flask-appbuilder
marshmallow-sqlalchemy==0.23.1 # via flask-appbuilder
marshmallow==2.21.0 # via flask-appbuilder, marshmallow-enum, marshmallow-sqlalchemy
marshmallow==3.7.1 # via flask-appbuilder, marshmallow-enum, marshmallow-sqlalchemy
mccabe==0.6.1 # via flake8, pylint
more-itertools==8.3.0 # via pytest
msgpack==0.6.2 # via apache-superset
more-itertools==8.5.0 # via pytest
msgpack==1.0.0 # via apache-superset
multidict==4.7.6 # via aiohttp, yarl
mypy-extensions==0.4.3 # via black
natsort==7.0.1 # via croniter
numpy==1.18.5 # via pandas, pyarrow
numpy==1.19.1 # via pandas, pyarrow
packaging==20.4 # via bleach, pytest, tox
pandas==0.25.3 # via apache-superset
pandas==1.0.5 # via apache-superset
parsedatetime==2.6 # via apache-superset
parso==0.7.0 # via jedi
parso==0.7.1 # via jedi
pathlib2==2.3.5 # via apache-superset
pathspec==0.8.0 # via black
pep8==1.7.1 # via -r requirements/dev.in
pexpect==4.8.0 # via ipython
pickleshare==0.7.5 # via ipython
pip-tools==5.2.0 # via -r requirements/dev.in
pip-tools==5.3.1 # via -r requirements/dev.in
pluggy==0.13.1 # via pytest, tox
polyline==1.4.0 # via apache-superset
prison==0.1.3 # via flask-appbuilder
prompt-toolkit==3.0.5 # via ipython
prompt-toolkit==3.0.7 # via ipython
ptyprocess==0.6.0 # via pexpect
py==1.8.1 # via pytest, retry, tox
pyarrow==0.16.0 # via apache-superset
py==1.9.0 # via pytest, retry, tox
pyarrow==0.17.1 # via apache-superset
pycodestyle==2.6.0 # via flake8
pycparser==2.20 # via cffi
pydocstyle==5.0.2 # via -r requirements/dev.in
pydocstyle==5.1.1 # via -r requirements/dev.in
pyflakes==2.2.0 # via flake8
pygments==2.6.1 # via ipython
pyjwt==1.7.1 # via flask-appbuilder, flask-jwt-extended
pylint-flask==0.6 # via -r requirements/dev.in
pylint-plugin-utils==0.6 # via pylint-flask
pylint==2.5.2 # via -r requirements/dev.in, pylint-flask, pylint-plugin-utils
pylint==2.6.0 # via -r requirements/dev.in, pylint-flask, pylint-plugin-utils
pyparsing==2.4.7 # via packaging
pyrsistent==0.16.0 # via jsonschema
pytest==5.4.3 # via -r requirements/dev.in
pytest==6.0.1 # via -r requirements/dev.in
python-dateutil==2.8.1 # via alembic, apache-superset, croniter, flask-appbuilder, pandas
python-dotenv==0.13.0 # via apache-superset
python-dotenv==0.14.0 # via apache-superset
python-editor==1.0.4 # via alembic
python-geohash==0.8.5 # via apache-superset
python3-openid==3.1.0 # via flask-openid
python3-openid==3.2.0 # via flask-openid
pytz==2020.1 # via babel, celery, flask-babel, pandas
pyyaml==5.3.1 # via apache-superset, apispec
regex==2020.5.14 # via black
regex==2020.7.14 # via black
requests==2.24.0 # via superset-patchup
retry==0.9.2 # via apache-superset
selenium==3.141.0 # via apache-superset
simplejson==3.17.0 # via apache-superset
six==1.15.0 # via astroid, bleach, cryptography, flask-jwt-extended, flask-talisman, isodate, jsonschema, packaging, pathlib2, pip-tools, polyline, prison, pyarrow, pyrsistent, python-dateutil, sqlalchemy-utils, tox, traitlets, virtualenv, wtforms-json
simplejson==3.17.2 # via apache-superset
six==1.15.0 # via astroid, bleach, cryptography, flask-jwt-extended, flask-talisman, isodate, jsonschema, packaging, pathlib2, pip-tools, polyline, prison, pyrsistent, python-dateutil, sqlalchemy-utils, tox, traitlets, virtualenv, wtforms-json
slackclient==2.5.0 # via apache-superset
snowballstemmer==2.0.0 # via pydocstyle
sqlalchemy-utils==0.36.6 # via apache-superset, flask-appbuilder
sqlalchemy==1.3.17 # via alembic, apache-superset, flask-sqlalchemy, marshmallow-sqlalchemy, sqlalchemy-utils
sqlparse==0.3.1 # via apache-superset
toml==0.10.1 # via black, pylint, tox
tox==3.15.1 # via -r requirements/dev.in
sqlalchemy-utils==0.36.8 # via apache-superset, flask-appbuilder
sqlalchemy==1.3.19 # via alembic, apache-superset, flask-sqlalchemy, marshmallow-sqlalchemy, sqlalchemy-utils
sqlparse==0.3.0 # via apache-superset
toml==0.10.1 # via black, pylint, pytest, tox
tox==3.19.0 # via -r requirements/dev.in
traitlets==4.3.3 # via ipython
typed-ast==1.4.1 # via black
urllib3==1.25.9 # via selenium
typed-ast==1.4.1 # via astroid, black
typing-extensions==3.7.4.3 # via aiohttp, black, yarl
urllib3==1.25.10 # via requests, selenium
vine==1.3.0 # via amqp, celery
virtualenv==20.0.21 # via tox
wcwidth==0.2.3 # via prompt-toolkit, pytest
virtualenv==20.0.31 # via tox
wcwidth==0.2.5 # via prompt-toolkit
webencodings==0.5.1 # via bleach
werkzeug==1.0.1 # via flask, flask-jwt-extended
wrapt==1.12.1 # via astroid
wtforms-json==0.3.3 # via apache-superset
wtforms==2.3.1 # via flask-wtf, wtforms-json
wtforms==2.3.3 # via flask-wtf, wtforms-json
yapf==0.30.0 # via -r requirements/dev.in
yarl==1.5.1 # via aiohttp
zipp==3.1.0 # via importlib-metadata, importlib-resources

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
packages=find_packages(exclude=['docs', 'tests']),
install_requires=[
'apache-superset',
'authlib',
'future',
'requests',
],
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7'
'Programming Language :: Python :: 3.8'
],
)
23 changes: 11 additions & 12 deletions superset_patchup/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def login(self, provider=None, register=None):
logging.debug("Login to Register")
session["register"] = True
if provider == "twitter":
return self.appbuilder.sm.oauth_remotes[provider].authorize(
callback=url_for(
return self.appbuilder.sm.oauth_remotes[provider].authorize_redirect(
redirect_uri=url_for(
".oauth_authorized",
provider=provider,
_external=True,
Expand All @@ -68,9 +68,8 @@ def login(self, provider=None, register=None):
)
callback = url_for(".oauth_authorized", provider=provider, _external=True,
_scheme=scheme)
return self.appbuilder.sm.oauth_remotes[provider].authorize(
callback=callback,
state=state,
return self.appbuilder.sm.oauth_remotes[provider].authorize_redirect(
redirect_uri=callback,
)
except Exception as err: # pylint: disable=broad-except
logging.error(f"Error on OAuth authorize: {err}")
Expand Down Expand Up @@ -117,7 +116,7 @@ def oauth_authorized(self, provider):
"""View that a user is redirected to from the Oauth server"""

logging.debug("Authorized init")
resp = self.appbuilder.sm.oauth_remotes[provider].authorized_response()
resp = self.appbuilder.sm.oauth_remotes[provider].authorize_access_token()
if "Custom-Api-Token" in request.headers:
resp = {"access_token": request.headers.get("Custom-Api-Token")}
if resp is None:
Expand Down Expand Up @@ -272,10 +271,10 @@ def oauth_user_info(self, provider, response=None):

if is_valid_provider(provider, "onadata"):
user = (self.appbuilder.sm.oauth_remotes[provider].get(
"api/v1/user.json").data)
"api/v1/user.json", token=response).json())

user_data = (self.appbuilder.sm.oauth_remotes[provider].get(
f"api/v1/profiles/{user['username']}.json").data)
f"api/v1/profiles/{user['username']}.json", token=response).json())

return {
"name": user_data["name"],
Expand All @@ -288,7 +287,7 @@ def oauth_user_info(self, provider, response=None):

if is_valid_provider(provider, "OpenSRP"):
user_object = (self.appbuilder.sm.oauth_remotes[provider].get(
"user-details").data)
"user-details", token=response).json())

username = user_object.get("username") or user_object.get('userName')

Expand All @@ -309,15 +308,15 @@ def oauth_user_info(self, provider, response=None):
# get referenceDataUserId
reference_user = self.appbuilder.sm.oauth_remotes[provider].get(
"oauth/check_token", data={"token": my_token})
reference_data_user_id = reference_user.data["referenceDataUserId"]
reference_data_user_id = reference_user.json()["referenceDataUserId"]
# get user details
endpoint = f"users/{reference_data_user_id}"
user_data = self.appbuilder.sm.oauth_remotes[provider].get(
endpoint).data
endpoint, token=response).json()
# get email
email_endpoint = f"userContactDetails/{reference_data_user_id}"
email = self.appbuilder.sm.oauth_remotes[provider].get(
email_endpoint).data
email_endpoint, token=response).json()
return {
"name": user_data["username"],
"email": email["emailDetails"]["email"],
Expand Down
1 change: 0 additions & 1 deletion superset_patchup/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def all_dashboards(self):
Returns the ids, links, names, and URLs of the dashboards a user has
access to.
"""

dashboards = superset.db.session.query(
superset.models.core.Dashboard)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
{
'name': 'onadata',
'remote_app': {
'consumer_key': 'consumer key goes here',
'consumer_secret': 'consumer secret goes here',
'base_url': 'https://stage-api.ona.io/',
'client_id': 'consumer key goes here',
'client_secret': 'consumer secret goes here',
'api_base_url': 'https://stage-api.ona.io/',
'access_token_url': 'https://stage-api.ona.io/o/token/',
'authorize_url': 'https://stage-api.ona.io/o/authorize/',
}
Expand Down
Loading

0 comments on commit 26b183f

Please sign in to comment.