diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20854ea..ec750da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,7 +31,7 @@ jobs: sudo sysctl -w vm.max_map_count=262144 - uses: elastic/elastic-github-actions/elasticsearch@master with: - stack-version: 7.17.0 + stack-version: 8.8.0 security-enabled: false - uses: actions/checkout@v3 - uses: actions/setup-node@v3 diff --git a/Changes.md b/Changes.md index 7f19c25..1fdf939 100644 --- a/Changes.md +++ b/Changes.md @@ -1,6 +1,19 @@ ### Unreleased +### [8.0.0] - 2023-06-NN + +- dep(elastic): bump dep version to 8.8 +- + + +### [7.0.0] - 2023-06-08 + +- chore: update ci & packaging +- dep(elastic): bump dep version to 7.17 +- bump major version to match ES major version + + ### [1.1.0] - 2023-06-08 - dep(elastic): dump dep version to 8.8 @@ -64,3 +77,5 @@ [1.0.7]: https://github.com/haraka/haraka-plugin-elasticsearch/releases/tag/1.0.7 [1.0.8]: https://github.com/haraka/haraka-plugin-elasticsearch/releases/tag/1.0.8 [1.1.0]: https://github.com/haraka/haraka-plugin-elasticsearch/releases/tag/1.1.0 +[7.0.0]: https://github.com/haraka/haraka-plugin-elasticsearch/releases/tag/7.0.0 +[8.0.0]: https://github.com/haraka/haraka-plugin-elasticsearch/releases/tag/8.0.0 diff --git a/index.js b/index.js index ff4e178..7fc6662 100644 --- a/index.js +++ b/index.js @@ -72,16 +72,17 @@ exports.es_connect = function (done) { plugin.es = new Elasticsearch.Client(plugin.clientArgs); - plugin.es.ping({}, function (error) { - if (error) { - plugin.logerror('cluster is down!'); - plugin.logerror(util.inspect(error, {depth: null})); - } - else { - plugin.lognotice('connected'); - } - if (done) done(error); - }); + plugin.es.ping() + .then(() => { + plugin.lognotice('connected') + }) + .catch(error => { + plugin.logerror('cluster is down!') + plugin.logerror(util.inspect(error, {depth: null})) + }) + .finally(() => { + if (done) done() + }) } exports.log_transaction = function (next, connection) { @@ -104,12 +105,13 @@ exports.log_transaction = function (next, connection) { type: 'haraka', id: connection.transaction.uuid, body: JSON.stringify(res), - }, (error, response) => { - if (error) { + }) + .then((response) => { + // connection.loginfo(plugin, response); + }) + .catch(error => { connection.logerror(plugin, error.message); - } - // connection.loginfo(plugin, response); - }); + }) // hook reset_transaction doesn't seem to wait for next(). If I // wait until after I get a response back from ES, Haraka throws @@ -144,13 +146,15 @@ exports.log_connection = function (next, connection) { type: 'haraka', id: connection.uuid, body: JSON.stringify(res), - }, function (error, response) { - if (error) { + }) + .then((response) => { + // connection.loginfo(plugin, response); + }) + .catch(error => { connection.logerror(plugin, error.message); - } - // connection.loginfo(plugin, response); - }); - next(); + }) + + next() } exports.objToArray = function (obj) { diff --git a/package.json b/package.json index 91e0cde..a37c0f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "haraka-plugin-elasticsearch", - "version": "7.0.0", + "version": "8.0.0", "description": "Haraka plugin that saves logs to Elasticsearch", "main": "index.js", "scripts": { @@ -25,7 +25,7 @@ }, "homepage": "https://github.com/haraka/haraka-plugin-elasticsearch#readme", "dependencies": { - "@elastic/elasticsearch": "^7.17.0", + "@elastic/elasticsearch": "^8.8.0", "haraka-utils": "*" }, "devDependencies": { diff --git a/test/index.js b/test/index.js index c4d04d6..cbe8105 100644 --- a/test/index.js +++ b/test/index.js @@ -215,10 +215,7 @@ describe('storesIndexMapTemplate', function () { plugin.es_connect((err) => { assert.ifError(err); - if (err) { - done() - return; - } + if (err) { done(); return; } fs.readFile(filePath, (err2, data) => { if (err2) { @@ -231,20 +228,18 @@ describe('storesIndexMapTemplate', function () { plugin.es.indices.putTemplate({ name: 'smtp-*', body: JSON.stringify(indexMap), - }, - function (err3, result) { - if (err3) { + }) + .then(result => { + console.log(result); + }) + .catch(err3 => { if (err3.status !== 404) { console.error(err3); } // other tests are running, so currently // stored mapping may conflict - done() - return; - } - console.log(result); - done() - }) + }) + .finally(done) }) }) })