Skip to content

Commit

Permalink
feat(report-portal): added report portal frontend and backend plugins
Browse files Browse the repository at this point in the history
Signed-off-by: Yash Oswal <[email protected]>
  • Loading branch information
yashoswalyo committed Feb 28, 2024
1 parent 1bb20a9 commit b1887b3
Show file tree
Hide file tree
Showing 36 changed files with 941 additions and 10 deletions.
1 change: 1 addition & 0 deletions plugins/report-portal-backend/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
14 changes: 14 additions & 0 deletions plugins/report-portal-backend/README.md
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.
5 changes: 5 additions & 0 deletions plugins/report-portal-backend/app-config.janus-idp.yaml
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}
22 changes: 22 additions & 0 deletions plugins/report-portal-backend/config.d.ts
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;
}>;
};
}
82 changes: 82 additions & 0 deletions plugins/report-portal-backend/package.json
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"
}
1 change: 1 addition & 0 deletions plugins/report-portal-backend/src/alpha.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { reportPortalPlugin } from './plugin';
11 changes: 11 additions & 0 deletions plugins/report-portal-backend/src/dynamic/index.ts
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,
},
};
8 changes: 8 additions & 0 deletions plugins/report-portal-backend/src/index.ts
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';
33 changes: 33 additions & 0 deletions plugins/report-portal-backend/src/plugin.ts
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),
}),
);
},
});
},
});
19 changes: 19 additions & 0 deletions plugins/report-portal-backend/src/run.ts
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);
});
30 changes: 30 additions & 0 deletions plugins/report-portal-backend/src/service/router.test.ts
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' });
});
});
});
56 changes: 56 additions & 0 deletions plugins/report-portal-backend/src/service/router.ts
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 plugins/report-portal-backend/src/service/standaloneServer.ts
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();
1 change: 1 addition & 0 deletions plugins/report-portal-backend/src/setupTests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
9 changes: 9 additions & 0 deletions plugins/report-portal-backend/tsconfig.json
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": "."
}
}
9 changes: 9 additions & 0 deletions plugins/report-portal-backend/turbo.json
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"]
}
}
}
1 change: 1 addition & 0 deletions plugins/report-portal/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@backstage/cli/config/eslint-factory')(__dirname);
13 changes: 13 additions & 0 deletions plugins/report-portal/README.md
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.
8 changes: 8 additions & 0 deletions plugins/report-portal/app-config.janus-idp.yaml
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: []
1 change: 1 addition & 0 deletions plugins/report-portal/config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export interface Config {}
Loading

0 comments on commit b1887b3

Please sign in to comment.