From 990b8f30ff361410545815aa57e80d8193ff1c58 Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Tue, 19 May 2020 15:09:14 +0200 Subject: [PATCH] Remove env.js and any hardcoded keycloak configs We now expect the users to pass the right config to vpu-auth. Only the API endpoint config remains which we haven't figured out how to deal with in all cases. --- packages/common/env.js | 43 ------------------------------ packages/common/errorreport.js | 7 ++--- packages/common/test/unit.js | 4 --- packages/common/utils.js | 31 ++++++++++++--------- packages/common/vpu-common-demo.js | 2 +- 5 files changed, 24 insertions(+), 63 deletions(-) delete mode 100644 packages/common/env.js diff --git a/packages/common/env.js b/packages/common/env.js deleted file mode 100644 index 664aa270..00000000 --- a/packages/common/env.js +++ /dev/null @@ -1,43 +0,0 @@ -import environment from 'consts:environment'; - -var config; - -switch(environment) { - case "development": - config = { - apiBaseUrl: 'https://mw-dev.tugraz.at', - keyCloakBaseURL: 'https://auth-dev.tugraz.at/auth', - keyCloakRealm: 'tugraz', - keyCloakClientId: 'auth-dev-mw-frontend', - //sentryDSN: 'http://0405d811e8d746cca2e70f6eff764570@129.27.166.25:9000/2', - }; - - break; - case "demo": - config = { - apiBaseUrl: 'https://api-demo.tugraz.at', - keyCloakBaseURL: 'https://auth-test.tugraz.at/auth', - keyCloakRealm: 'tugraz', - keyCloakClientId: 'ibib-demo_tugraz_at-IBIB', - }; - break; - case "production": - config = { - apiBaseUrl: 'https://api.tugraz.at', - keyCloakBaseURL: 'https://auth.tugraz.at/auth', - keyCloakRealm: 'tugraz', - keyCloakClientId: 'ibib_tugraz_at-IBIB', - }; - break; - case "local": - default: - config = { - apiBaseUrl: 'http://127.0.0.1:8000', - keyCloakBaseURL: 'https://auth-dev.tugraz.at/auth', - keyCloakRealm: 'tugraz', - keyCloakClientId: 'auth-dev-mw-frontend-local', - }; -} - - -export default config; \ No newline at end of file diff --git a/packages/common/errorreport.js b/packages/common/errorreport.js index 31276934..d1cfcb18 100644 --- a/packages/common/errorreport.js +++ b/packages/common/errorreport.js @@ -1,10 +1,11 @@ import * as Sentry from '@sentry/browser'; -import env from './env.js'; import environment from 'consts:environment'; let _isInitialized = false; let _canReportEvent = false; +let sentryDSN = ''; + /** * Initializes error reporting. * @@ -29,7 +30,7 @@ export function init(options) { sentryOptions['release'] = actual.release; } - if (!env.sentryDSN) { + if (!sentryDSN) { if (options.debug) console.log("No sentry DSN set, sentry disabled"); @@ -42,7 +43,7 @@ export function init(options) { return null; }; } else { - sentryOptions['dsn'] = env.sentryDSN; + sentryOptions['dsn'] = sentryDSN; _canReportEvent = true; } diff --git a/packages/common/test/unit.js b/packages/common/test/unit.js index 98b40049..17d7f7f1 100644 --- a/packages/common/test/unit.js +++ b/packages/common/test/unit.js @@ -38,10 +38,6 @@ suite('utils', () => { assert(utils.getAPiUrl().startsWith("http")); }); - test('setting', () => { - assert(utils.setting('apiBaseUrl').startsWith("http")); - }); - test('getAssetURL', () => { assert.equal(new URL(utils.getAssetURL("foo/bar")).pathname, "/foo/bar"); }); diff --git a/packages/common/utils.js b/packages/common/utils.js index 3afb0173..eeac3fd1 100644 --- a/packages/common/utils.js +++ b/packages/common/utils.js @@ -1,4 +1,4 @@ -import env from './env.js'; +import environment from 'consts:environment'; /** * Parses a link header @@ -30,18 +30,25 @@ export const parseLinkHeader = (header) => { return links; }; -/** - * Reads a setting - * - * @param key - * @returns {*} - */ -export const setting = (key) => { - return env[key]; -}; - export const getAPiUrl = (path = "") => { - return env.apiBaseUrl + path; + let apiBaseUrl = ''; + + switch(environment) { + case "development": + apiBaseUrl = 'https://mw-dev.tugraz.at'; + break; + case "demo": + apiBaseUrl = 'https://api-demo.tugraz.at'; + break; + case "production": + apiBaseUrl = 'https://api.tugraz.at'; + break; + case "local": + default: + apiBaseUrl = 'http://127.0.0.1:8000'; + } + + return apiBaseUrl + path; }; /** diff --git a/packages/common/vpu-common-demo.js b/packages/common/vpu-common-demo.js index 9b5e1825..16b12d91 100644 --- a/packages/common/vpu-common-demo.js +++ b/packages/common/vpu-common-demo.js @@ -80,7 +80,7 @@ class VpuCommonDemo extends ScopedElementsMixin(LitElement) { getAuthComponentHtml() { return this.noAuth ? html`` : html` <div class="container"> - <vpu-auth lang="${this.lang}" client-id="${commonUtils.setting('keyCloakClientId')}" load-person></vpu-auth> + <vpu-auth lang="${this.lang}" load-person></vpu-auth> </div> `; } -- GitLab