[ARVADOS-WORKBENCH2] updated: 1.1.4-428-gf7cf9da
Git user
git at public.curoverse.com
Wed Jul 25 10:58:20 EDT 2018
Summary of changes:
.env | 3 ++-
src/common/api/server-api.ts | 21 +++++++++++++--------
src/common/config.ts | 17 ++++++++++++-----
src/services/auth-service/auth-service.ts | 10 ++++++----
src/services/services.ts | 10 +++++-----
src/store/auth/auth-reducer.test.ts | 5 ++---
src/store/details-panel/details-panel-action.ts | 8 ++++----
7 files changed, 44 insertions(+), 30 deletions(-)
via f7cf9da472181411b7faaebd02008f012b247a94 (commit)
via 362a1f5afe16f1b9c13b6d3c9fc2638ef0b7bf43 (commit)
from a61404f0dafe868691ef0324c834e93138b9dd08 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
commit f7cf9da472181411b7faaebd02008f012b247a94
Merge: a61404f 362a1f5
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Wed Jul 25 16:57:20 2018 +0200
Merge branch '13819-fix-dynamic-url-configuration'
refs #13819
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
commit 362a1f5afe16f1b9c13b6d3c9fc2638ef0b7bf43
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Wed Jul 25 16:56:43 2018 +0200
Reorganiza service to make use of dynamic config
Feature #13819
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/.env b/.env
index a523865..ed397c5 100644
--- a/.env
+++ b/.env
@@ -3,4 +3,5 @@
# SPDX-License-Identifier: AGPL-3.0
REACT_APP_ARVADOS_CONFIG_URL=/config.json
-REACT_APP_ARVADOS_API_HOST=https://qr1hi.arvadosapi.com
\ No newline at end of file
+REACT_APP_ARVADOS_API_HOST=qr1hi.arvadosapi.com
+HTTPS=true
\ No newline at end of file
diff --git a/src/common/api/server-api.ts b/src/common/api/server-api.ts
index 5beecd4..bcd2f65 100644
--- a/src/common/api/server-api.ts
+++ b/src/common/api/server-api.ts
@@ -6,19 +6,24 @@ import Axios, { AxiosInstance } from "axios";
export const API_HOST = process.env.REACT_APP_ARVADOS_API_HOST;
-export const serverApi: AxiosInstance = Axios.create({
- baseURL: API_HOST + '/arvados/v1'
-});
+export const authClient: AxiosInstance = Axios.create();
+export const apiClient: AxiosInstance = Axios.create();
export function setServerApiAuthorizationHeader(token: string) {
- serverApi.defaults.headers.common = {
- 'Authorization': `OAuth2 ${token}`
- };}
+ [authClient, apiClient].forEach(client => {
+ client.defaults.headers.common = {
+ Authorization: `OAuth2 ${token}`
+ };
+ });
+}
export function removeServerApiAuthorizationHeader() {
- delete serverApi.defaults.headers.common.Authorization;
+ [authClient, apiClient].forEach(client => {
+ delete client.defaults.headers.common.Authorization;
+ });
}
export const setBaseUrl = (url: string) => {
- serverApi.defaults.baseURL = url + "/arvados/v1";
+ authClient.defaults.baseURL = url;
+ apiClient.defaults.baseURL = url + "/arvados/v1";
};
diff --git a/src/common/config.ts b/src/common/config.ts
index 4b4a52a..775b114 100644
--- a/src/common/config.ts
+++ b/src/common/config.ts
@@ -10,14 +10,21 @@ export interface Config {
API_HOST: string;
}
-const defaultConfig: Config = {
- API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || ""
-};
-
export const fetchConfig = () => {
return Axios
.get<Config>(CONFIG_URL + "?nocache=" + (new Date()).getTime())
.then(response => response.data)
- .catch(() => Promise.resolve(defaultConfig));
+ .catch(() => Promise.resolve(getDefaultConfig()))
+ .then(mapConfig);
};
+const mapConfig = (config: Config): Config => ({
+ ...config,
+ API_HOST: addProtocol(config.API_HOST)
+});
+
+const getDefaultConfig = (): Config => ({
+ API_HOST: process.env.REACT_APP_ARVADOS_API_HOST || ""
+});
+
+const addProtocol = (url: string) => `${window.location.protocol}//${url}`;
diff --git a/src/services/auth-service/auth-service.ts b/src/services/auth-service/auth-service.ts
index 1879e6a..551d435 100644
--- a/src/services/auth-service/auth-service.ts
+++ b/src/services/auth-service/auth-service.ts
@@ -24,7 +24,9 @@ export interface UserDetailsResponse {
export class AuthService {
- constructor(protected serverApi: AxiosInstance) { }
+ constructor(
+ protected authClient: AxiosInstance,
+ protected apiClient: AxiosInstance) { }
public saveApiToken(token: string) {
localStorage.setItem(API_TOKEN_KEY, token);
@@ -76,16 +78,16 @@ export class AuthService {
public login() {
const currentUrl = `${window.location.protocol}//${window.location.host}/token`;
- window.location.assign(`${API_HOST}/login?return_to=${currentUrl}`);
+ window.location.assign(`${this.authClient.defaults.baseURL || ""}/login?return_to=${currentUrl}`);
}
public logout() {
const currentUrl = `${window.location.protocol}//${window.location.host}`;
- window.location.assign(`${API_HOST}/logout?return_to=${currentUrl}`);
+ window.location.assign(`${this.authClient.defaults.baseURL || ""}/logout?return_to=${currentUrl}`);
}
public getUserDetails = (): Promise<User> => {
- return this.serverApi
+ return this.apiClient
.get<UserDetailsResponse>('/users/current')
.then(resp => ({
email: resp.data.email,
diff --git a/src/services/services.ts b/src/services/services.ts
index f0afd76..a08ed3c 100644
--- a/src/services/services.ts
+++ b/src/services/services.ts
@@ -4,13 +4,13 @@
import { AuthService } from "./auth-service/auth-service";
import { GroupsService } from "./groups-service/groups-service";
-import { serverApi } from "../common/api/server-api";
+import { authClient, apiClient } from "../common/api/server-api";
import { ProjectService } from "./project-service/project-service";
import { LinkService } from "./link-service/link-service";
import { FavoriteService } from "./favorite-service/favorite-service";
-export const authService = new AuthService(serverApi);
-export const groupsService = new GroupsService(serverApi);
-export const projectService = new ProjectService(serverApi);
-export const linkService = new LinkService(serverApi);
+export const authService = new AuthService(authClient, apiClient);
+export const groupsService = new GroupsService(apiClient);
+export const projectService = new ProjectService(apiClient);
+export const linkService = new LinkService(apiClient);
export const favoriteService = new FavoriteService(linkService, groupsService);
diff --git a/src/store/auth/auth-reducer.test.ts b/src/store/auth/auth-reducer.test.ts
index ea08e58..778b500 100644
--- a/src/store/auth/auth-reducer.test.ts
+++ b/src/store/auth/auth-reducer.test.ts
@@ -12,7 +12,6 @@ import {
USER_OWNER_UUID_KEY,
USER_UUID_KEY
} from "../../services/auth-service/auth-service";
-import { API_HOST } from "../../common/api/server-api";
import 'jest-localstorage-mock';
@@ -96,7 +95,7 @@ describe('auth-reducer', () => {
window.location.assign = jest.fn();
authReducer(initialState, authActions.LOGIN());
expect(window.location.assign).toBeCalledWith(
- `${API_HOST}/login?return_to=${window.location.protocol}//${window.location.host}/token`
+ `/login?return_to=${window.location.protocol}//${window.location.host}/token`
);
});
@@ -105,7 +104,7 @@ describe('auth-reducer', () => {
window.location.assign = jest.fn();
authReducer(initialState, authActions.LOGOUT());
expect(window.location.assign).toBeCalledWith(
- `${API_HOST}/logout?return_to=${location.protocol}//${location.host}`
+ `/logout?return_to=${location.protocol}//${location.host}`
);
});
});
diff --git a/src/store/details-panel/details-panel-action.ts b/src/store/details-panel/details-panel-action.ts
index ba330f2..974346e 100644
--- a/src/store/details-panel/details-panel-action.ts
+++ b/src/store/details-panel/details-panel-action.ts
@@ -5,7 +5,7 @@
import { unionize, ofType, UnionOf } from "unionize";
import { CommonResourceService } from "../../common/api/common-resource-service";
import { Dispatch } from "redux";
-import { serverApi } from "../../common/api/server-api";
+import { apiClient } from "../../common/api/server-api";
import { Resource, ResourceKind } from "../../models/resource";
export const detailsPanelActions = unionize({
@@ -29,11 +29,11 @@ export const loadDetails = (uuid: string, kind: ResourceKind) =>
const getService = (kind: ResourceKind) => {
switch (kind) {
case ResourceKind.Project:
- return new CommonResourceService(serverApi, "groups");
+ return new CommonResourceService(apiClient, "groups");
case ResourceKind.Collection:
- return new CommonResourceService(serverApi, "collections");
+ return new CommonResourceService(apiClient, "collections");
default:
- return new CommonResourceService(serverApi, "");
+ return new CommonResourceService(apiClient, "");
}
};
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list