-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* mongodb version added to appLayer, repos * bit of refactor to make system info elements follow conventions * mongodbversion display on about page, add enviromentInfo * systemInfo tests, authApiAppender moved into /api endpoint * PR fixes * mongodbversion typo * typo * config.js versions * [service] add semantic version components to system info and test stub * WIP - tests,app.systemInfo,webController * version assertion change, string to obj * tests for app.impl.systemInfo, and adapters.systemInfo webcontroller * WIP - skip test append * DI refactor of CreateReadSystemInfo,test passing * remove .skip * two URL obj icon db test * system info tests, revert back icon test urls --------- Co-authored-by: Robert St. John <[email protected]>
- Loading branch information
1 parent
5b7aadb
commit 0fcdb25
Showing
15 changed files
with
575 additions
and
421 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
service/src/adapters/systemInfo/adapters.systemInfo.controllers.web.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
|
||
import express from 'express' | ||
import { WebAppRequestFactory } from '../adapters.controllers.web' | ||
import { SystemInfoAppLayer } from '../../app.api/systemInfo/app.api.systemInfo' | ||
|
||
|
||
export function SystemInfoRoutes(appLayer: SystemInfoAppLayer, createAppRequest: WebAppRequestFactory): express.Router { | ||
|
||
const routes = express.Router() | ||
|
||
routes.route('/') | ||
.get(async (req, res, next) => { | ||
const appReq = createAppRequest(req) | ||
|
||
const appRes = await appLayer.readSystemInfo(appReq) | ||
if (appRes.success) { | ||
return res.json(appRes.success) | ||
} | ||
return next(appRes.error) | ||
}) | ||
|
||
return routes | ||
} |
25 changes: 25 additions & 0 deletions
25
service/src/adapters/systemInfo/adapters.systemInfo.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Connection } from 'mongoose' | ||
import { EnvironmentService, EnvironmentInfo } from '../../entities/systemInfo/entities.systemInfo' | ||
|
||
export class EnvironmentServiceImpl implements EnvironmentService { | ||
|
||
private mongodbVersion: string | null = null | ||
private readonly nodeVersion: string = process.versions.node | ||
|
||
constructor(private readonly dbConn: Connection) {} | ||
|
||
async readEnvironmentInfo(): Promise<EnvironmentInfo> { | ||
if (this.mongodbVersion === null) { | ||
const dbInfo = await this.dbConn.db.admin().serverInfo() | ||
this.mongodbVersion = dbInfo.version | ||
} | ||
return { | ||
nodeVersion: this.nodeVersion, | ||
monogdbVersion: this.mongodbVersion!, | ||
} | ||
} | ||
|
||
readDependencies(): Promise<unknown> { | ||
throw new Error('Method not implemented.') | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { SystemInfo } from '../../entities/systemInfo/entities.systemInfo' | ||
import { InfrastructureError } from '../app.api.errors' | ||
import { AppRequest, AppResponse } from '../app.api.global' | ||
|
||
|
||
export type ExoPrivilegedSystemInfo = SystemInfo | ||
export type ExoRedactedSystemInfo = Omit<SystemInfo, 'environment'> | ||
export type ExoSystemInfo = ExoPrivilegedSystemInfo | ExoRedactedSystemInfo | ||
|
||
export interface ReadSystemInfoRequest extends AppRequest {} | ||
export interface ReadSystemInfoResponse extends AppResponse<ExoSystemInfo, InfrastructureError> {} | ||
|
||
export interface ReadSystemInfo { | ||
(req: ReadSystemInfoRequest): Promise<ReadSystemInfoResponse> | ||
} | ||
|
||
export interface SystemInfoAppLayer { | ||
readSystemInfo: ReadSystemInfo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { AppResponse } from '../../app.api/app.api.global'; | ||
import * as api from '../../app.api/systemInfo/app.api.systemInfo'; | ||
import { EnvironmentService } from '../../entities/systemInfo/entities.systemInfo'; | ||
import * as Settings from '../../models/setting'; | ||
import * as AuthenticationConfiguration from '../../models/authenticationconfiguration'; | ||
import AuthenticationConfigurationTransformer from '../../transformers/authenticationconfiguration'; | ||
/** | ||
* This factory function creates the implementation of the {@link api.ReadSystemInfo} | ||
* application layer interface. | ||
*/ | ||
export function CreateReadSystemInfo( | ||
environmentService: EnvironmentService, | ||
config: any, | ||
settingsModule: typeof Settings = Settings, | ||
authConfigModule: typeof AuthenticationConfiguration = AuthenticationConfiguration, | ||
authConfigTransformerModule: typeof AuthenticationConfigurationTransformer = AuthenticationConfigurationTransformer | ||
): api.ReadSystemInfo { | ||
|
||
// appending the authentication strategies to the api | ||
async function appendAuthenticationStrategies( | ||
api: any, | ||
options: any = {} | ||
): Promise<any> { | ||
const apiCopy = { | ||
...api, | ||
authenticationStrategies: {} | ||
}; | ||
const authenticationConfigurations = await authConfigModule.getAllConfigurations(); | ||
const transformedConfigurations = authConfigTransformerModule.transform( | ||
authenticationConfigurations.filter( | ||
config => config.enabled || options.includeDisabled | ||
), | ||
options | ||
); | ||
transformedConfigurations.forEach( | ||
(configuration: { name: string | number }) => { | ||
apiCopy.authenticationStrategies[configuration.name] = { | ||
...configuration | ||
}; | ||
} | ||
); | ||
return apiCopy; | ||
} | ||
|
||
return async function readSystemInfo( | ||
req: api.ReadSystemInfoRequest | ||
): Promise<api.ReadSystemInfoResponse> { | ||
// TODO: will need a permission check to determine what level of system | ||
// information the requesting principal is allowed to see | ||
const environment = await environmentService.readEnvironmentInfo(); | ||
const disclaimer = (await settingsModule.getSetting('disclaimer')) || {}; | ||
const contactInfo = (await settingsModule.getSetting('contactInfo')) || {}; | ||
|
||
const apiConfig = Object.assign({}, config.api, { | ||
environment: environment, | ||
disclaimer: disclaimer, | ||
contactInfo: contactInfo | ||
}); | ||
|
||
const updatedApiConfig = await appendAuthenticationStrategies(apiConfig, { | ||
whitelist: true | ||
}); | ||
|
||
return AppResponse.success(updatedApiConfig as any); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
export interface EnvironmentInfo { | ||
nodeVersion: string | ||
monogdbVersion: string | ||
// TODO: maybe relavant environment variables? redact sensitive values | ||
} | ||
|
||
export interface EnvironmentService { | ||
readEnvironmentInfo(): Promise<EnvironmentInfo> | ||
// TODO: how to build dependency list/tree with all versions | ||
readDependencies(): Promise<unknown> | ||
} | ||
|
||
export interface SystemInfo { | ||
/** | ||
* These [semantic](https://semver.org/) version components are parsed from | ||
* the package version to allow the mobile apps to check compatibility with | ||
* the server. Without this structure, the apps will not allow interaction | ||
* with the server. | ||
*/ | ||
version: { major: number, minor: number, micro: number } | ||
/** | ||
* Package version string straight from package.json | ||
*/ | ||
environment: EnvironmentInfo | ||
disclaimer: any // mongoose Document type | ||
contactInfo: any | ||
} |
Oops, something went wrong.