feat: circleCI backend proxy

This commit is contained in:
Ivan Shmidt
2020-05-04 20:58:39 +02:00
parent 39f500a059
commit 31d05b1f92
11 changed files with 97 additions and 8 deletions
+1
View File
@@ -21,6 +21,7 @@
"@backstage/cli": "^0.1.1-alpha.4",
"@backstage/core": "^0.1.1-alpha.4",
"@backstage/plugin-circleci": "^0.1.1-alpha.4",
"@backstage/plugin-circleci-backend": "^0.1.1-alpha.4",
"@backstage/plugin-home-page": "^0.1.1-alpha.4",
"@backstage/plugin-inventory": "^0.1.1-alpha.4",
"@backstage/plugin-lighthouse": "^0.1.1-alpha.4",
+1
View File
@@ -19,3 +19,4 @@ export { plugin as LighthousePlugin } from '@backstage/plugin-lighthouse';
export { plugin as InventoryPlugin } from '@backstage/plugin-inventory';
export { plugin as TechRadar } from '@backstage/plugin-tech-radar';
export { plugin as Circleci } from '@backstage/plugin-circleci';
// export { plugin as CircleciBackend } from '@backstage/plugin-circleci-backend';
+1
View File
@@ -16,6 +16,7 @@
},
"dependencies": {
"@backstage/plugin-inventory-backend": "0.1.1-alpha.4",
"@backstage/plugin-circleci-backend": "0.1.1-alpha.4",
"compression": "^1.7.4",
"cors": "^2.8.5",
"express": "^4.17.1",
+2
View File
@@ -28,6 +28,7 @@ import helmet from 'helmet';
import compression from 'compression';
import { testRouter } from './test';
import { router as inventoryRouter } from '@backstage/plugin-inventory-backend';
import { router as circleCIRouter } from '@backstage/plugin-circleci-backend';
const DEFAULT_PORT = 7000;
@@ -40,6 +41,7 @@ app.use(compression());
app.use(express.json());
app.use('/test', testRouter);
app.use('/inventory', inventoryRouter);
app.use('/circleci', circleCIRouter);
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
extends: [require.resolve('@backstage/cli/config/eslint')],
};
+6
View File
@@ -0,0 +1,6 @@
# Title
Welcome to the circleci-backend plugin!
## Sub-section 1
## Sub-section 2
+23
View File
@@ -0,0 +1,23 @@
{
"name": "@backstage/plugin-circleci-backend",
"version": "0.1.1-alpha.4",
"main": "dist",
"license": "Apache-2.0",
"private": true,
"scripts": {
"build": "tsc",
"lint": "backstage-cli lint",
"test": "backstage-cli test",
"clean": "backstage-cli clean"
},
"devDependencies": {
"@backstage/cli": "^0.1.1-alpha.4"
},
"dependencies": {
"express": "^4.17.1",
"http-proxy-middleware": "^1.0.3"
},
"files": [
"dist"
]
}
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright 2020 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import express from 'express';
import httpProxy from 'http-proxy';
// Simple proxy for handling CORS for now
const proxy = httpProxy.createServer({
target: 'https://circleci.com/api/v1.1',
changeOrigin: true,
});
proxy.on('error', e => console.error(e));
export const router = express();
router.use('/api', (req, res) => proxy.web(req, res));
+15
View File
@@ -0,0 +1,15 @@
{
"include": ["src"],
"compilerOptions": {
"baseUrl": "src",
"outDir": "dist",
"incremental": true,
"sourceMap": true,
"declaration": true,
"strict": true,
"target": "es5",
"module": "commonjs",
"esModuleInterop": true,
"types": ["node", "jest"]
}
}
+5 -6
View File
@@ -18,6 +18,7 @@ import { CircleCI, GitType, CircleCIOptions } from 'circleci-api';
import { ApiRef } from '@backstage/core';
const defaultOptions: Partial<CircleCIOptions> = {
circleHost: 'http://backstage.localhost:7000/circleci/api',
vcs: {
type: GitType.GITHUB,
owner: 'CircleCITest3',
@@ -59,10 +60,10 @@ export class CircleCIApi {
const persistedToken = sessionStorage.getItem(key);
let persistedVCSOptions: {} | undefined;
try {
persistedVCSOptions = JSON.parse(sessionStorage.getItem(key + '_options') as string);
} catch(e) {
}
persistedVCSOptions = JSON.parse(
sessionStorage.getItem(key + '_options') as string,
);
} catch (e) {}
if (persistedToken && persistedVCSOptions) {
this.token = persistedToken;
this.options.vcs = persistedVCSOptions;
@@ -71,8 +72,6 @@ export class CircleCIApi {
return Promise.reject();
}
async persistToken() {
if (this.authed) return;
const key = circleCIApiRef.id;
+13 -2
View File
@@ -4003,7 +4003,7 @@
"@types/http-proxy" "*"
"@types/node" "*"
"@types/http-proxy@*":
"@types/http-proxy@*", "@types/http-proxy@^1.17.3":
version "1.17.4"
resolved "https://registry.npmjs.org/@types/http-proxy/-/http-proxy-1.17.4.tgz#e7c92e3dbe3e13aa799440ff42e6d3a17a9d045b"
integrity sha512-IrSHl2u6AWXduUaDLqYpt45tLVCtYv7o4Z0s1KghBCDgIIS9oW5K1H8mZG/A2CfeLdEa7rTd1ACOiHBc1EMT2Q==
@@ -10759,7 +10759,18 @@ http-proxy-middleware@0.19.1:
lodash "^4.17.11"
micromatch "^3.1.10"
http-proxy@^1.17.0:
http-proxy-middleware@^1.0.3:
version "1.0.3"
resolved "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-1.0.3.tgz#f73daad8dac622d51fe1769960c914b9b1f75a72"
integrity sha512-GHvPeBD+A357zS5tHjzj6ISrVOjjCiy0I92bdyTJz0pNmIjFxO0NX/bX+xkGgnclKQE/5hHAB9JEQ7u9Pw4olg==
dependencies:
"@types/http-proxy" "^1.17.3"
http-proxy "^1.18.0"
is-glob "^4.0.1"
lodash "^4.17.15"
micromatch "^4.0.2"
http-proxy@^1.17.0, http-proxy@^1.18.0:
version "1.18.0"
resolved "https://registry.npmjs.org/http-proxy/-/http-proxy-1.18.0.tgz#dbe55f63e75a347db7f3d99974f2692a314a6a3a"
integrity sha512-84I2iJM/n1d4Hdgc6y2+qY5mDaz2PUVjlg9znE9byl+q0uC3DeByqBGReQu5tpLK0TAqTIXScRUV+dg7+bUPpQ==