Skip to content

Commit

Permalink
Merge pull request #462 from immobiliare/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
antoniomuso authored May 16, 2024
2 parents 1f76565 + 4d497f0 commit 07371f6
Show file tree
Hide file tree
Showing 8 changed files with 2,747 additions and 1,846 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [6.5.1-alpha.0](https://github.com/immobiliare/backstage-plugin-gitlab/compare/v6.5.0...v6.5.1-alpha.0) (2024-05-16)

**Note:** Version bump only for package root

# [6.5.0](https://github.com/immobiliare/backstage-plugin-gitlab/compare/v6.5.0-alpha.0...v6.5.0) (2024-04-11)

**Note:** Version bump only for package root
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"useNx": true,
"useWorkspaces": true,
"npmClient": "yarn",
"version": "6.5.0"
"version": "6.5.1-alpha.0"
}
4 changes: 4 additions & 0 deletions packages/gitlab-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [6.5.1-alpha.0](https://github.com/immobiliare/backstage-plugin-gitlab/compare/v6.5.0...v6.5.1-alpha.0) (2024-05-16)

**Note:** Version bump only for package @immobiliarelabs/backstage-plugin-gitlab-backend

# [6.5.0](https://github.com/immobiliare/backstage-plugin-gitlab/compare/v6.5.0-alpha.0...v6.5.0) (2024-04-11)

**Note:** Version bump only for package @immobiliarelabs/backstage-plugin-gitlab-backend
Expand Down
20 changes: 10 additions & 10 deletions packages/gitlab-backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@immobiliarelabs/backstage-plugin-gitlab-backend",
"version": "6.5.0",
"version": "6.5.1-alpha.0",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts",
"license": "Apache-2.0",
Expand Down Expand Up @@ -36,10 +36,10 @@
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/backend-common": "^0.20.1",
"@backstage/backend-plugin-api": "^0.6.7",
"@backstage/config": "^1.1.1",
"@backstage/integration": "^1.7.0",
"@backstage/backend-common": "^0.22.0",
"@backstage/backend-plugin-api": "^0.6.18",
"@backstage/config": "^1.2.0",
"@backstage/integration": "^1.11.0",
"body-parser": "^1.20.2",
"express": "^4.17.3",
"express-promise-router": "^4.1.0",
Expand All @@ -48,11 +48,11 @@
"yn": "^4.0.0"
},
"devDependencies": {
"@backstage/backend-test-utils": "^0.2.8",
"@backstage/catalog-model": "^1.4.0",
"@backstage/cli": "^0.22.8",
"@backstage/plugin-catalog-common": "^1.0.14",
"@backstage/plugin-catalog-node": "^1.3.7",
"@backstage/backend-test-utils": "^0.3.8",
"@backstage/catalog-model": "^1.5.0",
"@backstage/cli": "^0.26.5",
"@backstage/plugin-catalog-common": "^1.0.23",
"@backstage/plugin-catalog-node": "^1.12.0",
"@types/express": "^4.17.21",
"@types/supertest": "^2.0.12",
"msw": "^1.0.0",
Expand Down
29 changes: 13 additions & 16 deletions packages/gitlab-backend/src/service/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Logger } from 'winston';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { Request } from 'http-proxy-middleware/dist/types';
import bodyParser from 'body-parser';
import { IncomingHttpHeaders } from 'http';

function getBasePath(config: Config) {
const baseUrl = config.getOptionalString('backend.baseUrl');
Expand All @@ -19,6 +20,16 @@ function getBasePath(config: Config) {
return new URL(baseUrl).pathname.replace(/\/$/, '');
}

function headersManipulation(headers: IncomingHttpHeaders) {
// Remove Backstage authorization before forwarding to GitLab
if (headers['authorization']) delete headers['authorization'];
// Forward authorization, this header is defined when gitlab.useOAuth is true
if (headers['gitlab-authorization']) {
headers['authorization'] = headers['gitlab-authorization'] as string;
delete headers['gitlab-authorization'];
}
}

export interface RouterOptions {
logger: Logger;
config: Config;
Expand Down Expand Up @@ -49,26 +60,12 @@ export async function createRouter(
// fires _after_ the agent has already sent the headers to the proxy
// target, causing a ERR_HTTP_HEADERS_SENT crash
const filter = (_pathname: string, req: Request): boolean => {
if (req.headers['authorization']) delete req.headers['authorization'];
// Forward authorization, this header is defined when gitlab.useOAuth is true
if (req.headers['gitlab-authorization']) {
req.headers['authorization'] = req.headers[
'gitlab-authorization'
] as string;
delete req.headers['gitlab-authorization'];
}
headersManipulation(req.headers);
return req.method === 'GET';
};

const graphqlFilter = (_pathname: string, req: Request): boolean => {
if (req.headers['authorization']) delete req.headers['authorization'];
// Forward authorization, this header is defined when gitlab.useOAuth is true
if (req.headers['gitlab-authorization']) {
req.headers['authorization'] = req.headers[
'gitlab-authorization'
] as string;
delete req.headers['gitlab-authorization'];
}
headersManipulation(req.headers);
return req.method === 'POST' && !req.body.query?.includes('mutation');
};

Expand Down
4 changes: 4 additions & 0 deletions packages/gitlab/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [6.5.1-alpha.0](https://github.com/immobiliare/backstage-plugin-gitlab/compare/v6.5.0...v6.5.1-alpha.0) (2024-05-16)

**Note:** Version bump only for package @immobiliarelabs/backstage-plugin-gitlab

# [6.5.0](https://github.com/immobiliare/backstage-plugin-gitlab/compare/v6.5.0-alpha.0...v6.5.0) (2024-04-11)

**Note:** Version bump only for package @immobiliarelabs/backstage-plugin-gitlab
Expand Down
26 changes: 13 additions & 13 deletions packages/gitlab/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@immobiliarelabs/backstage-plugin-gitlab",
"version": "6.5.0",
"version": "6.5.1-alpha.0",
"main": "dist/index.esm.js",
"types": "dist/index.d.ts",
"license": "Apache-2.0",
Expand Down Expand Up @@ -35,10 +35,10 @@
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage/core-components": "^0.13.8",
"@backstage/core-plugin-api": "^1.8.0",
"@backstage/plugin-catalog-react": "^1.9.0",
"@backstage/theme": "^0.4.4",
"@backstage/core-components": "^0.14.7",
"@backstage/core-plugin-api": "^1.9.2",
"@backstage/plugin-catalog-react": "^1.12.0",
"@backstage/theme": "^0.5.4",
"@material-ui/core": "^4.12.2",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "4.0.0-alpha.61",
Expand All @@ -54,14 +54,14 @@
"react-router-dom": "6.0.0-beta.0 || ^6.20.0"
},
"devDependencies": {
"@backstage/cli": "^0.24.0",
"@backstage/core-app-api": "^1.11.0",
"@backstage/dev-utils": "^1.0.24",
"@backstage/plugin-catalog-react": "^1.9.1",
"@backstage/test-utils": "^1.4.0",
"@backstage/cli": "^0.26.5",
"@backstage/core-app-api": "^1.12.5",
"@backstage/dev-utils": "^1.0.32",
"@backstage/plugin-catalog-react": "^1.12.0",
"@backstage/test-utils": "^1.5.5",
"@commitlint/cli": "^17.0.0",
"@commitlint/config-conventional": "^17.0.0",
"@gitbeaker/rest": "^39.0.0",
"@gitbeaker/rest": "^40.0.2",
"@nuxtjs/eslint-config-typescript": "^12.0.0",
"@saithodev/semantic-release-backmerge": "^2.0.0",
"@semantic-release/changelog": "^6.0.1",
Expand All @@ -70,7 +70,7 @@
"@semantic-release/github": "^9.0.7",
"@semantic-release/npm": "^9.0.0",
"@semantic-release/release-notes-generator": "^10.0.2",
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/jest-dom": "^6.4.5",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.3.0",
"@types/jest": "^29.5.1",
Expand All @@ -82,7 +82,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"husky": "^8.0.0",
"prettier": "^2.0.5",
"prettier": "^3.2.5",
"react": "^18.0.2",
"react-dom": "^18.0.2",
"react-router": "^6.3.0",
Expand Down
Loading

0 comments on commit 07371f6

Please sign in to comment.