Skip to content

Commit

Permalink
rename to forwarder
Browse files Browse the repository at this point in the history
Signed-off-by: Collin McNeese <[email protected]>
  • Loading branch information
collinmcneese committed Jan 29, 2023
1 parent 519e8bd commit 3ef95de
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 56 deletions.
50 changes: 25 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![CodeQL](https://github.com/collinmcneese/github-actions-reflector/actions/workflows/codeql.yml/badge.svg)](https://github.com/collinmcneese/github-actions-reflector/actions/workflows/codeql.yml) [![ci](https://github.com/collinmcneese/github-actions-reflector/actions/workflows/ci.yml/badge.svg)](https://github.com/collinmcneese/github-actions-reflector/actions/workflows/ci.yml)
[![CodeQL](https://github.com/collinmcneese/github-actions-forwarder/actions/workflows/codeql.yml/badge.svg)](https://github.com/collinmcneese/github-actions-forwarder/actions/workflows/codeql.yml) [![ci](https://github.com/collinmcneese/github-actions-forwarder/actions/workflows/ci.yml/badge.svg)](https://github.com/collinmcneese/github-actions-forwarder/actions/workflows/ci.yml)

# GitHub Actions Reflector
# GitHub Actions Forwarder

GitHub Actions workflow meant to run on [self-hosted](https://docs.github.com/en/actions/hosting-your-own-runners/about-self-hosted-runners) runners to leverage internal or private tooling (such as CICD systems) with GitHub repositories without the need to use reverse proxy implementations. Additionally could be used with [GitHub Larger Runners](https://docs.github.com/en/actions/using-github-hosted-runners/using-larger-runners) with reserved IPs to minimize ingress points and remove the need for self-hosted runner administration and maintenance.

Expand All @@ -14,7 +14,7 @@ The contents of this repository are individually maintained and are not a direct

- `target-url`: **String**, **Required**

The target URL destination where webhook event payloads will be reflected to.
The target URL destination where webhook event payloads will be forwarded to.
- `webhook-secret`: **String**, **Optional**

Secret data value to use for webhook payload. Populates `X-Hub-Signature` and `X-Hub-Signature-256` header values. See [Securing Your Webhooks](https://docs.github.com/en/developers/webhooks-and-events/webhooks/securing-your-webhooks) for additional context.
Expand All @@ -35,68 +35,68 @@ The contents of this repository are individually maintained and are not a direct

### Examples

Example simple workflow for consuming reflector:
Example simple workflow for consuming forwarder:

```yaml
name: reflector-call
name: forwarder-call

on:
pull_request:

jobs:
reflector-call:
forwarder-call:
runs-on: self-hosted
steps:
- name: GitHub Actions Reflector
uses: collinmcneese/github-actions-reflector@main
- name: GitHub Actions Forwarder
uses: collinmcneese/github-actions-forwarder@v1
with:
target-url: 'http://172.17.0.1:8080/github-webhook/'
webhook-secret: ${{ secrets.REFLECTOR_WEBHOOK_SECRET }}
webhook-secret: ${{ secrets.FORWARDER_WEBHOOK_SECRET }}
```
Example workflow using [variables](https://docs.github.com/en/actions/learn-github-actions/variables) to target requests to different endpoints:
```yaml
name: reflector-dynamic
name: forwarder-dynamic

on:
pull_request:
push:
issues:

jobs:
reflector-call:
forwarder-call:
runs-on: self-hosted
steps:
- name: Push - Reflector
- name: Push - Forwarder
if: |
github.event_name == 'push' ||
github.event_name == 'pull_request'
uses: collinmcneese/github-actions-reflector@main
uses: collinmcneese/github-actions-forwarder@v1
with:
target-url: ${{ vars.REFLECTOR_TARGET_PUSH }}
webhook-secret: ${{ secrets.REFLECTOR_WEBHOOK_SECRET_PUSH }}
allow-list-source: ${{ vars.REFLECTOR_ALLOW_LIST }}
- name: Issue - Reflector
target-url: ${{ vars.FORWARDER_TARGET_PUSH }}
webhook-secret: ${{ secrets.FORWARDER_WEBHOOK_SECRET_PUSH }}
allow-list-source: ${{ vars.FORWARDER_ALLOW_LIST }}
- name: Issue - Forwarder
if: ${{ github.event_name == 'issues' }}
uses: collinmcneese/github-actions-reflector@main
uses: collinmcneese/github-actions-forwarder@v1
with:
target-url: ${{ vars.REFLECTOR_TARGET_ISSUES }}
webhook-secret: ${{ secrets.REFLECTOR_WEBHOOK_SECRET_ISSUES }}
allow-list-source: ${{ vars.REFLECTOR_ALLOW_LIST }}
target-url: ${{ vars.FORWARDER_TARGET_ISSUES }}
webhook-secret: ${{ secrets.FORWARDER_WEBHOOK_SECRET_ISSUES }}
allow-list-source: ${{ vars.FORWARDER_ALLOW_LIST }}
```
## Why Does This Exist?
### Reflector Method
### Forwarder Method
Example overview of an implementation which uses the Actions Reflector workflow to route repository webhook events to internal systems. Actions Reflector is executed as a GitHub Actions workflow from `on:` events such as `push:` or `pull_request:` on self-hosted runners, routing event payloads to downstream target systems. This configuration leverages queueing, notification and retransmission capabilities of GitHub Actions and leverages self-hosted runners to prevent the need for ingress traffic initiation at a network edge.
Example overview of an implementation which uses the Actions Forwarder workflow to route repository webhook events to internal systems. Actions Forwarder is executed as a GitHub Actions workflow from `on:` events such as `push:` or `pull_request:` on self-hosted runners, routing event payloads to downstream target systems. This configuration leverages queueing, notification and retransmission capabilities of GitHub Actions and leverages self-hosted runners to prevent the need for ingress traffic initiation at a network edge.

<img src="./docs/010.png" alt="reflector-setup">
<img src="./docs/010.png" alt="forwarder-setup">

---

### Reverse Proxy Method (not Using Reflector)
### Reverse Proxy Method (not Using Forwarder)

Example overview of an implementation which uses reverse proxy or an API gateway to allow webhook traffic from GitHub cloud repositories to internal systems. In this setup, webhook events are sent from github.com to a reverse proxy or API gateway which are routed to an internal CICD system. This example pattern becomes more complicated when adding additional reliability measures in place such as webhook notifications (success or failure), retransmissions and potentially a queueing mechanism at the API gateway layer to handle traffic bursts and scale as required.

Expand Down
2 changes: 1 addition & 1 deletion __test__/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Wrapper function to run a command and capture the exit code
function ci-run {
echo ":test_tube: $@"
echo "::Running: $@"
$@
local status=$?
if [ $status -ne 0 ]; then
Expand Down
6 changes: 3 additions & 3 deletions __test__/reflector.test.js → __test__/forwarder.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Tests for functions in reflector.js
// Tests for functions in forwarder.js

const reflector = require('../src/reflector');
const { validateUrl, fetchAllowListSource, validateAllowList, getWebhookSignature, getRequestOptions } = reflector.reflectorPrivate;
const forwarder = require('../src/forwarder');
const { validateUrl, fetchAllowListSource, validateAllowList, getWebhookSignature, getRequestOptions } = forwarder.forwarderPrivate;

let allowListObject = [
'https://github.com',
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: GitHub Actions Reflector
description: Actions workflow for redirecting GitHub Actions event payloads to downstream applications.
name: GitHub Actions Forwarder
description: Actions workflow for forwarding GitHub Actions event payloads to downstream applications.
author: 'Collin McNeese'
branding:
icon: 'fast-forward'
Expand Down
20 changes: 10 additions & 10 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42073,10 +42073,10 @@ function wrappy (fn, cb) {

/***/ }),

/***/ 8917:
/***/ 2468:
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {

// reflector.js
// forwarder.js

const request = __nccwpck_require__(1265);
const crypto = __nccwpck_require__(6113);
Expand Down Expand Up @@ -42181,8 +42181,8 @@ function getRequestOptions(context, targetUrl, webhookSecret) {
return options;
}

// Main Reflector function
async function reflector({context, targetUrl, webhookSecret, allowListSource}) {
// Main Forwarder function
async function forwarder({context, targetUrl, webhookSecret, allowListSource}) {
// Validate that targetUrl is a valid URL
validateUrl(targetUrl);

Expand Down Expand Up @@ -42215,7 +42215,7 @@ async function reflector({context, targetUrl, webhookSecret, allowListSource}) {
};

// Export private functions for testing
const reflectorPrivate = {
const forwarderPrivate = {
validateUrl,
fetchAllowListSource,
validateAllowList,
Expand All @@ -42224,8 +42224,8 @@ const reflectorPrivate = {
};

module.exports = {
reflectorPrivate,
reflector,
forwarderPrivate,
forwarder,
};


Expand Down Expand Up @@ -42612,15 +42612,15 @@ var __webpack_exports__ = {};

const core = __nccwpck_require__(9991);
const github = __nccwpck_require__(6140);
const { reflector } = __nccwpck_require__(8917);
const { forwarder } = __nccwpck_require__(2468);

// Parse inputs
const targetUrl = core.getInput('target-url');
const webhookSecret = core.getInput('webhook-secret');
const allowListSource = core.getInput('allow-list-source');

// Run the Reflector action
reflector({
// Run the Forwarder action
forwarder({
context: github.context,
targetUrl: targetUrl,
webhookSecret: webhookSecret,
Expand Down
Binary file modified docs/010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "github-actions-reflector",
"name": "github-actions-forwarder",
"version": "1.0.0",
"description": "Workflow for redirecting GitHub Actions event payloads to downstream applications",
"main": "src/index.js",
Expand All @@ -13,7 +13,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/collinmcneese/github-actions-reflector.git"
"url": "git+https://github.com/collinmcneese/github-actions-forwarder.git"
},
"keywords": [
"github",
Expand All @@ -22,9 +22,9 @@
"author": "Collin McNeese <[email protected]>",
"license": "MIT",
"bugs": {
"url": "https://github.com/collinmcneese/github-actions-reflector/issues"
"url": "https://github.com/collinmcneese/github-actions-forwarder/issues"
},
"homepage": "https://github.com/collinmcneese/github-actions-reflector#readme",
"homepage": "https://github.com/collinmcneese/github-actions-forwarder#readme",
"devDependencies": {
"cspell": "^6.19.2",
"eslint": "^8.32.0",
Expand Down
12 changes: 6 additions & 6 deletions src/reflector.js → src/forwarder.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// reflector.js
// forwarder.js

const request = require('request');
const crypto = require('crypto');
Expand Down Expand Up @@ -103,8 +103,8 @@ function getRequestOptions(context, targetUrl, webhookSecret) {
return options;
}

// Main Reflector function
async function reflector({context, targetUrl, webhookSecret, allowListSource}) {
// Main Forwarder function
async function forwarder({context, targetUrl, webhookSecret, allowListSource}) {
// Validate that targetUrl is a valid URL
validateUrl(targetUrl);

Expand Down Expand Up @@ -137,7 +137,7 @@ async function reflector({context, targetUrl, webhookSecret, allowListSource}) {
};

// Export private functions for testing
const reflectorPrivate = {
const forwarderPrivate = {
validateUrl,
fetchAllowListSource,
validateAllowList,
Expand All @@ -146,6 +146,6 @@ const reflectorPrivate = {
};

module.exports = {
reflectorPrivate,
reflector,
forwarderPrivate,
forwarder,
};
6 changes: 3 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

const core = require('@actions/core');
const github = require('@actions/github');
const { reflector } = require('./reflector');
const { forwarder } = require('./forwarder');

// Parse inputs
const targetUrl = core.getInput('target-url');
const webhookSecret = core.getInput('webhook-secret');
const allowListSource = core.getInput('allow-list-source');

// Run the Reflector action
reflector({
// Run the Forwarder action
forwarder({
context: github.context,
targetUrl: targetUrl,
webhookSecret: webhookSecret,
Expand Down

0 comments on commit 3ef95de

Please sign in to comment.