Skip to content

Commit

Permalink
Release v1.0.2 (#14)
Browse files Browse the repository at this point in the history
* ci: add GHA ci workflow
* lint: no-var, prefer-template
* dep(redis): 2 -> 3
  • Loading branch information
msimerson authored Jun 8, 2022
1 parent 6690fe1 commit 95e0f9b
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 26 deletions.
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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 }}
13 changes: 13 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -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
49 changes: 44 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule ".release"]
path = .release
url = git@github.com:msimerson/.release.git
58 changes: 58 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .release
Submodule .release added at 9be2b2
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
30 changes: 15 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -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);
}
Expand All @@ -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: [],
Expand All @@ -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...
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": "*"
}
}

0 comments on commit 95e0f9b

Please sign in to comment.