blacklist sync
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-08-27 16:39:07 +02:00
parent e80e3f9a94
commit 31f739d4b8
15 changed files with 271 additions and 207 deletions

View File

@ -6,31 +6,44 @@
*/
import { debug } from '../debug';
import { redis } from '../Redis';
import { Redis } from '../Redis';
const logger = debug ('RedisBlacklistStore');
export class RedisBlacklistStore {
export class RedisBlacklistStore extends Redis {
public async add (key: string): Promise<void> {
const log = logger.extend ('set');
log ('trying to add key %s to redis blacklist', key);
if (!redis.is_active) {
if (!this.is_active) {
log ('redis is inactive, skipping');
return;
}
await redis.redis.sadd ('blacklist', key);
await this.redis.sadd ('blacklist', key);
log ('saved key');
}
public async remove (key: string): Promise<void> {
const log = logger.extend ('remove');
log ('removing key %s from redis', key);
if (!this.is_active) {
log ('redis is inactive, skipping');
return;
}
await this.redis.srem ('blacklist', key);
log ('removed key');
}
public async get (key: string): Promise<boolean> {
const log = logger.extend ('get');
log ('trying to find key %s in redis blacklist', key);
if (!redis.is_active) {
if (!this.is_active) {
log ('redis is inactive, skipping');
return false;
}
const res = await redis.redis.sismember ('blacklist', key) === 1;
const res = await this.redis.sismember ('blacklist', key) === 1;
log ('found key %s', res);
return res;
}
}
export const redis_blacklist_store = new RedisBlacklistStore;

View File

@ -7,15 +7,15 @@
import { debug } from '../debug';
import { LabelledKey } from '../Key';
import { redis } from '../Redis';
import { Redis } from '../Redis';
const logger = debug ('RedisKeyStore');
export class RedisKeyStore {
export class RedisKeyStore extends Redis {
public async set (value: LabelledKey): Promise<void> {
const log = logger.extend ('set');
log ('trying to set key %s to redis', value.index);
if (!redis.is_active) {
if (!this.is_active) {
log ('redis is inactive, skipping');
return;
}
@ -24,7 +24,7 @@ export class RedisKeyStore {
.getTime ()) / 1000
);
log ('key is valid for %d seconds', valid_for);
await redis.redis.setex (
await this.redis.setex (
`keystore_${value.index}`,
valid_for,
JSON.stringify (value)
@ -35,11 +35,11 @@ export class RedisKeyStore {
public async get (index: string): Promise<LabelledKey | null> {
const log = logger.extend ('get');
log ('trying to get key %s from redis', index);
if (!redis.is_active) {
if (!this.is_active) {
log ('redis is inactive, skipping');
return null;
}
const res = await redis.redis.get (`keystore_${index}`);
const res = await this.redis.get (`keystore_${index}`);
if (res === null) {
log ('key not found in redis');
return null;