diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0449e4a --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "weekly" + allow: + - dependency-type: production diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3eae1ac --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,41 @@ +name: CI + +on: [ push ] + +env: + CI: true + +jobs: + + lint: + uses: haraka/.github/.github/workflows/lint.yml@master + + # coverage: + # uses: haraka/.github/.github/workflows/coverage.yml@master + # secrets: inherit + + test: + needs: [ lint, get-lts ] + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ ubuntu-latest ] + node-version: ${{ fromJson(needs.get-lts.outputs.active) }} + fail-fast: false + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + name: Node ${{ matrix.node-version }} on ${{ matrix.os }} + with: + node-version: ${{ matrix.node-version }} + - run: npm install + - run: npm test + + get-lts: + runs-on: ubuntu-latest + steps: + - id: get + uses: msimerson/node-lts-versions@v1 + outputs: + active: ${{ steps.get.outputs.active }} + lts: ${{ steps.get.outputs.lts }} diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..383aca2 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,13 @@ +name: "CodeQL" + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + schedule: + - cron: '18 7 * * 4' + +jobs: + codeql: + uses: haraka/.github/.github/workflows/codeql.yml@master diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..42a9bb9 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,14 @@ +name: publish + +on: + push: + branches: + - master + +env: + CI: true + +jobs: + publish: + uses: haraka/.github/.github/workflows/publish.yml@master + secrets: inherit \ No newline at end of file diff --git a/.gitignore b/.gitignore index 9c1e43f..2d06a92 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,47 @@ +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories node_modules -!tests/node_modules -.coveralls.yml -Haraka -*~ +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +package-lock.json bower_components -coverage +# Optional npm cache directory +.npmrc .idea +.DS_Store +haraka-update.sh +.release +.gitmodules \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..a8e94cb --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule ".release"] + path = .release + url = git@github.com:msimerson/.release.git diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..3e8e260 --- /dev/null +++ b/.npmignore @@ -0,0 +1,58 @@ +# Logs +logs +*.log +npm-debug.log* + +# Runtime data +pids +*.pid +*.seed + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# Optional npm cache directory +.npm + +# Optional REPL history +.node_repl_history + +package-lock.json +bower_components +# Optional npm cache directory +.npmrc +.idea +.DS_Store +haraka-update.sh + +.github +.release +.codeclimate.yml +.editorconfig +.gitignore +.gitmodules +.lgtm.yml +appveyor.yml +codecov.yml +.travis.yml +.eslintrc.yaml +.eslintrc.json diff --git a/.release b/.release new file mode 160000 index 0000000..9be2b27 --- /dev/null +++ b/.release @@ -0,0 +1 @@ +Subproject commit 9be2b270ef836bcfefda085674bf62e2a91defe8 diff --git a/README.md b/README.md index f71034b..3846a9f 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ This plugin has been replaced by [haraka-plugin-limit](https://github.com/haraka/haraka-plugin-limit) -## Outbound Rate Limits +---- -[![Greenkeeper badge](https://badges.greenkeeper.io/haraka/haraka-plugin-outbound-rate-limit.svg)](https://greenkeeper.io/) +## Outbound Rate Limits This plugin for Haraka implements outbound rate limits using redis as the shared store. diff --git a/index.js b/index.js index c6f19ef..f4864c7 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,12 @@ "use strict"; -var constants = require('haraka-constants'); +const constants = require('haraka-constants'); exports.redis_host = '127.0.0.1:6379'; -var redis_client; +let redis_client; exports.register = function () { - var plugin = this; + const plugin = this; plugin.load_config(); plugin.init_redis(); @@ -18,18 +18,18 @@ exports.register = function () { } exports.increment_limit = function (next, hmail) { - var plugin = this; + const plugin = this; - var rkey = 'outbound-rate-limit:' + hmail.domain; + const rkey = `outbound-rate-limit:${ hmail.domain}`; redis_client.hincrby(rkey, 'TOTAL', 1); redis_client.hget(rkey, 'TOTAL', function (err, count) { if (err) { - plugin.logerror("Failed to get value from redis: " + err); + plugin.logerror(`Failed to get value from redis: ${ err}`); return next(); // just deliver } count = parseInt(count, 10); if (plugin.cfg.limits[hmail.domain]) { - var limit = parseInt(plugin.cfg.limits[hmail.domain], 10); + const limit = parseInt(plugin.cfg.limits[hmail.domain], 10); if (limit && count > limit) { return next(constants.delay, plugin.delay); } @@ -40,13 +40,13 @@ exports.increment_limit = function (next, hmail) { exports.decrement_limit = function (next, hmail) { - var rkey = 'outbound-rate-limit:' + hmail.domain; + const rkey = `outbound-rate-limit:${ hmail.domain}`; redis_client.hincrby(rkey, 'TOTAL', -1); return next(); } exports.load_config = function () { - var plugin = this; + const plugin = this; plugin.cfg = plugin.config.get('outbound_rate_limit.ini', { booleans: [], @@ -59,21 +59,21 @@ exports.load_config = function () { if (plugin.cfg.main.redis_host && plugin.cfg.main.redis_host !== plugin.redis_host) { plugin.redis_host = plugin.cfg.main.redis_host; - plugin.loginfo('set redis host to: ' + plugin.redis_host); + plugin.loginfo(`set redis host to: ${ plugin.redis_host}`); } }; exports.init_redis = function () { if (redis_client) { return; } - var redis = require('redis'); - var host_port = this.redis_host.split(':'); - var host = host_port[0] || '127.0.0.1'; - var port = parseInt(host_port[1], 10) || 6379; + const redis = require('redis'); + const host_port = this.redis_host.split(':'); + const host = host_port[0] || '127.0.0.1'; + const port = parseInt(host_port[1], 10) || 6379; redis_client = redis.createClient(port, host); redis_client.on('error', (err) => { - this.logerror('Redis error: ' + err); + this.logerror(`Redis error: ${ err}`); redis_client.quit(); redis_client = null; // should force a reconnect // not sure if that's the right thing but better than nothing... diff --git a/package.json b/package.json index 1eaf751..72a9d04 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,9 @@ "description": "Haraka Plugin for outbound rate limits", "main": "index.js", "scripts": { - "lint": "./node_modules/.bin/eslint *.js", - "test": "echo \"Error: no test specified\" && exit 1" + "lint": "npx eslint *.js", + "lintfix": "npx eslint --fix *.js", + "test": "echo \"Error: no test specified\"" }, "repository": { "type": "git", @@ -24,10 +25,10 @@ "homepage": "https://github.com/haraka/haraka-plugin-outbound-rate-limit#readme", "dependencies": { "haraka-constants": "*", - "redis": "^2.6.1" + "redis": "^3.1.2" }, "devDependencies": { - "eslint": ">=3", + "eslint": ">=8", "eslint-plugin-haraka": "*" } }