Ver Fonte

[api] Add endpoint for namespace config and dual auth

Romain Rigaux há 4 anos atrás
pai
commit
73ac02b1c8

+ 5 - 0
desktop/core/src/desktop/api_public.py

@@ -31,6 +31,11 @@ def get_config(request):
 
   return desktop_api.get_config(django_request)
 
+@api_view(["GET"])
+def get_context_namespaces(request, interface):
+  django_request = request._request
+  return desktop_api.get_context_namespaces(django_request, interface)
+
 
 @api_view(["POST"])
 def create_notebook(request):

+ 1 - 0
desktop/core/src/desktop/api_public_urls.py

@@ -36,6 +36,7 @@ urlpatterns = [
 # e.g. https://demo.gethue.com/notebook/api/execute/hive
 urlpatterns += [
   re_path(r'^iam/get_config/?$', api_public.get_config),
+  re_path(r'^iam/get_namespaces/(?P<interface>[\w\-]+)/?$', api_public.get_context_namespaces),  # To remove
 
   re_path(r'^editor/create_notebook/?$', api_public.create_notebook, name='api_create_notebook'),
   re_path(r'^editor/create_session/?$', api_public.create_session, name='api_create_session'),

+ 1 - 1
desktop/core/src/desktop/js/api/urls.js

@@ -21,8 +21,8 @@ export const EXECUTE_API_PREFIX = '/notebook/api/execute/';
 export const DOCUMENTS_API = '/desktop/api2/doc/';
 export const DOCUMENTS_SEARCH_API = '/desktop/api2/docs/';
 export const GET_HUE_CONFIG_API = '/desktop/api2/get_hue_config';
-// export const FETCH_CONFIG_API = '/desktop/api2/get_config/';
 export const FETCH_CONFIG_API = '/api/iam/get_config/';
+export const FETCH_CONFIG_API_PRIVATE = '/desktop/api2/get_config/';
 export const HDFS_API_PREFIX = '/filebrowser/view=' + encodeURIComponent('/');
 export const ADLS_API_PREFIX = '/filebrowser/view=' + encodeURIComponent('adl:/');
 export const ABFS_API_PREFIX = '/filebrowser/view=' + encodeURIComponent('ABFS://');

+ 2 - 4
desktop/core/src/desktop/js/catalog/api.ts

@@ -57,7 +57,7 @@ interface SampleFetchOptions extends SharedFetchOptions {
 }
 
 const AUTOCOMPLETE_URL_PREFIX = '/api/editor/autocomplete/';
-// const AUTOCOMPLETE_URL_PREFIX = '/notebook/api/autocomplete/';
+
 const CANCEL_STATEMENT_URL = '/notebook/api/cancel_statement';
 const CHECK_STATUS_URL = '/notebook/api/check_status';
 const DESCRIBE_URL = '/notebook/api/describe/';
@@ -195,9 +195,7 @@ export const fetchNamespaces = (
   connector: Connector,
   silenceErrors?: boolean
 ): CancellablePromise<Record<string, Namespace[]> & { dynamicClusters?: boolean }> =>
-  get(`/desktop/api2/context/namespaces/${connector.id}`, undefined, {
-    silenceErrors
-  });
+  get(`/api/iam/get_namespaces/${connector.id}`, undefined, { silenceErrors });
 
 export const fetchNavigatorMetadata = ({
   entry,

+ 1 - 1
desktop/core/src/desktop/js/config/hueConfig.ts

@@ -50,7 +50,7 @@ let lastKnownConfig: HueConfig | undefined;
 export const refreshConfig = async (viaApi?: boolean): Promise<HueConfig> => {
   lastConfigPromise = new Promise<HueConfig>(async (resolve, reject) => {
     try {
-      const url = viaApi ? URLS.FETCH_CONFIG_API : URLS.FETCH_CONFIG_PRIVATE_API;
+      const url = viaApi ? URLS.FETCH_CONFIG_API : URLS.FETCH_CONFIG_API_PRIVATE;
       const apiResponse = await post<HueConfig>(url, {}, { silenceErrors: true });
       if (apiResponse.status == 0) {
         lastKnownConfig = apiResponse;

+ 1 - 1
desktop/core/src/desktop/middleware.py

@@ -303,7 +303,7 @@ class LoginAndPermissionMiddleware(MiddlewareMixin):
     if request.path in ['/oidc/authenticate/', '/oidc/callback/', '/oidc/logout/', '/hue/oidc_failed/']:
       return None
 
-    if request.path.startswith('/api/'):
+    if request.path.startswith('/api/') or request.path == '/notebook/api/create_session':
       return None
 
     # Skip views not requiring login

+ 2 - 3
desktop/core/src/desktop/settings.py

@@ -285,12 +285,11 @@ CSRF_FAILURE_VIEW = 'desktop.views.csrf_failure'
 
 REST_FRAMEWORK = {
     'DEFAULT_PERMISSION_CLASSES': [
-      # 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly'
       'rest_framework.permissions.IsAuthenticated',
-      # 'rest_framework.permissions.AllowAny'
     ],
     'DEFAULT_AUTHENTICATION_CLASSES': (
       'rest_framework_simplejwt.authentication.JWTAuthentication',
+      'rest_framework.authentication.SessionAuthentication',
     ),
 }
 
@@ -301,7 +300,7 @@ JWT_AUTH = {
     'JWT_EXPIRATION_DELTA': datetime.timedelta(seconds=86400),
     'JWT_ALLOW_REFRESH': True,
     'JWT_REFRESH_EXPIRATION_DELTA': datetime.timedelta(days=7),
-     "JWT_AUTH_HEADER_PREFIX": "Bearer",
+    'JWT_AUTH_HEADER_PREFIX': 'Bearer',
 }
 
 ############################################################

+ 2 - 0
desktop/libs/notebook/src/notebook/api.py

@@ -26,6 +26,7 @@ import sys
 from django.urls import reverse
 from django.db.models import Q
 from django.views.decorators.http import require_GET, require_POST
+from rest_framework.decorators import api_view
 import opentracing.tracer
 
 from azure.abfs.__init__ import abfspath
@@ -102,6 +103,7 @@ def create_notebook(request):
   return JsonResponse(response)
 
 
+@api_view(["POST"])  # To fully port when Web Components are decoupled
 @require_POST
 @check_document_access_permission
 @api_error_handler