Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"types": "./dist/src/ui/index.d.ts",
"import": "./dist/src/ui/index.js",
"require": "./dist/src/ui/index.js"
},
"./utils/errors": {
"types": "./dist/src/utils/errors.d.ts",
"import": "./dist/src/utils/errors.js",
"require": "./dist/src/utils/errors.js"
}
},
"scripts": {
Expand Down
33 changes: 30 additions & 3 deletions packages/git-proxy-cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,19 @@ async function authoriseGitPush(id: string) {
if (isAxiosError(error) && error.response) {
switch (error.response.status) {
case 401:
case 403:
console.error('Error: Authorise: Authentication required');
process.exitCode = 3;
break;
case 404:
console.error(`Error: Authorise: ID: '${id}': Not Found`);
process.exitCode = 4;
break;
default:
console.error(
`Error: Authorise: '${error.response.status}': ${error.response.data?.message || error.message}`,
);
process.exitCode = 5;
}
} else {
handleErrorAndLog(error, `Error: Authorise: '${id}'`);
Expand All @@ -247,7 +254,7 @@ async function authoriseGitPush(id: string) {
* Reject git push by ID
* @param {string} id The ID of the git push to reject
*/
async function rejectGitPush(id: string) {
async function rejectGitPush(id: string, reason: string) {
if (!fs.existsSync(GIT_PROXY_COOKIE_FILE)) {
console.error('Error: Reject: Authentication required');
process.exitCode = 1;
Expand All @@ -263,7 +270,7 @@ async function rejectGitPush(id: string) {

await axios.post(
`${baseUrl}/api/v1/push/${id}/reject`,
{},
{ reason },
{
headers: { Cookie: cookies },
},
Expand All @@ -274,12 +281,19 @@ async function rejectGitPush(id: string) {
if (isAxiosError(error) && error.response) {
switch (error.response.status) {
case 401:
case 403:
console.error('Error: Reject: Authentication required');
process.exitCode = 3;
break;
case 404:
console.error(`Error: Reject: ID: '${id}': Not Found`);
process.exitCode = 4;
break;
default:
console.error(
`Error: Reject: '${error.response.status}': ${error.response.data?.message || error.message}`,
);
process.exitCode = 5;
}
} else {
handleErrorAndLog(error, `Error: Reject: '${id}'`);
Expand Down Expand Up @@ -319,12 +333,19 @@ async function cancelGitPush(id: string) {
if (isAxiosError(error) && error.response) {
switch (error.response.status) {
case 401:
case 403:
console.error('Error: Cancel: Authentication required');
process.exitCode = 3;
break;
case 404:
console.error(`Error: Cancel: ID: '${id}': Not Found`);
process.exitCode = 4;
break;
default:
console.error(
`Error: Cancel: '${error.response.status}': ${error.response.data?.message || error.message}`,
);
process.exitCode = 5;
}
} else {
handleErrorAndLog(error, `Error: Cancel: '${id}'`);
Expand Down Expand Up @@ -423,6 +444,7 @@ async function createUser(
if (isAxiosError(error) && error.response) {
switch (error.response.status) {
case 401:
case 403:
console.error('Error: Create User: Authentication required');
process.exitCode = 3;
break;
Expand Down Expand Up @@ -563,9 +585,14 @@ yargs(hideBin(process.argv)) // eslint-disable-line @typescript-eslint/no-unused
demandOption: true,
type: 'string',
},
reason: {
describe: 'Reason for rejection',
type: 'string',
default: 'Rejected via GitProxy CLI',
},
},
handler(argv) {
rejectGitPush(argv.id);
rejectGitPush(argv.id, argv.reason);
},
})
.command({
Expand Down
8 changes: 8 additions & 0 deletions packages/git-proxy-cli/test/testCli.proxy.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
"enabled": false
}
],
"attestationConfig": {
"questions": [
{
"label": "Authorising via GitProxy CLI",
"required": true
}
]
},
"authentication": [
{
"type": "local",
Expand Down
8 changes: 6 additions & 2 deletions packages/git-proxy-cli/test/testCli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@ import path from 'path';
import { describe, it, beforeAll, afterAll } from 'vitest';

import { setConfigFile } from '../../../src/config/file';
import { invalidateCache } from '../../../src/config';
import { SAMPLE_REPO } from '../../../src/proxy/processors/constants';
import { handleErrorAndLog } from '../../../src/utils/errors';

setConfigFile(path.join(process.cwd(), 'test', 'testCli.proxy.config.json'));
setConfigFile(
path.join(process.cwd(), 'packages', 'git-proxy-cli', 'test', 'testCli.proxy.config.json'),
);
invalidateCache();

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

cli = `${CLI_PATH} reject --id ${pushId}`;
cli = `${CLI_PATH} reject --id ${pushId} --reason "Rejected via CLI test"`;
expectedExitCode = 0;
expectedMessages = [`Reject: ID: '${pushId}': OK`];
expectedErrorMessages = null;
Expand Down
6 changes: 3 additions & 3 deletions packages/git-proxy-cli/test/testCliUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import { exec } from 'child_process';
import { expect } from 'vitest';
import { Request } from 'express';

import Proxy from '../../../src/proxy';
import { Proxy } from '../../../src/proxy';
import { Action } from '../../../src/proxy/actions/Action';
import { Step } from '../../../src/proxy/actions/Step';
import { exec as execProcessor } from '../../../src/proxy/processors/push-action/audit';
import { exec as execProcessor } from '../../../src/proxy/processors/post-processor/audit';
import * as db from '../../../src/db';
import { Repo } from '../../../src/db/types';
import service from '../../../src/service';
import { Service as service } from '../../../src/service';
import { CommitData } from '../../../src/proxy/processors/types';

const execAsync = util.promisify(exec);
Expand Down
3 changes: 2 additions & 1 deletion packages/git-proxy-cli/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"outDir": "./dist",
"rootDir": "."
"rootDir": ".",
"types": ["node"]
},
"include": ["index.ts", "types.ts"],
"exclude": [
Expand Down
Loading