Skip to content

Commit

Permalink
Merge pull request #255 from vertica/connection_page_update_01
Browse files Browse the repository at this point in the history
Connection page - Added option for Other connections
  • Loading branch information
mail4umar authored May 14, 2024
2 parents 6faa749 + 487c575 commit e63262c
Showing 1 changed file with 122 additions and 7 deletions.
129 changes: 122 additions & 7 deletions project/ui/conn.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
"from ipywidgets import interact, interactive, fixed, interact_manual\n",
"import ipywidgets as widgets\n",
"from IPython.display import display,clear_output, HTML\n",
"from ipyfilechooser import FileChooser\n",
"import ssl\n",
"\n",
"import verticapy as vp"
]
Expand All @@ -61,12 +63,29 @@
"outputs": [],
"source": [
"# style = {'description_width': '150px', 'width' : '400px'}\n",
"host = widgets.Text(description = \"Host\",placeholder = \"Enter Host (default is 'verticadb')\")\n",
"port = widgets.Text(description = \"Port\", placeholder = \"Enter Port (default is 5433)\")\n",
"user = widgets.Text(description = \"User name\", placeholder = \"Enter User Name (default is 'dbadmin')\")\n",
"password = widgets.Password(description = \"Password\", placeholder = \"Enter Password (default is Empty)\")\n",
"database = widgets.Text(description = \"Database\", placeholder = \"Enter Database (default is 'demo')\")\n",
"name = widgets.Text(description = \"Name\", placeholder = \"Enter Name (default is 'VerticaDSN')\")\n",
"host = widgets.Text(description = \"Host\",placeholder = \"Enter Host (default is 'verticadb')\", layout=widgets.Layout(width='350px'))\n",
"port = widgets.Text(description = \"Port\", placeholder = \"Enter Port (default is 5433)\", layout=widgets.Layout(width='350px'))\n",
"user = widgets.Text(description = \"User name\", placeholder = \"Enter User Name (default is 'dbadmin')\", layout=widgets.Layout(width='350px'))\n",
"password = widgets.Password(description = \"Password\", placeholder = \"Enter Password (default is Empty)\", layout=widgets.Layout(width='350px'))\n",
"database = widgets.Text(description = \"Database\", placeholder = \"Enter Database (default is 'demo')\", layout=widgets.Layout(width='350px'))\n",
"name = widgets.Text(description = \"Name\", placeholder = \"Enter Name (default is 'VerticaDSN')\", layout=widgets.Layout(width='350px'))\n",
"\n",
"connection_timeout = widgets.Text(description = \"Connection Timeout\", placeholder = \"Time in seconds (default is 5)\", layout=widgets.Layout(width='350px'))\n",
"connection_timeout.style.description_width = '130px'\n",
"autocommit = widgets.Checkbox(value = False, description = 'Autocommit', disabled = False, indent = False,layout=widgets.Layout(width = '350px',align_items='flex-end'))\n",
"\n",
"#Oauth\n",
"oauth_access_token = widgets.Password(description = \"OAuth Access Token\", placeholder = \"Enter Access Token\", layout=widgets.Layout(width='500px'))\n",
"oauth_access_token.style.description_width = '150px'\n",
"oauth_refresh_token = widgets.Password(description = \"OAuth Refresh Token\", placeholder = \"Enter Refresh Token\", layout=widgets.Layout(width='500px'))\n",
"oauth_refresh_token.style.description_width = '150px'\n",
"\n",
"#Kerberos\n",
"kerberos_host_name = widgets.Text(description = \"Kerberos host name\", placeholder = \"Enter Host\", layout=widgets.Layout(width='500px'))\n",
"kerberos_host_name.style.description_width = '150px'\n",
"kerberos_service_name = widgets.Text(description = \"Kerberos service name\", placeholder = \"Enter Name\", layout=widgets.Layout(width='500px'))\n",
"kerberos_service_name.style.description_width = '150px'\n",
"\n",
"backup_server_node = [\"localhost\"]"
]
},
Expand Down Expand Up @@ -94,9 +113,99 @@
" password,\n",
" database,\n",
" name,\n",
" connection_timeout\n",
"]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d87806cd-929a-48e6-9b33-1e93f1df556c",
"metadata": {},
"outputs": [],
"source": [
"tls_params = widgets.RadioButtons(\n",
" options=['Require', 'Verify-CA', 'Verify-Full'],\n",
" value='Require', # Defaults to 'Require'\n",
" description='Select:',\n",
" disabled=False\n",
")\n",
"ssl_context = None\n",
"# Create uploader widget\n",
"uploader = FileChooser('')\n",
"output_tls = widgets.Output()\n",
"# Function to display appropriate widget based on radio button selection\n",
"def display_widget_tls(selection):\n",
" output_tls.clear_output()\n",
" global ssl_context\n",
" with output_tls:\n",
" if selection == 'Verify-CA' or selection == 'Verify-Full':\n",
" display(uploader)\n",
" if selection == \"Verify-CA\":\n",
" ssl_context.check_hostname = False\n",
" elif selection == \"Verify-Full\":\n",
" ssl_context.check_hostname = True\n",
"\n",
"# Call function when radio button value changes\n",
"tls_params.observe(lambda change: display_widget_tls(change['new']), names='value')\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "840c448c-cc61-412d-b68e-8700c136a1c7",
"metadata": {},
"outputs": [],
"source": [
"# Create dropdown widget\n",
"dropdown = widgets.Dropdown(\n",
" options=['', 'OAuth', 'TLS', 'Kerberos'],\n",
" description='Advanced Connection',\n",
" disabled=False\n",
")\n",
"output_advanced_connection = widgets.Output()\n",
"\n",
"oauth_params = widgets.VBox([oauth_access_token,oauth_refresh_token])\n",
"kerberos_params = widgets.VBox([kerberos_host_name,kerberos_service_name])\n",
"\n",
"\n",
"# Function to display appropriate widget based on dropdown selection\n",
"def display_widget_advanced_connection(selection):\n",
" global ssl_context\n",
" output_advanced_connection.clear_output()\n",
"\n",
" with output_advanced_connection:\n",
" if selection == 'OAuth':\n",
" display(oauth_params)\n",
" elif selection == 'Kerberos':\n",
" display(kerberos_params)\n",
" elif selection == 'TLS':\n",
" ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)\n",
" ssl_context.check_hostname = False\n",
" ssl_context.verify_mode = ssl.CERT_NONE\n",
" display(tls_params,output_tls)\n",
" ssl_context\n",
"\n",
"# Call function when dropdown value changes\n",
"dropdown.observe(lambda change: display_widget_advanced_connection(change['new']), names='value')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "640cf2ec-5c0f-4c45-89e0-a5d025e2d26c",
"metadata": {},
"outputs": [],
"source": [
"\n",
"\n",
"advanced_options = widgets.VBox([dropdown,output_advanced_connection, autocommit])\n",
"\n",
"accordion = widgets.Accordion(children=[advanced_options], titles=('Advanced Options',))\n",
"accordion"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -113,13 +222,17 @@
"\n",
"def on_button_clicked(b):\n",
" output.clear_output(wait=True) # Clear the output\n",
" global ssl_context\n",
" if dropdown.value ==\"TLS\" and (tls_params==\"Verify-Full\" or tls_params==\"Verify-CA\"):\n",
" ssl_context.load_verify_locations(cafile=uploader.value) # CA certificate used to verify server certificate\n",
" with output:\n",
" conn_info = {\n",
" 'host': host.value if host.value else \"verticadb\", \n",
" 'port': port.value if port.value else 5433,\n",
" 'user': user.value if user.value else \"dbadmin\",\n",
" 'password': password.value if password.value else \"\",\n",
" 'database': database.value if database.value else \"demo\",\n",
" 'ssl': ssl_context if dropdown.value ==\"TLS\" else False,\n",
" }\n",
" vp.new_connection(\n",
" conn_info,\n",
Expand All @@ -134,7 +247,9 @@
{
"cell_type": "markdown",
"id": "4caf85a1-a3f9-4dd2-af9f-f2a43d239ed1",
"metadata": {},
"metadata": {
"jp-MarkdownHeadingCollapsed": true
},
"source": [
"## Or Select From List"
]
Expand Down

0 comments on commit e63262c

Please sign in to comment.