Skip to content

Commit

Permalink
feat: move health menu under Home menu #116
Browse files Browse the repository at this point in the history
  • Loading branch information
duttarnab committed Mar 7, 2022
1 parent 11927ed commit ae455c5
Show file tree
Hide file tree
Showing 19 changed files with 823 additions and 1 deletion.
11 changes: 11 additions & 0 deletions admin-ui/app/redux/actions/HealthAction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { GET_HEALTH, GET_HEALTH_RESPONSE } from './types'

export const getHealthStatus = (action) => ({
type: GET_HEALTH,
payload: { action },
})

export const getHealthStatusResponse = (data) => ({
type: GET_HEALTH_RESPONSE,
payload: { data },
})
26 changes: 26 additions & 0 deletions admin-ui/app/redux/actions/LicenseDetailsActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
GET_LICENSE_DETAILS,
GET_LICENSE_DETAILS_RESPONSE,
UPDATE_LICENSE_DETAILS,
UPDATE_LICENSE_DETAILS_RESPONSE,
} from './types'

export const getLicenseDetails = (action) => ({
type: GET_LICENSE_DETAILS,
payload: { action },
})

export const getLicenseDetailsResponse = (data) => ({
type: GET_LICENSE_DETAILS_RESPONSE,
payload: { data },
})

export const updateLicenseDetails = (action) => ({
type: UPDATE_LICENSE_DETAILS,
payload: { action },
})

export const updateLicenseDetailsResponse = (data) => ({
type: UPDATE_LICENSE_DETAILS_RESPONSE,
payload: { data },
})
10 changes: 9 additions & 1 deletion admin-ui/app/redux/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,12 @@ export const ACTIVATE_LICENSE = 'ACTIVATE_LICENSE'
export const ACTIVATE_LICENSE_RESPONSE = 'ACTIVATE_LICENSE_RESPONSE'
//OIDC DISCOVERY
export const GET_OIDC_DISCOVERY = 'GET_OIDC_DISCOVERY'
export const GET_OIDC_DISCOVERY_RESPONSE = 'GET_OIDC_DISCOVERY_RESPONSE'
export const GET_OIDC_DISCOVERY_RESPONSE = 'GET_OIDC_DISCOVERY_RESPONSE'
// Health
export const GET_HEALTH = 'GET_HEALTH'
export const GET_HEALTH_RESPONSE = 'GET_HEALTH_RESPONSE'
//License Details
export const GET_LICENSE_DETAILS = 'GET_LICENSE_DETAILS'
export const GET_LICENSE_DETAILS_RESPONSE = 'GET_LICENSE_DETAILS_RESPONSE'
export const UPDATE_LICENSE_DETAILS = 'UPDATE_LICENSE_DETAILS'
export const UPDATE_LICENSE_DETAILS_RESPONSE = 'UPDATE_LICENSE_DETAILS_RESPONSE'
18 changes: 18 additions & 0 deletions admin-ui/app/redux/api/HealthApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default class HealthApi {
constructor(api) {
this.api = api
}

getHealthStatus = () => {
return new Promise((resolve, reject) => {
this.api.getAuthServerHealth((error, data) => {
if (error) {
console.log(e);
reject(error)
} else {
resolve(data)
}
})
})
}
}
31 changes: 31 additions & 0 deletions admin-ui/app/redux/api/LicenseDetailsApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export default class LicenseDetailsApi {
constructor(api) {
this.api = api
}

getLicenseDetails = () => {
return new Promise((resolve, reject) => {
this.api.getAdminuiLicense((error, data) => {
this.handleResponse(error, reject, resolve, data)
})
})
}

updateLicenseDetails = (data) => {
const options = {}
options['licenseRequest'] = data
return new Promise((resolve, reject) => {
this.api.editAdminuiLicense(options, (error, options) => {
this.handleResponse(error, reject, resolve, data)
})
})
}

handleResponse(error, reject, resolve, data) {
if (error) {
reject(error)
} else {
resolve(data)
}
}
}
40 changes: 40 additions & 0 deletions admin-ui/app/redux/reducers/HealthReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { GET_HEALTH, GET_HEALTH_RESPONSE } from '../actions/types'
import reducerRegistry from './ReducerRegistry'
const INIT_STATE = {
serverStatus: null,
dbStatus: null,
loading: false,
}

const reducerName = 'healthReducer'

export default function healthReducer(state = INIT_STATE, action) {
switch (action.type) {
case GET_HEALTH:
return {
...state,
loading: true,
}
case GET_HEALTH_RESPONSE:
if (action.payload.data) {
return {
...state,
serverStatus: action.payload.data.status,
dbStatus: action.payload.data.db_status,
loading: false,
}
} else {
return handleDefault()
}
default:
return handleDefault()
}

function handleDefault() {
return {
...state,
loading: false,
}
}
}
reducerRegistry.register(reducerName, healthReducer)
54 changes: 54 additions & 0 deletions admin-ui/app/redux/reducers/LicenseDetailsReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { GET_LICENSE_DETAILS, GET_LICENSE_DETAILS_RESPONSE, UPDATE_LICENSE_DETAILS, UPDATE_LICENSE_DETAILS_RESPONSE } from '../actions/types'
import reducerRegistry from '../../redux/reducers/ReducerRegistry'
const INIT_STATE = {
item: {},
loading: true,
}

const reducerName = 'licenseDetailsReducer'

export default function licenseDetailsReducer(state = INIT_STATE, action) {
switch (action.type) {
case GET_LICENSE_DETAILS:
return {
...state,
loading: true,
}
case GET_LICENSE_DETAILS_RESPONSE:
if (action.payload.data) {
return {
...state,
item: action.payload.data,
loading: false,
}
} else {
return {
...state,
loading: false,
}
}
case UPDATE_LICENSE_DETAILS:
return {
...state,
loading: true,
}
case UPDATE_LICENSE_DETAILS_RESPONSE:
if (action.payload.data) {
return {
...state,
items: action.payload.data,
loading: false,
}
} else {
return {
...state,
loading: false,
}
}
default:
return {
...state,
}
}
}
reducerRegistry.register(reducerName, licenseDetailsReducer)
4 changes: 4 additions & 0 deletions admin-ui/app/redux/reducers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
* App Reducers
*/
import mauReducer from './MauReducer'
import healthReducer from './HealthReducer'
import authReducer from './AuthReducer'
import fidoReducer from './FidoReducer'
import initReducer from './InitReducer'
import logoutReducer from './LogoutReducer'
import licenseReducer from './LicenseReducer'
import licenseDetailsReducer from './LicenseDetailsReducer'
import oidcDiscoveryReducer from './OidcDiscoveryReducer'

const appReducers = {
Expand All @@ -17,6 +19,8 @@ const appReducers = {
licenseReducer,
oidcDiscoveryReducer,
mauReducer,
healthReducer,
licenseDetailsReducer,
}

export default appReducers
49 changes: 49 additions & 0 deletions admin-ui/app/redux/sagas/HealthSaga.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { call, all, put, fork, takeLatest, select } from 'redux-saga/effects'
import {
isFourZeroOneError,
addAdditionalData,
} from '../../utils/TokenController'
import { getHealthStatusResponse } from '../actions/HealthAction'
import { getAPIAccessToken } from '../actions/AuthActions'
import { postUserAction} from '../api/backend-api'
import { GET_HEALTH } from '../actions/types'
import HealthApi from '../api/HealthApi'
import { getClient } from '../api/base'
import { initAudit } from '../sagas/SagaUtils'
const JansConfigApi = require('jans_config_api')

function* newFunction() {
const token = yield select((state) => state.authReducer.token.access_token)
const issuer = yield select((state) => state.authReducer.issuer)
const api = new JansConfigApi.AuthServerHealthCheckApi(
getClient(JansConfigApi, token, issuer),
)
return new HealthApi(api)
}

export function* getHealthStatus({ payload }) {
const audit = yield* initAudit()
try {
payload = payload ? payload : { action: {} }
addAdditionalData(audit, 'FETCH', 'Health', payload)
const healthApi = yield* newFunction()
const data = yield call(healthApi.getHealthStatus, payload.action.action_data)
yield put(getHealthStatusResponse(data))
yield call(postUserAction, audit)
} catch (e) {

yield put(getHealthStatusResponse(null))
if (isFourZeroOneError(e)) {
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
yield put(getAPIAccessToken(jwt))
}
}
}

export function* watchGetHealthStatus() {
yield takeLatest(GET_HEALTH, getHealthStatus)
}

export default function* rootSaga() {
yield all([fork(watchGetHealthStatus)])
}
73 changes: 73 additions & 0 deletions admin-ui/app/redux/sagas/LicenseDetailsSaga.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { all, call, fork, put, takeEvery, select } from 'redux-saga/effects'
import { GET_LICENSE_DETAILS, UPDATE_LICENSE_DETAILS } from '../actions/types'
import {
getLicenseDetailsResponse,
updateLicenseDetailsResponse,
} from '../actions/LicenseDetailsActions'
import { getClient } from '../../redux/api/base'
import LicenseDetailsApi from '../api/LicenseDetailsApi'
const JansConfigApi = require('jans_config_api')
import { initAudit } from '../../redux/sagas/SagaUtils'
import {
isFourZeroOneError,
addAdditionalData,
} from '../../utils/TokenController'
import { getAPIAccessToken } from '../../redux/actions/AuthActions'

function* newFunction() {
const token = yield select((state) => state.authReducer.token.access_token)
const issuer = yield select((state) => state.authReducer.issuer)
const api = new JansConfigApi.AdminUILicenseApi(
getClient(JansConfigApi, token, issuer),
)
return new LicenseDetailsApi(api)
}


export function* getLicenseDetailsWorker({ payload }) {
const audit = yield* initAudit()
try {
//addAdditionalData(audit, FETCH, GET_LICENSE_DETAILS, payload)
const licenseApi = yield* newFunction()
const data = yield call(licenseApi.getLicenseDetails)
yield put(getLicenseDetailsResponse(data))
yield call(postUserAction, audit)
} catch (e) {
yield put(getLicenseDetailsResponse(null))
if (isFourZeroOneError(e)) {
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
yield put(getAPIAccessToken(jwt))
}
}
}

export function* updateLicenseDetailsWorker({ payload }) {
const audit = yield* initAudit()
try {
//addAdditionalData(audit, UPDATE, UPDATE_LICENSE_DETAILS, payload)
const roleApi = yield* newFunction()
const data = yield call(roleApi.updateLicenseDetails, payload.action.action_data)
yield put(updateLicenseDetailsResponse(data))
yield call(postUserAction, audit)
} catch (e) {
yield put(updateLicenseDetailsResponse(null))
if (isFourZeroOneError(e)) {
const jwt = yield select((state) => state.authReducer.userinfo_jwt)
yield put(getAPIAccessToken(jwt))
}
}
}


export function* getLicenseWatcher() {

yield takeEvery(GET_LICENSE_DETAILS, getLicenseDetailsWorker)
}

export function* updateLicenseWatcher() {
yield takeEvery(UPDATE_LICENSE_DETAILS, updateLicenseDetailsWorker)
}

export default function* rootSaga() {
yield all([fork(getLicenseWatcher), fork(updateLicenseWatcher)])
}
4 changes: 4 additions & 0 deletions admin-ui/app/redux/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { all } from 'redux-saga/effects'

// sagas
import mauSaga from './MauSaga'
import healthSaga from './HealthSaga'
import authSagas from './AuthSaga'
import fidoSaga from './FidoSaga'
import initSaga from './InitSaga'
import licenseSaga from './LicenseSaga'
import licenseDetailsSaga from './LicenseDetailsSaga'
import oidcDiscoverySaga from './OidcDiscoverySaga'
import process from '../../../plugins/PluginSagasResolver'

Expand All @@ -23,6 +25,8 @@ export default function* rootSaga() {
licenseSaga(),
oidcDiscoverySaga(),
mauSaga(),
healthSaga(),
licenseDetailsSaga(),
],
pluginSagaArr,
),
Expand Down
12 changes: 12 additions & 0 deletions admin-ui/app/routes/Apps/Gluu/GluuAppSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ function GluuAppSidebar({ scopes }) {
textStyle={{ fontSize: '18px', fontWeight: '600' }}
exact
/>
<SidebarMenu.Item
title={t('menus.health')}
to="/home/health"
textStyle={{ fontSize: '18px', fontWeight: '600' }}
exact
/>
<SidebarMenu.Item
title={t('menus.license')}
to="/home/licenseDetails"
textStyle={{ fontSize: '18px', fontWeight: '600' }}
exact
/>
</SidebarMenu.Item>
<Divider />
{/* -------- Plugins ---------*/}
Expand Down
Loading

0 comments on commit ae455c5

Please sign in to comment.