Skip to content

Commit

Permalink
Add secrets created statistics (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjarneo committed Oct 1, 2021
1 parent dff2729 commit e949347
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"aws-sdk": "^2.935.0",
"bcrypt": "^5.0.1",
"config": "^3.3.6",
"dayjs": "^1.10.7",
"email-validator": "^2.0.4",
"fastify": "^3.17.0",
"fastify-cors": "^6.0.1",
Expand Down
14 changes: 14 additions & 0 deletions src/server/services/redis.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const config = require('config');
const asyncRedis = require('async-redis');
const dayjs = require('dayjs');
const { nanoid } = require('nanoid');

const isValidTTL = require('../helpers/validate-ttl');
Expand Down Expand Up @@ -41,6 +42,8 @@ function createSecret(data, ttl) {
prepare.push(...['file', JSON.stringify(data.file)]);
}

createStatistics('secrets_created');

client
.multi()
.hmset(prepare)
Expand Down Expand Up @@ -124,6 +127,16 @@ async function createRateLimit(ip) {
return false;
}

async function createStatistics(type = '') {
const types = ['secrets_created'];

if (types.indexOf(type) === -1) {
console.log(` [*] Type "${type}" not supported`);
}

return await client.incr(`statistics:${type}:${dayjs().format('YYYY-MM-DD')}`);
}

module.exports = {
createSecret,
getSecret,
Expand All @@ -134,4 +147,5 @@ module.exports = {
getUser,
deleteUser,
createRateLimit,
createStatistics,
};

0 comments on commit e949347

Please sign in to comment.