From 32941ddf31e4ac8b73e570047efd8dc93f0fc7d2 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Wed, 20 Dec 2023 14:25:30 -0600 Subject: [PATCH 01/21] fix: test change for the register command to use markdown instead of HTML to allow viewing for databricks users --- graphistry/pygraphistry.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index f4d00a1b2..4ce03ca1b 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -270,7 +270,8 @@ def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): if in_ipython() or in_databricks() or sso_opt_into_type == 'display': # If run in notebook, just display the HTML # from IPython.core.display import HTML from IPython.display import display, HTML - display(HTML(f'Login SSO')) + display(HTML(f'old: Login SSO')) + display(Markdown(f'[new: Login SSO]({auth_url})")) print("Please click the above URL to open browser to login") print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}") print("Please close browser tab after SSO login to back to notebook") From 1ac252154ef51c73a0e23c51611a77db3d6a6d4c Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Wed, 20 Dec 2023 15:21:54 -0600 Subject: [PATCH 02/21] fix syntax error --- graphistry/pygraphistry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 4ce03ca1b..065521931 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -271,7 +271,7 @@ def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): # from IPython.core.display import HTML from IPython.display import display, HTML display(HTML(f'old: Login SSO')) - display(Markdown(f'[new: Login SSO]({auth_url})")) + display(Markdown(f'[new: Login SSO]({auth_url})')) print("Please click the above URL to open browser to login") print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}") print("Please close browser tab after SSO login to back to notebook") From d400975a3bb06acda737d8d72141254dee4ea440 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Wed, 20 Dec 2023 15:27:42 -0600 Subject: [PATCH 03/21] add import for Markdown --- graphistry/pygraphistry.py | 1 + 1 file changed, 1 insertion(+) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 065521931..3cb94c0bd 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -2,6 +2,7 @@ from typing_extensions import Literal from graphistry.Plottable import Plottable from graphistry.privacy import Mode, Privacy +from IPython.display import Markdown """Top-level import of class PyGraphistry as "Graphistry". Used to connect to the Graphistry server and then create a base plotter.""" import calendar, gzip, io, json, os, numpy as np, pandas as pd, requests, sys, time, warnings From 360a9eb66acc1877f34b9513f0a71cdc86520128 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Wed, 20 Dec 2023 15:35:52 -0600 Subject: [PATCH 04/21] added class to print Markdown --- graphistry/pygraphistry.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 3cb94c0bd..f91d061dd 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -2,7 +2,7 @@ from typing_extensions import Literal from graphistry.Plottable import Plottable from graphistry.privacy import Mode, Privacy -from IPython.display import Markdown +from IPython.display import DisplayObject, TextDisplayObject """Top-level import of class PyGraphistry as "Graphistry". Used to connect to the Graphistry server and then create a base plotter.""" import calendar, gzip, io, json, os, numpy as np, pandas as pd, requests, sys, time, warnings @@ -100,6 +100,19 @@ def strtobool(val: Any) -> bool: else: raise ValueError("invalid truth value %r" % (val,)) +# used to print Login link databricks register() call +class Markdown(TextDisplayObject): + + def __init__(self,TextDisplayObject): + import markdown as md + + #converting markdown to html + self.html = md.markdown(TextDisplayObject) + + def _repr_html_(self): + return self.html + + class PyGraphistry(object): _config = _get_initial_config() _tag = util.fingerprint() From 1b05c8fb57e304a21049055c920beb3ffc05102a Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Tue, 16 Jan 2024 18:02:28 -0600 Subject: [PATCH 05/21] fix: #539 - databricks login link and timer switch to javascript to handle async better --- graphistry/pygraphistry.py | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index f91d061dd..7c56874f0 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -282,14 +282,34 @@ def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): """ if in_ipython() or in_databricks() or sso_opt_into_type == 'display': # If run in notebook, just display the HTML - # from IPython.core.display import HTML from IPython.display import display, HTML - display(HTML(f'old: Login SSO')) - display(Markdown(f'[new: Login SSO]({auth_url})')) - print("Please click the above URL to open browser to login") - print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}") - print("Please close browser tab after SSO login to back to notebook") - # return HTML(make_iframe(auth_url, 20, extra_html=extra_html, override_html_style=override_html_style)) + + # this function was required due to bug where databricks notebooks do not display the html link while a timer is running + def display_link_and_timer(auth_url, sso_timeout): + html_content = f""" + Graphistry SSO Login

+
Timer starts...
+ + + """ + display(HTML(html_content)) + + display_link_and_timer(auth_url, sso_timeout) + elif sso_opt_into_type == 'browser': print("Please minimize browser after your SSO login and go back to pygraphistry") From 1d4bc290f23fcd198a3139b7e7afaefdbda321b3 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Tue, 16 Jan 2024 18:05:27 -0600 Subject: [PATCH 06/21] removed unused code from previous commit --- graphistry/pygraphistry.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 7c56874f0..ec764f4bc 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -2,7 +2,6 @@ from typing_extensions import Literal from graphistry.Plottable import Plottable from graphistry.privacy import Mode, Privacy -from IPython.display import DisplayObject, TextDisplayObject """Top-level import of class PyGraphistry as "Graphistry". Used to connect to the Graphistry server and then create a base plotter.""" import calendar, gzip, io, json, os, numpy as np, pandas as pd, requests, sys, time, warnings @@ -100,19 +99,6 @@ def strtobool(val: Any) -> bool: else: raise ValueError("invalid truth value %r" % (val,)) -# used to print Login link databricks register() call -class Markdown(TextDisplayObject): - - def __init__(self,TextDisplayObject): - import markdown as md - - #converting markdown to html - self.html = md.markdown(TextDisplayObject) - - def _repr_html_(self): - return self.html - - class PyGraphistry(object): _config = _get_initial_config() _tag = util.fingerprint() From fdd74fcc509b3a77d02777ab1817baecb2eea386 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 4 Mar 2024 21:53:37 -0600 Subject: [PATCH 07/21] added js timer for databricks --- graphistry/pygraphistry.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index ec764f4bc..aeec0bae6 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -267,7 +267,7 @@ def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): """ - if in_ipython() or in_databricks() or sso_opt_into_type == 'display': # If run in notebook, just display the HTML + if in_databricks(): # If run in databricks notebook, display the HTML and timer using javascript issue #539 from IPython.display import display, HTML # this function was required due to bug where databricks notebooks do not display the html link while a timer is running @@ -295,7 +295,17 @@ def display_link_and_timer(auth_url, sso_timeout): display(HTML(html_content)) display_link_and_timer(auth_url, sso_timeout) + logger.info("display_link_and_timer() done") + else: + if in_ipython() or sso_opt_into_type == 'display': # If run in notebook, just display the HTML + from IPython.display import display, HTML + display(HTML(f'Login SSO')) + print("Please click the above URL to open browser to login") + print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}") + print("Please close browser tab after SSO login to back to notebook") + + elif sso_opt_into_type == 'browser': print("Please minimize browser after your SSO login and go back to pygraphistry") From 1ce9643ea06772e6bacc23f6f3b54c8f2ccc99fe Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 11 Mar 2024 12:44:26 -0500 Subject: [PATCH 08/21] fix syntax error in if stmt --- graphistry/pygraphistry.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index aeec0bae6..70eb273ec 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -297,8 +297,7 @@ def display_link_and_timer(auth_url, sso_timeout): display_link_and_timer(auth_url, sso_timeout) logger.info("display_link_and_timer() done") - else: - if in_ipython() or sso_opt_into_type == 'display': # If run in notebook, just display the HTML + elif in_ipython() or sso_opt_into_type == 'display': # If run in notebook, just display the HTML from IPython.display import display, HTML display(HTML(f'Login SSO')) print("Please click the above URL to open browser to login") @@ -2521,3 +2520,7 @@ def default(self, obj): elif isinstance(obj, datetime): return obj.isoformat() return json.JSONEncoder.default(self, obj) + + + + From ded2bdce7281ee211513a81426c0e79699ffdd02 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 11 Mar 2024 18:12:40 -0500 Subject: [PATCH 09/21] added new func databricks_notebook_sso_login to present HTML link --- graphistry/pygraphistry.py | 124 ++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 51 deletions(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 70eb273ec..8eefebecf 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -201,6 +201,9 @@ def pkey_login(personal_key_id, personal_key_secret, org_name=None, fail_silent= return PyGraphistry.api_token() + + + @staticmethod def sso_login(org_name=None, idp_name=None, sso_timeout=SSO_GET_TOKEN_ELAPSE_SECONDS, sso_opt_into_type=None): """Authenticate with SSO and set token for reuse (api=3). @@ -242,12 +245,52 @@ def sso_login(org_name=None, idp_name=None, sso_timeout=SSO_GET_TOKEN_ELAPSE_SEC except Exception: # required to log on # print("required to log on") PyGraphistry.sso_state(arrow_uploader.sso_state) + auth_url = arrow_uploader.sso_auth_url + # print("auth_url : {}".format(auth_url)) + if auth_url and not PyGraphistry.api_token(): + PyGraphistry._handle_auth_url(auth_url, sso_timeout, sso_opt_into_type) + + @staticmethod + def databricks_notebook_sso_login(): + org_name=None + idp_name=None + sso_timeout=SSO_GET_TOKEN_ELAPSE_SECONDS + sso_opt_into_type=None + + if PyGraphistry._config['store_token_creds_in_memory']: + PyGraphistry.relogin = lambda: PyGraphistry.sso_login( + org_name, idp_name, sso_timeout, sso_opt_into_type + ) + PyGraphistry._is_authenticated = False + arrow_uploader = ArrowUploader( + server_base_path=PyGraphistry.protocol() + + "://" # noqa: W503 + + PyGraphistry.server(), # noqa: W503 + certificate_validation=PyGraphistry.certificate_validation(), + ).sso_login(org_name, idp_name) + + try: + if arrow_uploader.token: + PyGraphistry.api_token(arrow_uploader.token) + PyGraphistry._is_authenticated = True + arrow_uploader.token = None + return PyGraphistry.api_token() + except Exception: # required to log on + # print("required to log on") + PyGraphistry.sso_state(arrow_uploader.sso_state) auth_url = arrow_uploader.sso_auth_url # print("auth_url : {}".format(auth_url)) if auth_url and not PyGraphistry.api_token(): - PyGraphistry._handle_auth_url(auth_url, sso_timeout, sso_opt_into_type) - return auth_url + PyGraphistry._handle_auth_url(auth_url, sso_timeout, sso_opt_into_type) + + from IPython.display import display, HTML + display(HTML(f'Login SSO')) + print("Please click the above URL to open browser to login") + print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}") + print("Please close browser tab after SSO login to back to notebook") + # return HTML(make_iframe(auth_url, 20, extra_html=extra_html, override_html_style=override_html_style)) + @staticmethod def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): @@ -266,55 +309,26 @@ def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): SSO Login logic. """ - - if in_databricks(): # If run in databricks notebook, display the HTML and timer using javascript issue #539 - from IPython.display import display, HTML - - # this function was required due to bug where databricks notebooks do not display the html link while a timer is running - def display_link_and_timer(auth_url, sso_timeout): - html_content = f""" - Graphistry SSO Login

-
Timer starts...
- - - """ - display(HTML(html_content)) - - display_link_and_timer(auth_url, sso_timeout) - logger.info("display_link_and_timer() done") - - elif in_ipython() or sso_opt_into_type == 'display': # If run in notebook, just display the HTML - from IPython.display import display, HTML - display(HTML(f'Login SSO')) - print("Please click the above URL to open browser to login") - print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}") - print("Please close browser tab after SSO login to back to notebook") - - - elif sso_opt_into_type == 'browser': - print("Please minimize browser after your SSO login and go back to pygraphistry") - - import webbrowser - input("Press Enter to open browser ...") - # open browser to auth_url - webbrowser.open(auth_url) - else: - print(f"Please open a browser, browse to this URL, and sign in: {auth_url}") - print("After, if you get timeout error, run graphistry.sso_get_token() to complete the authentication") + if not in_databricks(): + # elif in_ipython() or sso_opt_into_type == 'display': # If run in notebook, just display the HTML + if in_ipython() or sso_opt_into_type == 'display': # If run in notebook, just display the HTML + + from IPython.display import display, HTML + display(HTML(f'Login SSO')) + print("Please click the above URL to open browser to login") + print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}") + print("Please close browser tab after SSO login to back to notebook") + + elif sso_opt_into_type == 'browser': + print("Please minimize browser after your SSO login and go back to pygraphistry") + + import webbrowser + input("Press Enter to open browser ...") + # open browser to auth_url + webbrowser.open(auth_url) + else: + print(f"Please open a browser, browse to this URL, and sign in: {auth_url}") + print("After, if you get timeout error, run graphistry.sso_get_token() to complete the authentication") if sso_timeout is not None: time.sleep(1) @@ -335,6 +349,8 @@ def display_link_and_timer(auth_url, sso_timeout): else: break except SsoRetrieveTokenTimeoutException as toe: + if in_databricks(): + print('Error: Make sure to call databricks_notebook_sso_login() function before register() to display SSO html login link') logger.debug(toe, exc_info=1) break except Exception: @@ -700,6 +716,12 @@ def register( import graphistry graphistry.register(api=3, protocol='http', server='nginx', client_protocol_hostname='https://my.site.com', token='abc') + **Example: Databricks notebook and dashboard users need to call the following before register to correctly display the HTML link: + :: + import graphistry + databricks_notebook_sso_login + graphistry.register(api=3, protocol='https', server='200.1.1.1', is_sso_login=True) + **Example: Standard (1.0)** :: From 0ac0ab048e868cf2ba5fcfc438540c76cb1e35f5 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 11 Mar 2024 18:17:56 -0500 Subject: [PATCH 10/21] fix: skip _handle_auth_url in databricks_notebook_sso_login --- graphistry/pygraphistry.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 8eefebecf..f36cf19ac 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -282,14 +282,12 @@ def databricks_notebook_sso_login(): auth_url = arrow_uploader.sso_auth_url # print("auth_url : {}".format(auth_url)) if auth_url and not PyGraphistry.api_token(): - PyGraphistry._handle_auth_url(auth_url, sso_timeout, sso_opt_into_type) - - from IPython.display import display, HTML - display(HTML(f'Login SSO')) - print("Please click the above URL to open browser to login") - print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}") - print("Please close browser tab after SSO login to back to notebook") - # return HTML(make_iframe(auth_url, 20, extra_html=extra_html, override_html_style=override_html_style)) + from IPython.display import display, HTML + display(HTML(f'Login SSO')) + print("Please click the above URL to open browser to login") + print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}") + print("Please close browser tab after SSO login to back to notebook") + # return HTML(make_iframe(auth_url, 20, extra_html=extra_html, override_html_style=override_html_style)) @staticmethod @@ -719,7 +717,7 @@ def register( **Example: Databricks notebook and dashboard users need to call the following before register to correctly display the HTML link: :: import graphistry - databricks_notebook_sso_login + databricks_notebook_sso_login() graphistry.register(api=3, protocol='https', server='200.1.1.1', is_sso_login=True) **Example: Standard (1.0)** From daa9e7ff3b340fe915a517fcfcf9291a84642c17 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 11 Mar 2024 18:22:23 -0500 Subject: [PATCH 11/21] fix: added global to point to databricks_notebook_sso_login --- graphistry/pygraphistry.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index f36cf19ac..33006184a 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -2526,6 +2526,8 @@ def _handle_api_response(response): personal_key_id = PyGraphistry.personal_key_id personal_key_secret = PyGraphistry.personal_key_secret switch_org = PyGraphistry.switch_org +databricks_notebook_sso_login = PyGraphistry.databricks_notebook_sso_login + From ae9d912e65b891575d4703cb76bd6426cd6fd658 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 11 Mar 2024 18:26:39 -0500 Subject: [PATCH 12/21] fix: missing import in __init.py__ for databricks_notebook_sso_login --- graphistry/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/graphistry/__init__.py b/graphistry/__init__.py index 246fdf6cb..bc0ac0ecf 100644 --- a/graphistry/__init__.py +++ b/graphistry/__init__.py @@ -46,7 +46,8 @@ ArrowFileUploader, PyGraphistry, from_igraph, - from_cugraph + from_cugraph, + databricks_notebook_sso_login ) from graphistry.compute import ( From 1ab200ceb9ccf435c93cf290273378ff3c78b77b Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 11 Mar 2024 19:41:47 -0500 Subject: [PATCH 13/21] fix: remove _get_auth_url call --- graphistry/pygraphistry.py | 53 +++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 33006184a..9a07d12c5 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -251,16 +251,49 @@ def sso_login(org_name=None, idp_name=None, sso_timeout=SSO_GET_TOKEN_ELAPSE_SEC PyGraphistry._handle_auth_url(auth_url, sso_timeout, sso_opt_into_type) @staticmethod - def databricks_notebook_sso_login(): - org_name=None - idp_name=None - sso_timeout=SSO_GET_TOKEN_ELAPSE_SECONDS - sso_opt_into_type=None - - if PyGraphistry._config['store_token_creds_in_memory']: - PyGraphistry.relogin = lambda: PyGraphistry.sso_login( - org_name, idp_name, sso_timeout, sso_opt_into_type - ) + def databricks_notebook_sso_login( + # key: Optional[str] = None, + # username: Optional[str] = None, + # password: Optional[str] = None, + # token: Optional[str] = None, + # personal_key_id: Optional[str] = None, + # personal_key_secret: Optional[str] = None, + server: Optional[str] = None, + protocol: Optional[str] = None, + api: Optional[Literal[1, 3]] = None, + certificate_validation: Optional[bool] = None, + # bolt: Optional[Union[Dict, Any]] = None, + token_refresh_ms: int = 10 * 60 * 1000, + store_token_creds_in_memory: Optional[bool] = None, + client_protocol_hostname: Optional[str] = None, + org_name: Optional[str] = None, + idp_name: Optional[str] = None, + is_sso_login: Optional[bool] = False, + sso_timeout: Optional[int] = SSO_GET_TOKEN_ELAPSE_SECONDS, + sso_opt_into_type: Optional[Literal["display", "browser"]] = None +): + """display HTML link for databricks notebooks + + see graphistry.register docstring for details on input parameters. + """ + + PyGraphistry.api_version(api) + PyGraphistry.api_token_refresh_ms(token_refresh_ms) + PyGraphistry.server(server) + PyGraphistry.protocol(protocol) + PyGraphistry.client_protocol_hostname(client_protocol_hostname) + PyGraphistry.certificate_validation(certificate_validation) + PyGraphistry.store_token_creds_in_memory(store_token_creds_in_memory) + # Reset token creds + PyGraphistry.__reset_token_creds_in_memory() + + # the following code was copied from sso_login() to get the auth_url + # + # not required: + # if PyGraphistry._config['store_token_creds_in_memory']: + # PyGraphistry.relogin = lambda: PyGraphistry.sso_login( + # org_name, idp_name, sso_timeout, sso_opt_into_type + # ) PyGraphistry._is_authenticated = False arrow_uploader = ArrowUploader( From d2ef7bf57567f72c8fd30b6a5d1f8ec094612ae1 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 11 Mar 2024 23:22:46 -0500 Subject: [PATCH 14/21] updated CHANGELOG and minor formatting changes in pygraphistry.py --- CHANGELOG.md | 7 +++++++ graphistry/pygraphistry.py | 21 +-------------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6642a01b8..e8478dd7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ## [Development] +## [0.33.7 - 2024-03-11] + +### Fixed + +* new function databricks_notebook_sso_login() that should be called prior to register(), fixes: #539 where databricks dashboards do not get an HTML link for SSO logins + + ## [0.31.1 - 2023-12-05] ### Docs diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 9a07d12c5..34ccf9b64 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -252,17 +252,10 @@ def sso_login(org_name=None, idp_name=None, sso_timeout=SSO_GET_TOKEN_ELAPSE_SEC @staticmethod def databricks_notebook_sso_login( - # key: Optional[str] = None, - # username: Optional[str] = None, - # password: Optional[str] = None, - # token: Optional[str] = None, - # personal_key_id: Optional[str] = None, - # personal_key_secret: Optional[str] = None, server: Optional[str] = None, protocol: Optional[str] = None, api: Optional[Literal[1, 3]] = None, certificate_validation: Optional[bool] = None, - # bolt: Optional[Union[Dict, Any]] = None, token_refresh_ms: int = 10 * 60 * 1000, store_token_creds_in_memory: Optional[bool] = None, client_protocol_hostname: Optional[str] = None, @@ -288,12 +281,6 @@ def databricks_notebook_sso_login( PyGraphistry.__reset_token_creds_in_memory() # the following code was copied from sso_login() to get the auth_url - # - # not required: - # if PyGraphistry._config['store_token_creds_in_memory']: - # PyGraphistry.relogin = lambda: PyGraphistry.sso_login( - # org_name, idp_name, sso_timeout, sso_opt_into_type - # ) PyGraphistry._is_authenticated = False arrow_uploader = ArrowUploader( @@ -310,17 +297,11 @@ def databricks_notebook_sso_login( arrow_uploader.token = None return PyGraphistry.api_token() except Exception: # required to log on - # print("required to log on") PyGraphistry.sso_state(arrow_uploader.sso_state) auth_url = arrow_uploader.sso_auth_url - # print("auth_url : {}".format(auth_url)) if auth_url and not PyGraphistry.api_token(): from IPython.display import display, HTML - display(HTML(f'Login SSO')) - print("Please click the above URL to open browser to login") - print(f"If you cannot see the URL, please open browser, browse to this URL: {auth_url}") - print("Please close browser tab after SSO login to back to notebook") - # return HTML(make_iframe(auth_url, 20, extra_html=extra_html, override_html_style=override_html_style)) + display(HTML(f'Graphistry SSO Login')) @staticmethod From 7ed40bd7a30806c9b13118e100dd3f283806a26d Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 11 Mar 2024 23:31:33 -0500 Subject: [PATCH 15/21] remove blank lines from end of file for linter --- graphistry/pygraphistry.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 34ccf9b64..f0754c4f8 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -2555,8 +2555,4 @@ def default(self, obj): return None elif isinstance(obj, datetime): return obj.isoformat() - return json.JSONEncoder.default(self, obj) - - - - + return json.JSONEncoder.default(self, obj) \ No newline at end of file From cbf96a0018a4689c82995e66e0886d3b9ade56f5 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Mon, 11 Mar 2024 23:35:20 -0500 Subject: [PATCH 16/21] add newline at end of file for linter --- graphistry/pygraphistry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index f0754c4f8..fb776f53a 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -2555,4 +2555,4 @@ def default(self, obj): return None elif isinstance(obj, datetime): return obj.isoformat() - return json.JSONEncoder.default(self, obj) \ No newline at end of file + return json.JSONEncoder.default(self, obj) From 05b7b639c8ea4214955d7ed5c55551d6f1e7c047 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Tue, 12 Mar 2024 00:20:28 -0500 Subject: [PATCH 17/21] merge with master --- graphistry/pygraphistry.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 480d1fc30..30475ed94 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -249,7 +249,6 @@ def sso_login(org_name=None, idp_name=None, sso_timeout=SSO_GET_TOKEN_ELAPSE_SEC # print("auth_url : {}".format(auth_url)) if auth_url and not PyGraphistry.api_token(): PyGraphistry._handle_auth_url(auth_url, sso_timeout, sso_opt_into_type) -<<<<<<< HEAD @staticmethod def databricks_notebook_sso_login( @@ -304,12 +303,8 @@ def databricks_notebook_sso_login( from IPython.display import display, HTML display(HTML(f'Graphistry SSO Login')) -======= - return auth_url ->>>>>>> 2506b798ec723e906c1c5279f613fe0c37bdbad2 - - @staticmethod - def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): +@staticmethod +def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): """Internal function to handle what to do with the auth_url based on the client mode python/ipython console or notebook. From d779e9d31e43c240a1533782503eccad7a664c94 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Tue, 12 Mar 2024 00:24:08 -0500 Subject: [PATCH 18/21] indent typo --- graphistry/pygraphistry.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 30475ed94..1a79cd834 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -303,8 +303,8 @@ def databricks_notebook_sso_login( from IPython.display import display, HTML display(HTML(f'Graphistry SSO Login')) -@staticmethod -def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): + @staticmethod + def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): """Internal function to handle what to do with the auth_url based on the client mode python/ipython console or notebook. From e2ee637ad56b206c854e0ad73a75f332980ec351 Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Tue, 12 Mar 2024 20:13:57 -0500 Subject: [PATCH 19/21] remove missed merge section break --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9df45f2d6..63e850bb4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,7 +84,6 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Breaking 🔥 * GFQL `e()` now aliases `e_undirected` instead of the base class `ASTEdge` ->>>>>>> 2506b798ec723e906c1c5279f613fe0c37bdbad2 ## [0.31.1 - 2023-12-05] From 647481076d4d638720f34c2cc4fefb10a07a6bca Mon Sep 17 00:00:00 2001 From: Thomas Cook Date: Wed, 13 Mar 2024 02:45:42 -0500 Subject: [PATCH 20/21] added relogin back to databricks_notebook_sso_login func --- graphistry/pygraphistry.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 1a79cd834..80d2b36ae 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -282,6 +282,11 @@ def databricks_notebook_sso_login( # the following code was copied from sso_login() to get the auth_url + if PyGraphistry._config['store_token_creds_in_memory']: + PyGraphistry.relogin = lambda: PyGraphistry.sso_login( + org_name, idp_name, sso_timeout, sso_opt_into_type + ) + PyGraphistry._is_authenticated = False arrow_uploader = ArrowUploader( server_base_path=PyGraphistry.protocol() From 9a9c22333c3d1d10772d897afa82bef05ec4ae17 Mon Sep 17 00:00:00 2001 From: Vaim Dev Date: Wed, 13 Mar 2024 23:48:13 +0800 Subject: [PATCH 21/21] fix (databricks): display SSO login url for databrick notebook --- graphistry/pygraphistry.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/graphistry/pygraphistry.py b/graphistry/pygraphistry.py index 1a79cd834..57603b4bf 100644 --- a/graphistry/pygraphistry.py +++ b/graphistry/pygraphistry.py @@ -340,6 +340,9 @@ def _handle_auth_url(auth_url, sso_timeout, sso_opt_into_type): else: print(f"Please open a browser, browse to this URL, and sign in: {auth_url}") print("After, if you get timeout error, run graphistry.sso_get_token() to complete the authentication") + else: + from IPython.display import display, HTML + display(HTML(f'Graphistry SSO Login')) if sso_timeout is not None: time.sleep(1)