forked from janus-idp/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(report-portal): added report portal frontend and backend plugins
Signed-off-by: Yash Oswal <[email protected]>
- Loading branch information
1 parent
1bb20a9
commit b1887b3
Showing
36 changed files
with
941 additions
and
10 deletions.
There are no files selected for viewing
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 @@ | ||
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); |
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,14 @@ | ||
# report-portal | ||
|
||
Welcome to the report-portal backend plugin! | ||
|
||
_This plugin was created through the Backstage CLI_ | ||
|
||
## Getting started | ||
|
||
Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn | ||
start` in the root directory, and then navigating to [/report-portal](http://localhost:3000/report-portal). | ||
|
||
You can also serve the plugin in isolation by running `yarn start` in the plugin directory. | ||
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. | ||
It is only meant for local development, and the setup for it can be found inside the [/dev](/dev) directory. |
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,5 @@ | ||
reportPortal: | ||
integrations: | ||
- host: ${REPORT_PORTAL_HOST} | ||
baseUrl: ${REPORT_PORTAL_BASE_URL} | ||
token: ${REPORT_PORTAL_TOKEN} |
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,22 @@ | ||
export interface Config { | ||
/** | ||
* Configuration values for Report Portal plugin | ||
*/ | ||
reportPortal: { | ||
integrations: Array<{ | ||
/** | ||
* Host of report portal url | ||
*/ | ||
host: string; | ||
/** | ||
* Base api url for report portal instance | ||
*/ | ||
baseUrl: string; | ||
/** | ||
* The Api token that will be used to | ||
* @visibility secret | ||
*/ | ||
token: string; | ||
}>; | ||
}; | ||
} |
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,82 @@ | ||
{ | ||
"name": "@appdev-platform/backstage-plugin-report-portal-backend", | ||
"version": "0.1.0", | ||
"main": "src/index.ts", | ||
"types": "src/index.ts", | ||
"license": "Apache-2.0", | ||
"publishConfig": { | ||
"access": "public", | ||
"main": "dist/index.cjs.js", | ||
"types": "dist/index.d.ts" | ||
}, | ||
"backstage": { | ||
"role": "backend-plugin" | ||
}, | ||
"exports": { | ||
".": "./src/index.ts", | ||
"./alpha": "./src/alpha.ts", | ||
"./package.json": "./package.json" | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
"alpha": [ | ||
"src/alpha.ts" | ||
], | ||
"package.json": [ | ||
"package.json" | ||
] | ||
} | ||
}, | ||
"scripts": { | ||
"build": "backstage-cli package build", | ||
"clean": "backstage-cli package clean", | ||
"export-dynamic": "janus-cli package export-dynamic-plugin", | ||
"lint": "backstage-cli package lint", | ||
"postpack": "backstage-cli package postpack", | ||
"postversion": "yarn run export-dynamic", | ||
"prepack": "backstage-cli package prepack", | ||
"start": "backstage-cli package start", | ||
"test": "backstage-cli package test --passWithNoTests --coverage", | ||
"tsc": "tsc" | ||
}, | ||
"dependencies": { | ||
"@backstage/backend-common": "^0.19.8", | ||
"@backstage/backend-plugin-api": "^0.6.6", | ||
"@backstage/backend-plugin-manager": "npm:@janus-idp/[email protected]", | ||
"@backstage/config": "^1.1.1", | ||
"@types/express": "^*", | ||
"express": "^4.17.1", | ||
"express-promise-router": "^4.1.0", | ||
"http-proxy-middleware": "^2.0.6", | ||
"node-fetch": "^2.6.7", | ||
"winston": "^3.2.1", | ||
"yn": "^4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@backstage/cli": "0.23.0", | ||
"@janus-idp/cli": "1.7.1", | ||
"@types/supertest": "2.0.12", | ||
"msw": "1.0.0", | ||
"supertest": "6.2.4" | ||
}, | ||
"files": [ | ||
"dist", | ||
"config.d.ts", | ||
"dist-dynamic/*.*", | ||
"dist-dynamic/dist/**", | ||
"dist-dynamic/alpha/*", | ||
"app-config.janus-idp.yaml" | ||
], | ||
"configSchema": "config.d.ts", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/janus-idp/backstage-plugins", | ||
"directory": "plugins/report-portal" | ||
}, | ||
"keywords": [ | ||
"backstage", | ||
"plugin" | ||
], | ||
"homepage": "https://janus-idp.io/", | ||
"bugs": "https://github.com/janus-idp/backstage-plugins/issues" | ||
} |
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 @@ | ||
export { reportPortalPlugin } from './plugin'; |
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,11 @@ | ||
import { BackendDynamicPluginInstaller } from '@backstage/backend-plugin-manager'; | ||
|
||
import { createRouter } from '../service/router'; | ||
|
||
export const dynamicPluginInstaller: BackendDynamicPluginInstaller = { | ||
kind: 'legacy', | ||
router: { | ||
pluginID: 'report-portal', | ||
createPlugin: createRouter, | ||
}, | ||
}; |
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,8 @@ | ||
/** | ||
* The report-portal backend plugin. | ||
* | ||
* @packageDocumentation | ||
*/ | ||
|
||
export * from './dynamic/index'; | ||
export * from './service/router'; |
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,33 @@ | ||
import { loggerToWinstonLogger } from '@backstage/backend-common'; | ||
import { | ||
coreServices, | ||
createBackendPlugin, | ||
} from '@backstage/backend-plugin-api'; | ||
|
||
import { createRouter } from './service/router'; | ||
|
||
/** | ||
* The report-portal backend plugin. | ||
* | ||
* @alpha | ||
*/ | ||
export const reportPortalPlugin = createBackendPlugin({ | ||
pluginId: 'report-portal', | ||
register(env) { | ||
env.registerInit({ | ||
deps: { | ||
logger: coreServices.logger, | ||
config: coreServices.rootConfig, | ||
http: coreServices.httpRouter, | ||
}, | ||
async init({ config, logger, http }) { | ||
http.use(() => | ||
createRouter({ | ||
config: config, | ||
logger: loggerToWinstonLogger(logger), | ||
}), | ||
); | ||
}, | ||
}); | ||
}, | ||
}); |
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 { getRootLogger } from '@backstage/backend-common'; | ||
|
||
import yn from 'yn'; | ||
|
||
import { startStandaloneServer } from './service/standaloneServer'; | ||
|
||
const port = process.env.PLUGIN_PORT ? Number(process.env.PLUGIN_PORT) : 7007; | ||
const enableCors = yn(process.env.PLUGIN_CORS, { default: false }); | ||
const logger = getRootLogger(); | ||
|
||
startStandaloneServer({ port, enableCors, logger }).catch(err => { | ||
logger.error('Standalone server failed:', err); | ||
process.exit(1); | ||
}); | ||
|
||
process.on('SIGINT', () => { | ||
logger.info('CTRL+C pressed; exiting.'); | ||
process.exit(0); | ||
}); |
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,30 @@ | ||
import { getVoidLogger } from '@backstage/backend-common'; | ||
|
||
import express from 'express'; | ||
import request from 'supertest'; | ||
|
||
import { createRouter } from './router'; | ||
|
||
describe('createRouter', () => { | ||
let app: express.Express; | ||
|
||
beforeAll(async () => { | ||
const router = await createRouter({ | ||
logger: getVoidLogger(), | ||
}); | ||
app = express().use(router); | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('GET /health', () => { | ||
it('returns ok', async () => { | ||
const response = await request(app).get('/health'); | ||
|
||
expect(response.status).toEqual(200); | ||
expect(response.body).toEqual({ status: 'ok' }); | ||
}); | ||
}); | ||
}); |
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,56 @@ | ||
import { errorHandler } from '@backstage/backend-common'; | ||
import { Config } from '@backstage/config'; | ||
|
||
import express from 'express'; | ||
import Router from 'express-promise-router'; | ||
import { createProxyMiddleware } from 'http-proxy-middleware'; | ||
import { Logger } from 'winston'; | ||
|
||
export interface RouterOptions { | ||
logger: Logger; | ||
config: Config; | ||
} | ||
|
||
export async function createRouter( | ||
options: RouterOptions, | ||
): Promise<express.Router> { | ||
const { logger, config } = options; | ||
const hostsConfig = config.getConfigArray('reportPortal.integrations'); | ||
|
||
const router = Router(); | ||
router.use(express.json()); | ||
|
||
router.get('/*', (req, res, next) => { | ||
const hostName = req.query.host; | ||
if (!hostName) { | ||
res.status(500).json({ message: 'Oops, I think you forgot something?' }); | ||
return; | ||
} | ||
const reqConfig = hostsConfig | ||
.find(instance => instance.getString('host') === hostName) | ||
?.get() as PluginConfig; | ||
|
||
const proxy = createProxyMiddleware({ | ||
target: reqConfig.baseUrl, | ||
changeOrigin: true, | ||
secure: false, | ||
headers: { | ||
Authorization: reqConfig.token, | ||
}, | ||
pathRewrite: { | ||
['/api/report-portal']: '', | ||
}, | ||
}); | ||
|
||
proxy(req, res, next); | ||
}); | ||
|
||
router.use(errorHandler()); | ||
return router; | ||
} | ||
|
||
type PluginConfig = { | ||
host: string; | ||
baseUrl: string; | ||
token: string; | ||
}; |
40 changes: 40 additions & 0 deletions
40
plugins/report-portal-backend/src/service/standaloneServer.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,40 @@ | ||
import { createServiceBuilder } from '@backstage/backend-common'; | ||
import { Config, ConfigReader } from '@backstage/config'; | ||
|
||
import { Logger } from 'winston'; | ||
|
||
import { Server } from 'http'; | ||
|
||
import { createRouter } from './router'; | ||
|
||
export interface ServerOptions { | ||
port: number; | ||
enableCors: boolean; | ||
logger: Logger; | ||
} | ||
|
||
export async function startStandaloneServer( | ||
options: ServerOptions, | ||
): Promise<Server> { | ||
const config = new ConfigReader({}); | ||
const logger = options.logger.child({ service: 'report-portal-backend' }); | ||
logger.debug('Starting application server...'); | ||
const router = await createRouter({ | ||
logger, | ||
config, | ||
}); | ||
|
||
let service = createServiceBuilder(module) | ||
.setPort(options.port) | ||
.addRouter('/report-portal', router); | ||
if (options.enableCors) { | ||
service = service.enableCors({ origin: 'http://localhost:3000' }); | ||
} | ||
|
||
return await service.start().catch(err => { | ||
logger.error('Dev server failed:', err); | ||
process.exit(1); | ||
}); | ||
} | ||
|
||
module.hot?.accept(); |
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 @@ | ||
export {}; |
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,9 @@ | ||
{ | ||
"extends": "@backstage/cli/config/tsconfig.json", | ||
"include": ["src", "dev", "migrations"], | ||
"exclude": ["node_modules"], | ||
"compilerOptions": { | ||
"outDir": "../../dist-types/plugins/report-portal", | ||
"rootDir": "." | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"extends": ["//"], | ||
"pipeline": { | ||
"tsc": { | ||
"outputs": ["../../dist-types/plugins/report-portal/**"], | ||
"dependsOn": ["^tsc"] | ||
} | ||
} | ||
} |
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 @@ | ||
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname); |
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,13 @@ | ||
# report-portal | ||
|
||
Welcome to the report-portal plugin! | ||
|
||
_This plugin was created through the Backstage CLI_ | ||
|
||
## Getting started | ||
|
||
Your plugin has been added to the example app in this repository, meaning you'll be able to access it by running `yarn start` in the root directory, and then navigating to [/report-portal](http://localhost:3000/report-portal). | ||
|
||
You can also serve the plugin in isolation by running `yarn start` in the plugin directory. | ||
This method of serving the plugin provides quicker iteration speed and a faster startup and hot reloads. | ||
It is only meant for local development, and the setup for it can be found inside the [/dev](./dev) directory. |
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,8 @@ | ||
dynamicPlugins: | ||
frontend: | ||
janus-idp.backstage-plugin-report-portal: | ||
apiFactories: [] | ||
appIcons: [] | ||
dynamicRoutes: [] | ||
mountPoints: [] | ||
routeBindings: [] |
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 @@ | ||
export interface Config {} |
Oops, something went wrong.