Browse Source

[api] Have get_config into both private and public URLs

Romain Rigaux 4 years ago
parent
commit
ab9551da1e

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

@@ -20,7 +20,7 @@ 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_PRIVATE_API = '/desktop/api2/get_config/';
 export const FETCH_CONFIG_API = '/api/iam/get_config/';
 export const HDFS_API_PREFIX = '/filebrowser/view=' + encodeURIComponent('/');
 export const ADLS_API_PREFIX = '/filebrowser/view=' + encodeURIComponent('adl:/');

+ 1 - 1
desktop/core/src/desktop/js/apps/editor/components/sqlScratchpad/SqlScratchpad.vue

@@ -155,7 +155,7 @@
         }
 
         try {
-          await getConfig();
+          await getConfig(true);
         } catch (err) {
           errorMessage.value = 'Failed loading the Hue config!';
           console.error(err);

+ 5 - 3
desktop/core/src/desktop/js/config/hueConfig.ts

@@ -47,10 +47,11 @@ type ConnectorTest<T extends keyof InterpreterMap> = (connector: InterpreterMap[
 let lastConfigPromise: Promise<HueConfig> | undefined;
 let lastKnownConfig: HueConfig | undefined;
 
-export const refreshConfig = async (): Promise<HueConfig> => {
+export const refreshConfig = async (viaApi?: boolean): Promise<HueConfig> => {
   lastConfigPromise = new Promise<HueConfig>(async (resolve, reject) => {
     try {
-      const apiResponse = await post<HueConfig>(URLS.FETCH_CONFIG_API, {}, { silenceErrors: true });
+      const url = viaApi ? URLS.FETCH_CONFIG_API : URLS.FETCH_CONFIG_PRIVATE_API;
+      const apiResponse = await post<HueConfig>(url, {}, { silenceErrors: true });
       if (apiResponse.status == 0) {
         lastKnownConfig = apiResponse;
         resolve(lastKnownConfig);
@@ -76,7 +77,8 @@ export const refreshConfig = async (): Promise<HueConfig> => {
 
 export const getLastKnownConfig = (): HueConfig | undefined => lastKnownConfig;
 
-export const getConfig = async (): Promise<HueConfig> => getLastKnownConfig() || refreshConfig();
+export const getConfig = async (viaApi?: boolean): Promise<HueConfig> =>
+  getLastKnownConfig() || refreshConfig(viaApi);
 
 const getInterpreters = <T extends keyof InterpreterMap>(appType: T): InterpreterMap[T][] => {
   if (!lastKnownConfig || !lastKnownConfig.app_config) {