Skip to content

Commit

Permalink
Merge branch 'main' into license_inventory_kickoff
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieSlome authored Dec 6, 2024
2 parents 02cb92f + e640ef1 commit 35fa251
Show file tree
Hide file tree
Showing 12 changed files with 827 additions and 1,445 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
npm run test-coverage-ci --workspaces --if-present
- name: Upload test coverage report
uses: codecov/codecov-action@v4.6.0
uses: codecov/codecov-action@v5.0.7
with:
files: ./coverage/lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/sample-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Publish samples to NPM

on:
push:
tags:
- 'sample-*'

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
# Setup .npmrc file to publish to npm
- uses: actions/setup-node@v4
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- name: publish sample package
run: npm install --include peer && npm publish --access=public
working-directory: plugins/git-proxy-plugin-samples
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:

steps:
- name: Harden Runner
uses: step-security/harden-runner@91182cccc01eb5e619899d80e4e971d6181294a7 # v2.10.1
uses: step-security/harden-runner@0080882f6c36860b6ba35c610c98ce87d4e2f26f # v2.10.2
with:
egress-policy: audit

Expand Down Expand Up @@ -72,6 +72,6 @@ jobs:

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@e2b3eafc8d227b0241d48be5f425d47c2d750a13 # v3.26.10
uses: github/codeql-action/upload-sarif@aa578102511db1f4524ed59b8cc2bae4f6e88195 # v3.27.6
with:
sarif_file: results.sarif
1,834 changes: 590 additions & 1,244 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-html-parser": "^2.0.2",
"react-router-dom": "6.26.2",
"react-router-dom": "6.28.0",
"simple-git": "^3.25.0",
"uuid": "^10.0.0",
"yargs": "^17.7.2"
Expand Down
18 changes: 0 additions & 18 deletions packages/git-proxy-notify-hello/package.json

This file was deleted.

10 changes: 0 additions & 10 deletions plugins/README.md

This file was deleted.

14 changes: 14 additions & 0 deletions plugins/git-proxy-plugin-samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# GitProxy plugins & samples
GitProxy supports extensibility in the form of plugins. These plugins are specified via [configuration](https://git-proxy.finos.org/docs/category/configuration) as NPM packages or JavaScript code on disk. For each plugin configured, GitProxy will attempt to load each package or file as a standard [Node module](https://nodejs.org/api/modules.html). Plugin authors will create instances of the extension classes exposed by GitProxy and use these objects to implement custom functionality.

For detailed documentation, please refer to the [GitProxy development resources on the project's site](https://git-proxy.finos.org/docs/development/plugins)

## Included plugins
These plugins are maintained by the core GitProxy team. As a future roadmap item, organizations can choose to omit
certain features of GitProxy by simply removing the dependency from a deployed version of the application.

- `git-proxy-plugin-samples`: "hello world" examples of the GitProxy plugin system

## Contributing

Please refer to the [CONTRIBUTING.md](https://git-proxy.finos.org/docs/development/contributing) file for information on how to contribute to the GitProxy project.
4 changes: 2 additions & 2 deletions plugins/git-proxy-plugin-samples/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*/

// Peer dependencies; its expected that these deps exist on Node module path if you've installed @finos/git-proxy
import { PullActionPlugin } from "@finos/git-proxy/src/plugin";
import { Step } from "@finos/git-proxy/src/proxy/actions";
import { PullActionPlugin } from "@finos/git-proxy/src/plugin.js";
import { Step } from "@finos/git-proxy/src/proxy/actions/index.js";

class RunOnPullPlugin extends PullActionPlugin {
constructor() {
Expand Down
4 changes: 2 additions & 2 deletions plugins/git-proxy-plugin-samples/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finos/git-proxy-plugin-samples",
"version": "0.1.0-alpha.0",
"version": "0.1.1",
"description": "A set of sample (dummy) plugins for GitProxy to demonstrate how plugins are authored.",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand All @@ -16,6 +16,6 @@
"express": "^4.18.2"
},
"peerDependencies": {
"@finos/git-proxy": "1.3.5-alpha.5"
"@finos/git-proxy": "^1.4.0"
}
}
88 changes: 50 additions & 38 deletions website/docs/development/plugins.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ The below instructions are using the [`@finos/git-proxy-plugin-samples`](https:/
1. Install both `@finos/git-proxy` and the `@finos/git-proxy-plugin-samples` package to the local `node_modules/` directory using the following command:

```bash
$ npm install -g @finos/git-proxy@latest @finos/git-proxy-plugin-samples@0.1.0
$ npm install -g @finos/git-proxy @finos/git-proxy-plugin-samples
```

Alternatively, you can create local packages from source and install those instead.
```bash
$ git clone https://github.com/finos/git-proxy
$ cd git-proxy
$ npm pack
$ npm install -g ./finos-git-proxy-1.3.5.tgz
$ (cd plugins/git-proxy-plugin-samples && npm pack)
$ npm install -g plugins/git-proxy-plugin-samples/finos-git-proxy-plugin-samples-0.1.0.tgz
$ npm install -g \
./finos-git-proxy-1.7.0.tgz \
./plugins/git-proxy-plugin-samples/finos-git-proxy-plugin-samples-0.1.1.tgz
```

2. Create or edit an existing `proxy.config.json` file to configure the plugin(s) to load. You must include the full import path that would typically be used in a `import {}` (ESM) or `require()` (CJS) statement:
Expand Down Expand Up @@ -85,7 +86,7 @@ $ cat package.json
"name": "foo-plugin",
...
"dependencies": {
"@finos/git-proxy": "^1.3.5"
"@finos/git-proxy": "^1.7.0"
}
}
# Alternatively, add git-proxy that is cloned locally as a file-based dependency
Expand Down Expand Up @@ -122,29 +123,42 @@ Loaded plugin: FooPlugin

## Developing new plugins

To develop a new plugin, you must add `@finos/git-proxy` as a [peer dependency](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies). The main app (also known as the "host application") exports the following extension points:
To develop a new plugin, you must add `@finos/git-proxy` as a [peer dependency](https://docs.npmjs.com/cli/v10/configuring-npm/package-json#peerdependencies). The plugin & proxy classes can then be imported from `@finos/git-proxy` via the following extension points:

- `@finos/git-proxy/src/plugin/PushActionPlugin`: execute as an action in the proxy chain during a `git push`
- `@finos/git-proxy/src/plugin/PullActionPlugin`: execute as an action in the proxy chain during a `git fetch`
- `@finos/git-proxy/src/proxy/actions/Step` and `@finos/git-proxy/src/proxy/actions/Action`: internal classes which act as carriers for `git` state during proxying. Plugins should modify the passed in `action` for affecting any global state of the git operation and add its own custom `Step` object to capture the plugin's own internal state (logs, errored/blocked status, etc.)
```js
import { PushActionPlugin } from '@finos/git-proxy/src/plugin.js'
```
- Use this class to execute as an action in the proxy chain during a `git push`


```js
import { PullActionPlugin } from '@finos/git-proxy/src/plugin.js'
```
- Use this class to execute as an action in the proxy chain during a `git fetch`


```js
import { Step, Action } from '@finos/git-proxy/src/proxy/actions/index.js'
```
- These are internal classes which act as carriers for `git` state during proxying. Plugins should modify the passed in `Action` for affecting any global state of the git operation and add its own custom `Step` object to capture the plugin's own internal state (logs, errored/blocked status, etc).

GitProxy will load your plugin only if it extends one of the two plugin classes above. It is also important that your package has [`exports`](https://nodejs.org/api/packages.html#exports) defined for the plugin loader to properly load your module(s).
GitProxy will load your plugin only if it extends one of the two plugin classes above.

Please see the [sample plugin package included in the repo](https://github.com/finos/git-proxy/tree/main/plugins/git-proxy-plugin-samples) for details on how to structure your plugin package.

If your plugin relies on custom state, it is recommended to create subclasses in the following manner:

```javascript
import { PushActionPlugin } from "@finos/git-proxy/src/plugin";
import { PushActionPlugin } from "@finos/git-proxy/src/plugin.js";

class FooPlugin extends PushActionPlugin {
constructor() {
super(); // don't pass any function to the parent class - let the parent's this.exec function be undefined
this.displayName = 'FooPlugin';
this.someProperty = 'Hello from the FooPlugin';
// overwrite the parent's exec function which is executed as part of GitProxy's action chain.
// use an arrow function if you require access to the instances's state (properties, methods, etc.)
this.exec = async (req, action) => {
console.log(this.displayName);
console.log(this.someProperty);
this.utilMethod();
// do something
return action;
Expand All @@ -157,40 +171,20 @@ class FooPlugin extends PushActionPlugin {
}
```

### Example
### Instructions for creating a new plugin package

1. Create a new directory for your plugin package and initialize a new npm package:
```bash
$ npm init
# ...
$ npm install --save-peer @finos/git-proxy@latest
$ npm install --save-peer @finos/git-proxy
```

`package.json`

```json
{
"name": "bar",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"description": "",
"exports": {
".": "./bar.js"
},
"peerDependencies": {
"@finos/git-proxy": "^1.3.5"
}
}
```
2. Create a new JavaScript file for your plugin. The file should export an instance of `PushActionPlugin` or `PullActionPlugin`:

`bar.js`
```javascript
import { PushActionPlugin } from "@finos/git-proxy/src/plugin";
import { Step } from "@finos/git-proxy/src/proxy/actions";
import { PushActionPlugin } from "@finos/git-proxy/src/plugin.js";
import { Step } from "@finos/git-proxy/src/proxy/actions/index.js";

//Note: Only use a default export if you do not rely on any state. Otherwise, create a sub-class of [Push/Pull]ActionPlugin
export default new PushActionPlugin(function(req, action) {
Expand All @@ -206,3 +200,21 @@ export default new PushActionPlugin(function(req, action) {
return action; // always return the action - even in the case of errors
});
```

3. In your GitProxy installation, install your plugin package & update the `proxy.config.json` file to include the path to your plugin module(s):

```bash
$ npm install @finos/git-proxy /path/to/your/plugin/package
$ cat proxy.config.json
{
"plugins": [
"/path/to/your/plugin/package/index.js"
]
}
$ git-proxy
Service Listening on 8080
HTTP Proxy Listening on 8000
HTTPS Proxy Listening on 8443
Found 1 plugin modules
Loaded plugin: PushActionPlugin
```
Loading

0 comments on commit 35fa251

Please sign in to comment.