External Services
How to integrate external services
The ExternalServiceIntegration sample (@finos/git-proxy-plugin-samples/externalServiceIntegration) shows how to integrate a GitProxy plugin with an external service, and keep the git push connection open while waiting for the service to complete. It also demonstrates how to handle client disconnection.
In this example, we're using a mock Data Loss Prevention (DLP) service.
Components
-
externalServiceIntegration.tsis the actualPushActionPlugin. It sends the diff to the mock DLP service, waits for the verdict, and finally lets the push continue (or blocks it).submitScancalls the mock service. Replace this with a call to your actual external servicewaitForResultwaits for the result to come back, and also checks for client disconnection viaisClientDisconnected. Replace theDlpScanparameter with the relevant object handle (i.e. aJoborScanobject) for the actual service
-
mockDlpService.tsis a fake DLP service. It doesn't depend on GitProxy: it takes each scan and answers it with a random verdict after a random delay. Replace this with a client for your real service.- The verdict is randomized and the delay is too: some scans take a few seconds (2-30 seconds) while others take much longer (1-10 minutes).
- Since the default timeout is 5 minutes, some scans will time out.
ExternalServiceIntegrationhandles this inresult.status === 'timeout'. The push is rejected but the scan continues in the external service. The user is prompted to push again in order to reattach the scan - If the DLP approves the scan, the push continues through the remaining chain steps. If rejected, the push is blocked with a random reason from
REJECTION_REASONS - If the client disconnects while waiting, the scan continues and it will be reattached in the next
git push
ExternalServiceIntegration runs in the AFTER_DIFF phase of the branch push chain. See Chain Phases for when action.diff is available.
Try it out
- Run
npm run buildinplugins/git-proxy-plugin-samplesand install the package next to GitProxy (see the plugin guide). - Add the plugin to
proxy.config.json:
{
"plugins": ["@finos/git-proxy-plugin-samples/externalServiceIntegration"]
}
- Optionally, create an executable
hooks/pre-receive.shfile relative to the directory where GitProxy is started. Make the hook exit with0so that pushes skip the manual approval phase. Combined with theExternalServiceIntegrationsample, pushes approved by the DLP are automatically approved, rejected ones are automatically rejected. See Pre-Receive Hook for how those exit codes are applied.
mkdir -p hooks
printf '#!/bin/sh\nexit 0\n' > hooks/pre-receive.sh
chmod +x hooks/pre-receive.sh
- Start GitProxy and make a push. See the
[MockDLP]and[ExternalServiceIntegration]output in the server logs. Mock scans log their result and delay ahead of time so GitProxy behaviour is easier to understand.