Commit 2aa60a4e authored by Axel Bocciarelli's avatar Axel Bocciarelli
Browse files

Merge branch 'more-env' into 'master'

Add env vars for icat.js config

See merge request !434
parents bd8fcca2 9f2441a4
Pipeline #32491 passed with stages
in 7 minutes and 36 seconds
......@@ -10,5 +10,10 @@ EXTEND_ESLINT=true
# To override one of these variables in development, create a file called `.env.local`.
#####
# ICAT+ SERVER URL
# ICAT+ server URL
REACT_APP_ICATPLUS_URL=http://localhost:8000
# Authentication methods
REACT_APP_SSO_AUTH_ENABLED=true
REACT_APP_ANONYMOUS_AUTH_ENABLED=true
REACT_APP_DB_AUTH_ENABLED=true
# ICAT+ SERVER URL
# ICAT+ production server URL
REACT_APP_ICATPLUS_URL=https://icatplus.esrf.fr
# ICAT+ SERVER URL
# Use fake ICAT+ SERVER URL
REACT_APP_ICATPLUS_URL=https://icatplus.test
# Disable SSO authentication
REACT_APP_SSO_AUTH_ENABLED=false
# Configurations files
/src/config/icat/icat.js
# Local environment files
.env.local
.env.development.local
......
......@@ -11,7 +11,6 @@ Lint:
image: node:12.14.1
script:
- npm ci
- npm run configure
- npm run lint
Test:
......@@ -19,7 +18,6 @@ Test:
image: node:12.14.1
script:
- npm ci
- npm run configure
- npm run test
.docker-template:
......
......@@ -3,6 +3,7 @@
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"firefox-devtools.vscode-firefox-debug"
"firefox-devtools.vscode-firefox-debug",
"mikestead.dotenv"
]
}
{
"version": "0.2.0",
"configurations": [
{
"type": "firefox",
"request": "launch",
"name": "Launch Firefox against locaholst",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
......@@ -15,27 +15,21 @@ Currently, datahub depends on:
# Menu
1. [Installation](#installation)
2. [Configuration](#configuration)
3. [Developments](#developments)
- [Installation](#installation)
- [Configuration](#configuration)
- [Developments](#developments)
# Installation
## Prerequisite:
1. Make sure the dependencies mentioned above are installed and properly configured.
## Installation procedure
1. Clone or download the project from [GitLab](https://gitlab.esrf.fr/icat/E-DataPortal)
2. Install the dependencies
1. Install the dependencies
```bash
npm install
```
3. [Configure the app](#configuration)
4. Start the app
1. Start the app
```bash
npm start
......@@ -53,86 +47,19 @@ Datahub configuration is spread among different files located in <kbd>src/config
Some of the configuration options in these files are stored in [environment variables](#environment-variables).
Example file for [icat.js](src/config/icat/icat.example.js) is provided and needs to be copied in configuration file:
You can copy it manually:
```bash
cp src/config/icat/icat.example.js src/config/icat/icat.js
```
or run:
```
npm run-script configure
```
## Environment variables
Create React App loads environment variables from [environment files](https://create-react-app.dev/docs/adding-custom-environment-variables/#what-other-env-files-can-be-used) (<kbd>.env</kbd>, <kbd>.env.test</kbd>, etc.) according to the Node environment (`NODE_ENV`).
File <kbd>.env</kbd> is loaded in every environment with the lowest priority and is therefore used to declare default values and development fallbacks.
The following portal configuration variable is currently declared in <kbd>.env</kbd>:
The following portal configuration variables are declared in <kbd>.env</kbd>:
- `REACT_APP_ICATPLUS_URL` - the URL of the ICAT+ server (used in <kbd>src/config/icatPlus.js</kbd>)
- `REACT_APP_SSO_AUTH_ENABLED` - whether to allow users to sign-in to ICAT with SSO (used in <kbd>src/config/icat.js</kbd>)
- `REACT_APP_ANONYMOUS_AUTH_ENABLED` - whether to allow users to sign-in to ICAT as anonymous (used in <kbd>src/config/icat.js</kbd>)
- `REACT_APP_DB_AUTH_ENABLED` - whether to allow users to sign-in to ICAT with database credentials (used in <kbd>src/config/icat.js</kbd>)
In development, you can override this variable by creating a file called `.env.local`. This file is ignored from version control.
## icat.js
Edit the file **icat.js** with your favorite text editor and set the configuration to access the metadata catalogue following the indications below.
<!--START configurationICAT -->
```js
/**
* icat.example.js configuration file
*/
var ICAT = {
authentication: {
/** Single sign-on configuration */
sso: {
enabled: true,
/** ICAT authentication plugin for json web tokens */
plugin: 'esrf',
/** Configuration to be passed to keycloak.js (https://github.com/keycloak/keycloak-documentation/blob/master/securing_apps/topics/oidc/javascript-adapter.adoc) */
configuration: {
realm: 'ESRF',
url: 'https://websso.esrf.fr/auth/',
clientId: 'icat',
},
},
/** Anonymous user's credentials*/
anonymous: {
enabled: true,
/** ICAT plugin used for authentication. */
plugin: 'db',
/** Username for the anonymous user */
username: 'reader',
/** Password for the anonymous user */
password: 'reader',
},
authenticators: [
{
plugin: 'esrf',
/** title will be displayed as the title of the Tab at the login Form */
title: 'ESRF',
/** If will be hidden in the login form */
hidden: false,
},
{
plugin: 'db',
title: 'Database',
hidden: false,
},
],
},
};
export default ICAT;
```
<!--END configurationICAT -->
In development, you can override any of these variables by creating a file called `.env.local`. This file is ignored from version control.
## techniques.js
......
......@@ -8,13 +8,10 @@
"npm": "6.x"
},
"scripts": {
"build": "npm run configure && react-scripts build",
"configure": "echo 'Copying config/icat/icat.example.js' && cp src/config/icat/icat.example.js src/config/icat/icat.js",
"build": "react-scripts build",
"start": "react-scripts start",
"test": "react-scripts test --env=jsdom-fourteen",
"doc": "npm run Readme:ConfigDoc:ICAT && npm run Readme:ConfigDoc:ICAT:ReplaceCodeSection && npm run Readme:ConfigDoc:ICATPlus && npm run Readme:ConfigDoc:ICATPlus:ReplaceCodeSection && npm run Readme:ConfigDoc:Config && npm run Readme:ConfigDoc:Config:ReplaceCodeSection",
"Readme:ConfigDoc:ICAT": "node ./node_modules/jscat/bin/jscat src/config/icat/icat.example.js | node ./node_modules/injectmd/bin/cli.js -t configurationICAT -i Readme.md",
"Readme:ConfigDoc:ICAT:ReplaceCodeSection": "./node_modules/replace/bin/replace.js '<!--START configurationICAT -->' '<!--START configurationICAT -->\n```js' Readme.md && ./node_modules/replace/bin/replace.js '<!--END configurationICAT -->' '```\n<!--END configurationICAT -->' Readme.md",
"Readme:ConfigDoc:Config": "node ./node_modules/jscat/bin/jscat src/config/ui/config.js | node ./node_modules/injectmd/bin/cli.js -t config -i Readme.md",
"Readme:ConfigDoc:Config:ReplaceCodeSection": "./node_modules/replace/bin/replace.js '<!--START config -->' '<!--START config -->\n```js' Readme.md && ./node_modules/replace/bin/replace.js '<!--END config -->' '```\n<!--END config -->' Readme.md",
"complexity-report": "./node_modules/.bin/es6-plato -r -d ./public/report src",
......
......@@ -25,7 +25,7 @@ import MintSelectionPage from './containers/Selection/MintSelectionPage';
import BeamlineDataPage from './containers/BeamlineDataPage';
import { getRemainingSessionTime } from './helpers/auth';
import { doLogOut, doSilentRefreshFromSSO } from './actions/login';
import keycloak from './config/sso/keycloak';
import keycloak from './keycloak';
import Menu from './components/Menu/Menu';
import { fetchAllInvestigations } from './actions/investigations';
import { fetchDataCollections } from './actions/datacollections';
......
......@@ -6,7 +6,7 @@ import {
LOG_IN,
LOG_OUT,
} from '../constants/actionTypes';
import keycloak from '../config/sso/keycloak';
import keycloak from '../keycloak';
import ICAT from '../config/icat/icat';
export function doLogOut(params = { expired: false }) {
......
......@@ -3,7 +3,7 @@ import UI from '../../config/ui/config';
import Loader from '../Loader';
import ErrorUserMessage from '../UserMessages/ErrorUserMessage';
import AnonymousSignIn from './AnonymousSignIn';
import keycloak from '../../config/sso/keycloak';
import keycloak from '../../keycloak';
import { useSelector } from 'react-redux';
import { useLocation } from 'react-router';
import { Button, Alert } from 'react-bootstrap';
......
......@@ -5,7 +5,7 @@ import { Link } from 'react-router-dom';
import UI from '../../config/ui/config';
import BreadCrumbs from '../Breadcrumbs/BreadCrumbs';
import ManagerMenu from './ManagerMenu';
import keycloak from '../../config/sso/keycloak';
import keycloak from '../../keycloak';
import { useSelector, useDispatch } from 'react-redux';
import { doLogOut } from '../../actions/login';
import { fetchInvestigationsAsInstrumentScientist } from '../../actions/investigations';
......
/**
* icat.example.js configuration file
*/
const ICAT = {
authentication: {
/** Single sign-on configuration */
// Single sign-on configuration
sso: {
enabled: true,
/** ICAT authentication plugin for json web tokens */
enabled: process.env.REACT_APP_SSO_AUTH_ENABLED,
plugin: 'esrf',
/** Configuration to be passed to keycloak.js (https://github.com/keycloak/keycloak-documentation/blob/master/securing_apps/topics/oidc/javascript-adapter.adoc) */
// Keycloak configuration - https://www.keycloak.org/docs/latest/securing_apps/#_javascript_adapter
configuration: {
realm: 'ESRF',
url: 'https://websso.esrf.fr/auth/',
clientId: 'icat',
},
},
/** Anonymous user's credentials*/
// Anonymous user's credentials
anonymous: {
enabled: true,
/** ICAT plugin used for authentication. */
enabled: process.env.REACT_APP_ANONYMOUS_AUTH_ENABLED,
plugin: 'db',
/** Username for the anonymous user */
username: 'reader',
/** Password for the anonymous user */
password: 'reader',
},
authenticators: [
{
plugin: 'esrf',
/** title will be displayed as the title of the Tab at the login Form */
title: 'ESRF',
/** If will be hidden in the login form */
hidden: true,
},
// Database authenticator
{
plugin: 'db',
title: 'Database',
hidden: false,
hidden: !process.env.REACT_APP_DB_AUTH_ENABLED,
},
],
},
......
import moment from 'moment';
import { store } from '../store';
import { doLogOut, doSignIn } from '../actions/login';
import keycloak from '../config/sso/keycloak';
import keycloak from '../keycloak';
import ICAT from '../config/icat/icat';
export function getRemainingSessionTime(expirationTime) {
......
......@@ -20,7 +20,7 @@ import { unregister } from './registerServiceWorker';
import { persistor, store } from './store';
import ScrollToTop from './components/ScrollToTop';
import { BrowserRouter } from 'react-router-dom';
import keycloak from './config/sso/keycloak';
import keycloak from './keycloak';
import { checkExpirationTime, matchAuthStateToSSO } from './helpers/auth';
import { doLogOut } from './actions/login';
......
import Keycloak from 'keycloak-js';
import ICAT from '../icat/icat';
import ICAT from './config/icat/icat';
const keycloak = ICAT.authentication.sso.enabled
? new Keycloak(ICAT.authentication.sso.configuration)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment