-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #713 from RBC/feat/new-plugin-system
feat: expose plugin extension points into main package, developer docs + sample
- Loading branch information
Showing
29 changed files
with
1,427 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
# This file required to override .gitignore when publishing to npm | ||
# This file required to override .gitignore when publishing to npm | ||
website/ | ||
plugins/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# GitProxy plugins & samples | ||
GitProxy supports extensibility in the form of plugins. These plugins are specified via [configuration](/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* This is a sample plugin that logs a message when the pull action is called. It is written using | ||
* CommonJS modules to demonstrate the use of CommonJS in plugins. | ||
*/ | ||
|
||
// Peer dependencies; its expected that these deps exist on Node module path if you've installed @finos/git-proxy | ||
const { PushActionPlugin } = require('@finos/git-proxy/plugin'); | ||
const { Step } = require('@finos/git-proxy/proxy/actions'); | ||
'use strict'; | ||
|
||
/** | ||
* | ||
* @param {object} req Express Request object | ||
* @param {Action} action GitProxy Action | ||
* @return {Promise<Action>} Promise that resolves to an Action | ||
*/ | ||
async function logMessage(req, action) { | ||
const step = new Step('LogRequestPlugin'); | ||
action.addStep(step); | ||
console.log(`LogRequestPlugin: req url ${req.url}`); | ||
console.log(`LogRequestPlugin: req user-agent ${req.header('User-Agent')}`); | ||
console.log('LogRequestPlugin: action', JSON.stringify(action)); | ||
return action; | ||
} | ||
|
||
class LogRequestPlugin extends PushActionPlugin { | ||
constructor() { | ||
super(logMessage) | ||
} | ||
} | ||
|
||
|
||
module.exports = { | ||
// Plugins can be written inline as new instances of Push/PullActionPlugin | ||
// A custom class is not required | ||
hello: new PushActionPlugin(async (req, action) => { | ||
const step = new Step('HelloPlugin'); | ||
action.addStep(step); | ||
console.log('Hello world from the hello plugin!'); | ||
return action; | ||
}), | ||
// Sub-classing is fine too if you require more control over the plugin | ||
logRequest: new LogRequestPlugin(), | ||
someOtherValue: 'foo', // This key will be ignored by the plugin loader | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* This is a sample plugin that logs a message when the pull action is called. It is written using | ||
* ES modules to demonstrate the use of ESM in plugins. | ||
*/ | ||
|
||
// 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/plugin"; | ||
import { Step } from "@finos/git-proxy/proxy/actions"; | ||
|
||
class RunOnPullPlugin extends PullActionPlugin { | ||
constructor() { | ||
super(function logMessage(req, action) { | ||
const step = new Step('RunOnPullPlugin'); | ||
action.addStep(step); | ||
console.log('RunOnPullPlugin: Received fetch request', req.url); | ||
return action; | ||
}) | ||
} | ||
} | ||
|
||
// Default exports are supported and will be loaded by the plugin loader | ||
export default new RunOnPullPlugin(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"name": "@finos/git-proxy-plugin-samples", | ||
"version": "0.1.0-alpha.0", | ||
"description": "A set of sample (dummy) plugins for GitProxy to demonstrate how plugins are authored.", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Thomas Cooper", | ||
"license": "Apache-2.0", | ||
"type": "module", | ||
"exports": { | ||
".": "./index.js", | ||
"./example": "./example.cjs" | ||
}, | ||
"dependencies": { | ||
"express": "^4.18.2" | ||
}, | ||
"peerDependencies": { | ||
"@finos/git-proxy": "1.3.5-alpha.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.