Skip to content

Commit a475fee

Browse files
authored
Merge pull request #1043 from kriswest/950-key-on-repo-urls
feat(key on repo url): support git hosts other than GitHub + multiple forks
2 parents de10c80 + cb75f82 commit a475fee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3061
-1523
lines changed

config.schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
"description": "Configuration for customizing git-proxy",
66
"type": "object",
77
"properties": {
8-
"proxyUrl": { "type": "string" },
8+
"proxyUrl": {
9+
"type": "string",
10+
"description": "Used in early versions of git proxy to configure the remote host that traffic is proxied to. In later versions, the repository URL is used to determine the domain proxied, allowing multiple hosts to be proxied by one instance.",
11+
"deprecated": true
12+
},
913
"cookieSecret": { "type": "string" },
1014
"sessionMaxAgeHours": { "type": "number" },
1115
"api": {

cypress/e2e/repo.cy.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('Repo', () => {
1010

1111
describe('Code button for repo row', () => {
1212
it('Opens tooltip with correct content and can copy', () => {
13-
const cloneURL = 'http://localhost:8000/finos/git-proxy.git';
13+
const cloneURLRegex = /http:\/\/localhost:8000\/(?:[^\/]+\/).+\.git/;
1414
const tooltipQuery = 'div[role="tooltip"]';
1515

1616
cy
@@ -19,10 +19,8 @@ describe('Repo', () => {
1919
.should('not.exist');
2020

2121
cy
22-
// find the entry for finos/git-proxy
23-
.get('a[href="/dashboard/repo/git-proxy"]')
24-
// take it's parent row
25-
.closest('tr')
22+
// find a table row for a repo (any will do)
23+
.get('table#RepoListTable>tbody>tr')
2624
// find the nearby span containing Code we can click to open the tooltip
2725
.find('span')
2826
.contains('Code')
@@ -35,7 +33,7 @@ describe('Repo', () => {
3533
.should('exist')
3634
.find('span')
3735
// check it contains the url we expect
38-
.contains(cloneURL)
36+
.contains(cloneURLRegex)
3937
.should('exist')
4038
.parent()
4139
// find the adjacent span that contains the svg

index.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { hideBin } from 'yargs/helpers';
66
import * as fs from 'fs';
77
import { configFile, setConfigFile, validate } from './src/config/file';
88
import { initUserConfig } from './src/config';
9-
import proxy from './src/proxy';
9+
import Proxy from './src/proxy';
1010
import service from './src/service';
1111

1212
const argv = yargs(hideBin(process.argv))
@@ -30,7 +30,7 @@ const argv = yargs(hideBin(process.argv))
3030
.strict()
3131
.parseSync();
3232

33-
setConfigFile(argv.c as string || "");
33+
setConfigFile((argv.c as string) || '');
3434
initUserConfig();
3535

3636
if (argv.v) {
@@ -48,7 +48,8 @@ if (argv.v) {
4848

4949
validate();
5050

51+
const proxy = new Proxy();
5152
proxy.start();
52-
service.start();
53+
service.start(proxy);
5354

5455
export { proxy, service };

packages/git-proxy-cli/test/testCli.test.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,13 @@ describe('test git-proxy-cli', function () {
221221
before(async function () {
222222
await helper.addRepoToDb(TEST_REPO_CONFIG);
223223
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
224-
await helper.addGitPushToDb(pushId, TEST_USER, TEST_EMAIL, TEST_REPO);
224+
await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url, TEST_USER, TEST_EMAIL);
225225
});
226226

227227
after(async function () {
228228
await helper.removeGitPushFromDb(pushId);
229229
await helper.removeUserFromDb(TEST_USER);
230-
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
230+
await helper.removeRepoFromDb(TEST_REPO_CONFIG.url);
231231
});
232232

233233
it('attempt to authorise should fail when server is down', async function () {
@@ -304,7 +304,7 @@ describe('test git-proxy-cli', function () {
304304
after(async function () {
305305
await helper.removeGitPushFromDb(pushId);
306306
await helper.removeUserFromDb(TEST_USER);
307-
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
307+
await helper.removeRepoFromDb(TEST_REPO_CONFIG.url);
308308
});
309309

310310
it('attempt to cancel should fail when server is down', async function () {
@@ -421,13 +421,13 @@ describe('test git-proxy-cli', function () {
421421
before(async function () {
422422
await helper.addRepoToDb(TEST_REPO_CONFIG);
423423
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
424-
await helper.addGitPushToDb(pushId, TEST_USER, TEST_EMAIL, TEST_REPO);
424+
await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url, TEST_USER, TEST_EMAIL);
425425
});
426426

427427
after(async function () {
428428
await helper.removeGitPushFromDb(pushId);
429429
await helper.removeUserFromDb(TEST_USER);
430-
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
430+
await helper.removeRepoFromDb(TEST_REPO_CONFIG.url);
431431
});
432432

433433
it('attempt to reject should fail when server is down', async function () {
@@ -498,19 +498,13 @@ describe('test git-proxy-cli', function () {
498498
before(async function () {
499499
await helper.addRepoToDb(TEST_REPO_CONFIG);
500500
await helper.addUserToDb(TEST_USER, TEST_PASSWORD, TEST_EMAIL, TEST_GIT_ACCOUNT);
501-
await helper.addGitPushToDb(pushId, TEST_REPO, TEST_USER, TEST_EMAIL);
501+
await helper.addGitPushToDb(pushId, TEST_REPO_CONFIG.url, TEST_USER, TEST_EMAIL);
502502
});
503503

504504
after(async function () {
505505
await helper.removeGitPushFromDb(pushId);
506506
await helper.removeUserFromDb(TEST_USER);
507-
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
508-
});
509-
510-
after(async function () {
511-
await helper.removeUserFromDb('testuser1');
512-
await helper.removeGitPushFromDb(pushId);
513-
await helper.removeRepoFromDb(TEST_REPO_CONFIG.name);
507+
await helper.removeRepoFromDb(TEST_REPO_CONFIG.url);
514508
});
515509

516510
it('attempt to ls should list existing push', async function () {

packages/git-proxy-cli/test/testCliUtils.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ async function runCli(
3030
expectedExitCode = 0,
3131
expectedMessages = null,
3232
expectedErrorMessages = null,
33-
debug = false,
33+
debug = true,
3434
) {
3535
try {
3636
console.log(`cli: '${cli}'`);
@@ -152,8 +152,9 @@ async function addRepoToDb(newRepo, debug = false) {
152152
const found = repos.find((y) => y.project === newRepo.project && newRepo.name === y.name);
153153
if (!found) {
154154
await db.createRepo(newRepo);
155-
await db.addUserCanPush(newRepo.name, 'admin');
156-
await db.addUserCanAuthorise(newRepo.name, 'admin');
155+
const repo = await db.getRepoByUrl(newRepo.url);
156+
await db.addUserCanPush(repo._id, 'admin');
157+
await db.addUserCanAuthorise(repo._id, 'admin');
157158
if (debug) {
158159
console.log(`New repo added to database: ${newRepo}`);
159160
}
@@ -166,27 +167,28 @@ async function addRepoToDb(newRepo, debug = false) {
166167

167168
/**
168169
* Removes a repo from the DB.
169-
* @param {string} repoName The name of the repo to remove.
170+
* @param {string} repoUrl The url of the repo to remove.
170171
*/
171-
async function removeRepoFromDb(repoName) {
172-
await db.deleteRepo(repoName);
172+
async function removeRepoFromDb(repoUrl) {
173+
const repo = await db.getRepoByUrl(repoUrl);
174+
await db.deleteRepo(repo._id);
173175
}
174176

175177
/**
176178
* Add a new git push record to the database.
177179
* @param {string} id The ID of the git push.
178-
* @param {string} repo The repository of the git push.
180+
* @param {string} repoUrl The repository URL of the git push.
179181
* @param {string} user The user who pushed the git push.
180182
* @param {string} userEmail The email of the user who pushed the git push.
181183
* @param {boolean} debug Flag to enable logging for debugging.
182184
*/
183-
async function addGitPushToDb(id, repo, user = null, userEmail = null, debug = false) {
185+
async function addGitPushToDb(id, repoUrl, user = null, userEmail = null, debug = false) {
184186
const action = new actions.Action(
185187
id,
186188
'push', // type
187189
'get', // method
188190
Date.now(), // timestamp
189-
repo,
191+
repoUrl,
190192
);
191193
action.user = user;
192194
action.userEmail = userEmail;

proxy.config.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"proxyUrl": "https://github.com",
32
"cookieSecret": "cookie secret",
43
"sessionMaxAgeHours": 12,
54
"rateLimit": {

src/config/index.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ let _database: Database[] = defaultSettings.sink;
2828
let _authentication: Authentication[] = defaultSettings.authentication;
2929
let _apiAuthentication: Authentication[] = defaultSettings.apiAuthentication;
3030
let _tempPassword: TempPasswordConfig = defaultSettings.tempPassword;
31-
let _proxyUrl = defaultSettings.proxyUrl;
3231
let _api: Record<string, unknown> = defaultSettings.api;
3332
let _cookieSecret: string = serverConfig.GIT_PROXY_COOKIE_SECRET || defaultSettings.cookieSecret;
3433
let _sessionMaxAgeHours: number = defaultSettings.sessionMaxAgeHours;
@@ -54,15 +53,6 @@ let _config = { ...defaultSettings, ...(_userSettings || {}) } as Configuration;
5453
// Create config loader instance
5554
const configLoader = new ConfigLoader(_config);
5655

57-
// Get configured proxy URL
58-
export const getProxyUrl = () => {
59-
if (_userSettings !== null && _userSettings.proxyUrl) {
60-
_proxyUrl = _userSettings.proxyUrl;
61-
}
62-
63-
return _proxyUrl;
64-
};
65-
6656
// Gets a list of authorised repositories
6757
export const getAuthorisedList = () => {
6858
if (_userSettings !== null && _userSettings.authorisedList) {

src/db/file/index.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,27 @@ import * as users from './users';
22
import * as repo from './repo';
33
import * as pushes from './pushes';
44

5-
export const {
6-
getPushes,
7-
writeAudit,
8-
getPush,
9-
deletePush,
10-
authorise,
11-
cancel,
12-
reject,
13-
canUserCancelPush,
14-
canUserApproveRejectPush,
15-
} = pushes;
5+
export const { getPushes, writeAudit, getPush, deletePush, authorise, cancel, reject } = pushes;
166

177
export const {
188
getRepos,
199
getRepo,
10+
getRepoByUrl,
11+
getRepoById,
2012
createRepo,
2113
addUserCanPush,
2214
addUserCanAuthorise,
2315
removeUserCanPush,
2416
removeUserCanAuthorise,
2517
deleteRepo,
26-
isUserPushAllowed,
27-
canUserApproveRejectPushRepo,
2818
} = repo;
2919

30-
export const { findUser, findUserByOIDC, getUsers, createUser, deleteUser, updateUser } = users;
20+
export const {
21+
findUser,
22+
findUserByEmail,
23+
findUserByOIDC,
24+
getUsers,
25+
createUser,
26+
deleteUser,
27+
updateUser,
28+
} = users;

0 commit comments

Comments
 (0)