Skip to content

Commit

Permalink
Merge pull request #48 from sepal-contrib/add_authentication
Browse files Browse the repository at this point in the history
add authentication
  • Loading branch information
dfguerrerom authored Dec 20, 2023
2 parents 52df07f + 92e5c64 commit 943b2ba
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 253 deletions.
259 changes: 7 additions & 252 deletions no_ui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -12,273 +12,28 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>/*******************************************************************************\n",
" * Customization of the provided css from the different libs used by sepal_ui\n",
" */\n",
"\n",
"/* replace the map panel elements on top */\n",
".leaflet-pane,\n",
".leaflet-top,\n",
".leaflet-bottom {\n",
" z-index: 2 !important;\n",
"}\n",
"\n",
"/* remove the shadow from the widgets on the maps */\n",
".leaflet-widgetcontrol {\n",
" box-shadow: none;\n",
"}\n",
"\n",
"/* remove extra padding on top of the content */\n",
"main.v-content {\n",
" padding-top: 0px !important;\n",
"}\n",
"\n",
"/* remove all the backgrounds from the controls and widget to be colored naturelly by the map */\n",
".leaflet-control-container .vuetify-styles .v-application {\n",
" background: rgb(0, 0, 0, 0);\n",
"}\n",
".v-alert__wrapper .progress {\n",
" background-color: transparent;\n",
"}\n",
"\n",
"/* set the bar on top of the map (800) when set to fullscreen */\n",
"header.v-app-bar {\n",
" z-index: 800 !important;\n",
"}\n",
"\n",
"/* set the menu_content on top of the map when it's set to fullscreen */\n",
".v-menu__content {\n",
" max-width: 100% !important;\n",
"}\n",
"\n",
"/* make sure navigation drawers are always visible when they exist */\n",
"nav.v-navigation-drawer {\n",
" z-index: 900 !important;\n",
"}\n",
"\n",
"/* create extra position for the leaflet map controls */\n",
".leaflet-center {\n",
" left: 50%;\n",
" transform: translate(-50%, 0%);\n",
"}\n",
"\n",
".leaflet-middle {\n",
" top: 50%;\n",
" position: absolute;\n",
" z-index: 1000;\n",
" pointer-events: none;\n",
" transform: translate(0%, -50%);\n",
"}\n",
"\n",
".leaflet-center.leaflet-middle {\n",
" transform: translate(-50%, -50%);\n",
"}\n",
"\n",
"/* create extra classes to customize the layer_control table */\n",
".v-no-hover:hover {\n",
" background-color: transparent !important;\n",
"}\n",
"\n",
".v-no-border tbody tr td,\n",
".v-no-border tbody tr th {\n",
" border: none !important;\n",
"}\n",
"\n",
"/* extra css rules to make the messages disappear beneath the SimpleSlider */\n",
".v-no-messages .v-messages {\n",
" display: none;\n",
"}\n",
"\n",
".v-no-messages .v-input__slot {\n",
" margin-bottom: 0;\n",
"}\n",
"\n",
"/* specific css for the btn placed on maps */\n",
".v-btn.v-size--default.v-map-btn:not(.v-btn--round) {\n",
" padding: 0px;\n",
" min-width: 0px;\n",
" width: 30px;\n",
" height: 30px;\n",
"}\n",
"\n",
"/* add specific css for the zoom btn of the map */\n",
".v-btn.v-zoom-plus {\n",
" border-bottom-left-radius: 0;\n",
" border-bottom-right-radius: 0;\n",
"}\n",
"\n",
".v-btn.v-zoom-minus {\n",
" margin-top: -1px;\n",
" border-top-left-radius: 0;\n",
" border-top-right-radius: 0;\n",
"}\n",
"\n",
"/* css rules for fullscreen menus */\n",
".v-card.v-menu-fullscreen {\n",
" width: calc(100vw - 80px);\n",
" height: calc(100vh - 20px);\n",
"}\n",
"\n",
"/* hide the disclaimer message placed on top of the ui notebook\n",
" * the message will be displayed until the css is loaded */\n",
"#loading-app {\n",
" display: none !important;\n",
"}\n",
"\n",
"/* Related with https://github.com/12rambau/sepal_ui/issues/893 */\n",
"#rendered_cells {\n",
" contain: revert !important;\n",
" background-color: revert !important;\n",
"}\n",
"</style>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css\"/>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"/*******************************************************************************\n",
" * remove any links from fontawesome 5 created by jupyter in favor of\n",
" * fontawesome 6. to be removed when Jupyter updates it\n",
" */\n",
"\n",
"function remove_fa5() {\n",
" let links = document.querySelectorAll(\n",
" \"link[href^='https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@^5']\"\n",
" );\n",
"\n",
" links.forEach((link) => link.remove());\n",
"}\n",
"\n",
"if (document.readyState != \"loading\") remove_fa5();\n",
"else document.addEventListener(\"DOMContentLoaded\", remove_fa5);\n"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "a6a2f3d0547b4cb3bd36a01d6811bef2",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"ResizeTrigger()"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"from component import tile\n",
"from sepal_ui import aoi"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "019f8614e7d9445bac9e0a08b0033bb5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VuetifyTemplate(template='<script>{methods: {jupyter_embed(){/* set a selected map to embed mode (i.e. default…"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/javascript": [
"/* set a selected map to fullscreen */\n",
"var i = 0;\n",
"const wait_unitl_element_appear = setInterval(() => {\n",
" var element = document.querySelector(\".vujvjc .leaflet-container\");\n",
" if (element != null) {\n",
" element.style.position = \"fixed\";\n",
" element.style.width = \"100vw\";\n",
" element.style.height = \"calc(100vh - 48px)\";\n",
" element.style.zIndex = 800;\n",
" element.style.bottom = 0;\n",
" element.style.left = 0;\n",
" window.dispatchEvent(new Event(\"resize\"));\n",
" clearInterval(wait_unitl_element_appear);\n",
" } else if (i > 50) {\n",
" clearInterval(wait_unitl_element_appear);\n",
" console.log(\"cannot find the map element\");\n",
" } else {\n",
" i++;\n",
" }\n",
"}, 100);\n"
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"outputs": [],
"source": [
"map_tile = tile.MapTile()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "986435b059b74d65976343b06894548f",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"MapTile(align_center=True, children=[Card(children=[Html(children=[''], layout=None, tag='h2'), Flex(children=…"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"map_tile"
]
Expand Down
26 changes: 25 additions & 1 deletion ui.ipynb
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "6f434bc9",
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"from pathlib import Path\n",
"import ee\n",
"\n",
"\n",
"def authenticate_gee():\n",
" \"\"\"Authenticate GEE using the credentials file in the user's home directory.\"\"\"\n",
" credential_folder_path = Path.home() / \".config\" / \"earthengine\"\n",
" credential_file_path = credential_folder_path / \"credentials\"\n",
" credentials = json.loads(credential_file_path.read_text())\n",
" project = credentials.get(\"project_id\", credentials.get(\"project\", None))\n",
" ee.Initialize(project=project)\n",
" assert ee.data.getAssetRoots(), \"Error: You have not initialized the GEE home folder. Please follow the the SEPAL documentation: https://docs.sepal.io/en/latest/setup/gee.html#initialize-the-home-folder.\"\n",
" \n",
"authenticate_gee()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -108,7 +132,7 @@
],
"metadata": {
"kernelspec": {
"display_name": " (venv) PlanetLab order (beta)",
"display_name": "(venv) planet-order",
"language": "python",
"name": "venv-planet-order"
},
Expand Down

0 comments on commit 943b2ba

Please sign in to comment.