@lucaapp/service-utils 5.22.0 → 5.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { IsOperatorTokenRevokedParams, IsRevokedOperatorJwtParams, RevokeOperatorTokensParams } from './types';
|
|
1
|
+
import { CheckRevocationRedisSafetyParams, IsOperatorTokenRevokedParams, IsRevokedOperatorJwtParams, RevokeOperatorTokensParams } from './types';
|
|
2
2
|
export declare const OPERATOR_REVOCATION_KEY_PREFIX = "revoked:operator:";
|
|
3
3
|
export declare const OPERATOR_REVOCATION_TTL_SECONDS: number;
|
|
4
4
|
export declare const buildOperatorRevocationKey: (operatorUuid: string) => string;
|
|
5
5
|
export declare const revokeOperatorTokens: ({ redis, logger, operatorUuid, }: RevokeOperatorTokensParams) => Promise<void>;
|
|
6
6
|
export declare const isOperatorTokenRevoked: ({ redis, logger, operatorUuid, issuedAtSeconds, }: IsOperatorTokenRevokedParams) => Promise<boolean>;
|
|
7
7
|
export declare const isRevokedOperatorJwt: ({ redis, logger, payload, operatorRole, }: IsRevokedOperatorJwtParams) => Promise<boolean>;
|
|
8
|
+
export declare const checkRevocationRedisSafety: ({ redis, logger, }: CheckRevocationRedisSafetyParams) => Promise<void>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isRevokedOperatorJwt = exports.isOperatorTokenRevoked = exports.revokeOperatorTokens = exports.buildOperatorRevocationKey = exports.OPERATOR_REVOCATION_TTL_SECONDS = exports.OPERATOR_REVOCATION_KEY_PREFIX = void 0;
|
|
3
|
+
exports.checkRevocationRedisSafety = exports.isRevokedOperatorJwt = exports.isOperatorTokenRevoked = exports.revokeOperatorTokens = exports.buildOperatorRevocationKey = exports.OPERATOR_REVOCATION_TTL_SECONDS = exports.OPERATOR_REVOCATION_KEY_PREFIX = void 0;
|
|
4
4
|
exports.OPERATOR_REVOCATION_KEY_PREFIX = 'revoked:operator:';
|
|
5
5
|
exports.OPERATOR_REVOCATION_TTL_SECONDS = 24 * 60 * 60;
|
|
6
6
|
const REDIS_GET_TIMEOUT_MS = 50;
|
|
@@ -68,3 +68,25 @@ const isRevokedOperatorJwt = async ({ redis, logger, payload, operatorRole, }) =
|
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
70
|
exports.isRevokedOperatorJwt = isRevokedOperatorJwt;
|
|
71
|
+
const readMaxMemoryPolicy = (raw) => {
|
|
72
|
+
if (Array.isArray(raw) && raw.length >= 2 && typeof raw[1] === 'string') {
|
|
73
|
+
return raw[1];
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
const checkRevocationRedisSafety = async ({ redis, logger, }) => {
|
|
78
|
+
try {
|
|
79
|
+
const policy = readMaxMemoryPolicy(await redis.config('GET', 'maxmemory-policy'));
|
|
80
|
+
if (policy === null) {
|
|
81
|
+
logger.warn('could not read operator token revocation redis maxmemory-policy');
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (policy !== 'noeviction') {
|
|
85
|
+
logger.error({ policy }, 'operator token revocation redis uses evicting maxmemory-policy');
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
logger.warn(error, 'operator token revocation redis maxmemory-policy check unavailable');
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
exports.checkRevocationRedisSafety = checkRevocationRedisSafety;
|
|
@@ -25,3 +25,10 @@ export interface IsRevokedOperatorJwtParams {
|
|
|
25
25
|
payload: RevocableJwtPayload;
|
|
26
26
|
operatorRole: string;
|
|
27
27
|
}
|
|
28
|
+
export interface MaxMemoryPolicyReader {
|
|
29
|
+
config(subcommand: 'GET', parameter: string): Promise<unknown>;
|
|
30
|
+
}
|
|
31
|
+
export interface CheckRevocationRedisSafetyParams {
|
|
32
|
+
redis: MaxMemoryPolicyReader;
|
|
33
|
+
logger: Pick<Logger, 'warn' | 'error'>;
|
|
34
|
+
}
|