Skip to content

Commit

Permalink
Support providing secret via environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Nov 14, 2023
1 parent 034906b commit 46055fc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ A `config.json` file is necessary. It should look like this:

- `port` is the express port the server will be running on.
- `secret` is the secret configured in the GitHub webook.
- The secret can also be provided via the environment variable `WEBHOOK_SECRET`.
- `verbosity` allows controlling which output is logged.
- `log` adds default logging (which webhooks are executed, etc.) as well as error logging for executed commands (default)
- `all` is the same as `log`, but also logs standout output of executed commands as well as the full body of unmatched requests
Expand Down
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ try {
console.error("config.json file is required (see README).")
process.exit(1)
}

// Also support secret from enviroment variable
config.secret = config.secret ?? process.env.WEBHOOK_SECRET

// Configure logging
config.verbosity = ["log", "warn", "error", "all", "none"].includes(config.verbosity) ? config.verbosity : "log"
config.log = (options) => {
Expand Down Expand Up @@ -65,6 +69,11 @@ if (config.webhooks.length) {
} else {
config.warn("There are no webhooks configured in config.json. Please add at least one webhook.")
}

if (!config.secret) {
config.warn("No global secret provided. Only webhooks with a local secret or skipValidation are executed.")
}

// Adjust webhooks
const propertyMappings = {
repository: "body.repository.full_name",
Expand Down

0 comments on commit 46055fc

Please sign in to comment.