Skip to content

Commit ba4f08e

Browse files
authored
Merge pull request finos#1499 from fabiovincenzi/fix/cli-restore
fix: restore broken CLI package
2 parents c0b4a8d + 1b3e695 commit ba4f08e

6 files changed

Lines changed: 54 additions & 9 deletions

File tree

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
"types": "./dist/src/ui/index.d.ts",
4040
"import": "./dist/src/ui/index.js",
4141
"require": "./dist/src/ui/index.js"
42+
},
43+
"./utils/errors": {
44+
"types": "./dist/src/utils/errors.d.ts",
45+
"import": "./dist/src/utils/errors.js",
46+
"require": "./dist/src/utils/errors.js"
4247
}
4348
},
4449
"scripts": {

packages/git-proxy-cli/index.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,19 @@ async function authoriseGitPush(id: string) {
229229
if (isAxiosError(error) && error.response) {
230230
switch (error.response.status) {
231231
case 401:
232+
case 403:
232233
console.error('Error: Authorise: Authentication required');
233234
process.exitCode = 3;
234235
break;
235236
case 404:
236237
console.error(`Error: Authorise: ID: '${id}': Not Found`);
237238
process.exitCode = 4;
239+
break;
240+
default:
241+
console.error(
242+
`Error: Authorise: '${error.response.status}': ${error.response.data?.message || error.message}`,
243+
);
244+
process.exitCode = 5;
238245
}
239246
} else {
240247
handleErrorAndLog(error, `Error: Authorise: '${id}'`);
@@ -247,7 +254,7 @@ async function authoriseGitPush(id: string) {
247254
* Reject git push by ID
248255
* @param {string} id The ID of the git push to reject
249256
*/
250-
async function rejectGitPush(id: string) {
257+
async function rejectGitPush(id: string, reason: string) {
251258
if (!fs.existsSync(GIT_PROXY_COOKIE_FILE)) {
252259
console.error('Error: Reject: Authentication required');
253260
process.exitCode = 1;
@@ -263,7 +270,7 @@ async function rejectGitPush(id: string) {
263270

264271
await axios.post(
265272
`${baseUrl}/api/v1/push/${id}/reject`,
266-
{},
273+
{ reason },
267274
{
268275
headers: { Cookie: cookies },
269276
},
@@ -274,12 +281,19 @@ async function rejectGitPush(id: string) {
274281
if (isAxiosError(error) && error.response) {
275282
switch (error.response.status) {
276283
case 401:
284+
case 403:
277285
console.error('Error: Reject: Authentication required');
278286
process.exitCode = 3;
279287
break;
280288
case 404:
281289
console.error(`Error: Reject: ID: '${id}': Not Found`);
282290
process.exitCode = 4;
291+
break;
292+
default:
293+
console.error(
294+
`Error: Reject: '${error.response.status}': ${error.response.data?.message || error.message}`,
295+
);
296+
process.exitCode = 5;
283297
}
284298
} else {
285299
handleErrorAndLog(error, `Error: Reject: '${id}'`);
@@ -319,12 +333,19 @@ async function cancelGitPush(id: string) {
319333
if (isAxiosError(error) && error.response) {
320334
switch (error.response.status) {
321335
case 401:
336+
case 403:
322337
console.error('Error: Cancel: Authentication required');
323338
process.exitCode = 3;
324339
break;
325340
case 404:
326341
console.error(`Error: Cancel: ID: '${id}': Not Found`);
327342
process.exitCode = 4;
343+
break;
344+
default:
345+
console.error(
346+
`Error: Cancel: '${error.response.status}': ${error.response.data?.message || error.message}`,
347+
);
348+
process.exitCode = 5;
328349
}
329350
} else {
330351
handleErrorAndLog(error, `Error: Cancel: '${id}'`);
@@ -423,6 +444,7 @@ async function createUser(
423444
if (isAxiosError(error) && error.response) {
424445
switch (error.response.status) {
425446
case 401:
447+
case 403:
426448
console.error('Error: Create User: Authentication required');
427449
process.exitCode = 3;
428450
break;
@@ -563,9 +585,14 @@ yargs(hideBin(process.argv)) // eslint-disable-line @typescript-eslint/no-unused
563585
demandOption: true,
564586
type: 'string',
565587
},
588+
reason: {
589+
describe: 'Reason for rejection',
590+
type: 'string',
591+
default: 'Rejected via GitProxy CLI',
592+
},
566593
},
567594
handler(argv) {
568-
rejectGitPush(argv.id);
595+
rejectGitPush(argv.id, argv.reason);
569596
},
570597
})
571598
.command({

packages/git-proxy-cli/test/testCli.proxy.config.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
"enabled": false
2525
}
2626
],
27+
"attestationConfig": {
28+
"questions": [
29+
{
30+
"label": "Authorising via GitProxy CLI",
31+
"required": true
32+
}
33+
]
34+
},
2735
"authentication": [
2836
{
2937
"type": "local",

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@ import path from 'path';
1919
import { describe, it, beforeAll, afterAll } from 'vitest';
2020

2121
import { setConfigFile } from '../../../src/config/file';
22+
import { invalidateCache } from '../../../src/config';
2223
import { SAMPLE_REPO } from '../../../src/proxy/processors/constants';
2324
import { handleErrorAndLog } from '../../../src/utils/errors';
2425

25-
setConfigFile(path.join(process.cwd(), 'test', 'testCli.proxy.config.json'));
26+
setConfigFile(
27+
path.join(process.cwd(), 'packages', 'git-proxy-cli', 'test', 'testCli.proxy.config.json'),
28+
);
29+
invalidateCache();
2630

2731
/* test constants */
2832
// push ID which does not exist
@@ -774,7 +778,7 @@ describe('test git-proxy-cli', function () {
774778
let expectedErrorMessages = null;
775779
await helper.runCli(cli, expectedExitCode, expectedMessages, expectedErrorMessages);
776780

777-
cli = `${CLI_PATH} reject --id ${pushId}`;
781+
cli = `${CLI_PATH} reject --id ${pushId} --reason "Rejected via CLI test"`;
778782
expectedExitCode = 0;
779783
expectedMessages = [`Reject: ID: '${pushId}': OK`];
780784
expectedErrorMessages = null;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import { exec } from 'child_process';
2020
import { expect } from 'vitest';
2121
import { Request } from 'express';
2222

23-
import Proxy from '../../../src/proxy';
23+
import { Proxy } from '../../../src/proxy';
2424
import { Action } from '../../../src/proxy/actions/Action';
2525
import { Step } from '../../../src/proxy/actions/Step';
26-
import { exec as execProcessor } from '../../../src/proxy/processors/push-action/audit';
26+
import { exec as execProcessor } from '../../../src/proxy/processors/post-processor/audit';
2727
import * as db from '../../../src/db';
2828
import { Repo } from '../../../src/db/types';
29-
import service from '../../../src/service';
29+
import { Service as service } from '../../../src/service';
3030
import { CommitData } from '../../../src/proxy/processors/types';
3131

3232
const execAsync = util.promisify(exec);

packages/git-proxy-cli/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"allowSyntheticDefaultImports": true,
1616
"resolveJsonModule": true,
1717
"outDir": "./dist",
18-
"rootDir": "."
18+
"rootDir": ".",
19+
"types": ["node"]
1920
},
2021
"include": ["index.ts", "types.ts"],
2122
"exclude": [

0 commit comments

Comments
 (0)