Skip to content

Commit a91570e

Browse files
authored
Merge pull request finos#749 from 06kellyjac/allow_custom_proxy_domain
feat: allow for providing an alternative domain for the proxy
2 parents 00a9d12 + 0174814 commit a91570e

File tree

13 files changed

+207
-68
lines changed

13 files changed

+207
-68
lines changed

.env.development

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
VITE_API_URI=http://localhost:8080
2-
VITE_SERVER_URI=http://localhost:8000

config.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"description": "Customisable questions to add to attestation form",
2121
"type": "object"
2222
},
23+
"domains": {
24+
"description": "Provide domains to use alternative to the defaults",
25+
"type": "object"
26+
},
2327
"privateOrganizations": {
2428
"description": "Pattern searches for listed private organizations are disabled",
2529
"type": "array"

cypress/e2e/repo.cy.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
describe('Repo', () => {
2+
beforeEach(() => {
3+
cy.visit('/admin/repo');
4+
5+
// prevent failures on 404 request and uncaught promises
6+
cy.on('uncaught:exception', () => false);
7+
});
8+
9+
describe('Code button for repo row', () => {
10+
it('Opens tooltip with correct content and can copy', () => {
11+
const cloneURL = 'http://localhost:8000/finos/test-repo.git';
12+
const tooltipQuery = 'div[role="tooltip"]';
13+
14+
cy
15+
// tooltip isn't open to start with
16+
.get(tooltipQuery)
17+
.should('not.exist');
18+
19+
cy
20+
// find the entry for finos/test-repo
21+
.get('a[href="/admin/repo/test-repo"]')
22+
// take it's parent row
23+
.closest('tr')
24+
// find the nearby span containing Code we can click to open the tooltip
25+
.find('span')
26+
.contains('Code')
27+
.should('exist')
28+
.click();
29+
30+
cy
31+
// find the newly opened tooltip
32+
.get(tooltipQuery)
33+
.should('exist')
34+
.find('span')
35+
// check it contains the url we expect
36+
.contains(cloneURL)
37+
.should('exist')
38+
.parent()
39+
// find the adjacent span that contains the svg
40+
.find('span')
41+
.next()
42+
// check it has the copy icon first and click it
43+
.get('svg.octicon-copy')
44+
.should('exist')
45+
.click()
46+
// check the icon has changed to the check icon
47+
.get('svg.octicon-copy')
48+
.should('not.exist')
49+
.get('svg.octicon-check')
50+
.should('exist');
51+
52+
// failed to successfully check the clipboard
53+
});
54+
});
55+
});

cypress/support/commands.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,16 @@
2222
//
2323
//
2424
// -- This will overwrite an existing command --
25-
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
25+
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
26+
27+
// start of a login command with sessions
28+
// TODO: resolve issues with the CSRF token
29+
Cypress.Commands.add('login', (username, password) => {
30+
cy.session([username, password], () => {
31+
cy.visit('/login');
32+
cy.get('[data-test=username]').type(username);
33+
cy.get('[data-test=password]').type(password);
34+
cy.get('[data-test=login]').click();
35+
cy.url().should('contain', '/admin/profile');
36+
});
37+
});

proxy.config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
}
9393
]
9494
},
95+
"domains": {},
9596
"privateOrganizations": [],
9697
"urlShortener": "",
9798
"contactEmail": "",

scripts/doc-schema.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ try {
2020
console.log(genDocOutput);
2121

2222
const schemaDoc = readFileSync(`${tempdir}${sep}schema.md`, 'utf-8')
23+
.replace(/\s\s\n\n<\/summary>/g, '\n</summary>')
2324
.replace(/# GitProxy configuration file/g, '# Schema Reference'); // https://github.com/finos/git-proxy/pull/327#discussion_r1377343213
2425
const docString = `---
2526
title: Schema Reference

src/config/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ let _privateOrganizations = defaultSettings.privateOrganizations;
2424
let _urlShortener = defaultSettings.urlShortener;
2525
let _contactEmail = defaultSettings.contactEmail;
2626
let _csrfProtection = defaultSettings.csrfProtection;
27+
let _domains = defaultSettings.domains;
2728

2829
// Get configured proxy URL
2930
const getProxyUrl = () => {
@@ -189,6 +190,13 @@ const getSSLCertPath = () => {
189190
return _sslCertPath;
190191
};
191192

193+
const getDomains = () => {
194+
if (_userSettings && _userSettings.domains) {
195+
_domains = _userSettings.domains;
196+
}
197+
return _domains;
198+
};
199+
192200
exports.getAPIs = getAPIs;
193201
exports.getProxyUrl = getProxyUrl;
194202
exports.getAuthorisedList = getAuthorisedList;
@@ -207,3 +215,4 @@ exports.getCSRFProtection = getCSRFProtection;
207215
exports.getPlugins = getPlugins;
208216
exports.getSSLKeyPath = getSSLKeyPath;
209217
exports.getSSLCertPath = getSSLCertPath;
218+
exports.getDomains = getDomains;

src/service/proxyURL.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const { GIT_PROXY_SERVER_PORT: PROXY_HTTP_PORT, GIT_PROXY_UI_PORT: UI_PORT } =
2+
require('../config/env').Vars;
3+
const config = require('../config');
4+
5+
module.exports = {
6+
getProxyURL: (req) => {
7+
const defaultURL = `${req.protocol}://${req.headers.host}`.replace(
8+
`:${UI_PORT}`,
9+
`:${PROXY_HTTP_PORT}`,
10+
);
11+
return config.getDomains().proxy ?? defaultURL;
12+
},
13+
};

src/service/routes/repo.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const express = require('express');
22
const router = new express.Router();
33
const db = require('../../db');
4+
const { getProxyURL } = require('../proxyURL');
45

56
router.get('/', async (req, res) => {
7+
const proxyURL = getProxyURL(req);
68
const query = {
79
type: 'push',
810
};
@@ -18,12 +20,15 @@ router.get('/', async (req, res) => {
1820
query[k] = v;
1921
}
2022

21-
res.send(await db.getRepos(query));
23+
const qd = await db.getRepos(query);
24+
res.send(qd.map((d) => ({ ...d, proxyURL })));
2225
});
2326

2427
router.get('/:name', async (req, res) => {
28+
const proxyURL = getProxyURL(req);
2529
const name = req.params.name;
26-
res.send(await db.getRepo(name));
30+
const qd = await db.getRepo(name);
31+
res.send({ ...qd, proxyURL });
2732
});
2833

2934
router.patch('/:name/user/push', async (req, res) => {

src/ui/views/RepoDetails/RepoDetails.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ export default function RepoDetails() {
5959
if (isLoading) return <div>Loading...</div>;
6060
if (isError) return <div>Something went wrong ...</div>;
6161

62-
const { project: org, name } = data || {};
63-
const cloneURL = `${import.meta.env.VITE_SERVER_URI}/${org}/${name}.git`;
62+
const { project: org, name, proxyURL } = data || {};
63+
const cloneURL = `${proxyURL}/${org}/${name}.git`;
6464

6565
return (
6666
<GridContainer>

0 commit comments

Comments
 (0)