Module API for getting user name of a client (#8508)
Adding RM_GetClientUserNameById to get the ACL user name of a client connection.
This commit is contained in:
parent
f24d4002c0
commit
956949e7a1
23
src/module.c
23
src/module.c
@ -1837,6 +1837,28 @@ unsigned long long RM_GetClientId(RedisModuleCtx *ctx) {
|
|||||||
return ctx->client->id;
|
return ctx->client->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Return the ACL user name used by the client with the specified client ID.
|
||||||
|
* Client ID can be obtained with RM_GetClientId() API. If the client does not
|
||||||
|
* exist, NULL is returned and errno is set to ENOENT. If the client isn't
|
||||||
|
* using an ACL user, NULL is returned and errno is set to ENOTSUP */
|
||||||
|
RedisModuleString *RM_GetClientUserNameById(RedisModuleCtx *ctx, uint64_t id) {
|
||||||
|
client *client = lookupClientByID(id);
|
||||||
|
if (client == NULL) {
|
||||||
|
errno = ENOENT;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client->user == NULL) {
|
||||||
|
errno = ENOTSUP;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
sds name = sdsnew(client->user->name);
|
||||||
|
robj *str = createObject(OBJ_STRING, name);
|
||||||
|
autoMemoryAdd(ctx, REDISMODULE_AM_STRING, str);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
/* This is an helper for RM_GetClientInfoById() and other functions: given
|
/* This is an helper for RM_GetClientInfoById() and other functions: given
|
||||||
* a client, it populates the client info structure with the appropriate
|
* a client, it populates the client info structure with the appropriate
|
||||||
* fields depending on the version provided. If the version is not valid
|
* fields depending on the version provided. If the version is not valid
|
||||||
@ -9157,6 +9179,7 @@ void moduleRegisterCoreAPI(void) {
|
|||||||
REGISTER_API(IsKeysPositionRequest);
|
REGISTER_API(IsKeysPositionRequest);
|
||||||
REGISTER_API(KeyAtPos);
|
REGISTER_API(KeyAtPos);
|
||||||
REGISTER_API(GetClientId);
|
REGISTER_API(GetClientId);
|
||||||
|
REGISTER_API(GetClientUserNameById);
|
||||||
REGISTER_API(GetContextFlags);
|
REGISTER_API(GetContextFlags);
|
||||||
REGISTER_API(AvoidReplicaTraffic);
|
REGISTER_API(AvoidReplicaTraffic);
|
||||||
REGISTER_API(PoolAlloc);
|
REGISTER_API(PoolAlloc);
|
||||||
|
@ -665,6 +665,7 @@ REDISMODULE_API long long (*RedisModule_StreamTrimByID)(RedisModuleKey *key, int
|
|||||||
REDISMODULE_API int (*RedisModule_IsKeysPositionRequest)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
|
REDISMODULE_API int (*RedisModule_IsKeysPositionRequest)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
|
||||||
REDISMODULE_API void (*RedisModule_KeyAtPos)(RedisModuleCtx *ctx, int pos) REDISMODULE_ATTR;
|
REDISMODULE_API void (*RedisModule_KeyAtPos)(RedisModuleCtx *ctx, int pos) REDISMODULE_ATTR;
|
||||||
REDISMODULE_API unsigned long long (*RedisModule_GetClientId)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
|
REDISMODULE_API unsigned long long (*RedisModule_GetClientId)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
|
||||||
|
REDISMODULE_API RedisModuleString * (*RedisModule_GetClientUserNameById)(RedisModuleCtx *ctx, uint64_t id) REDISMODULE_ATTR;
|
||||||
REDISMODULE_API int (*RedisModule_GetClientInfoById)(void *ci, uint64_t id) REDISMODULE_ATTR;
|
REDISMODULE_API int (*RedisModule_GetClientInfoById)(void *ci, uint64_t id) REDISMODULE_ATTR;
|
||||||
REDISMODULE_API int (*RedisModule_PublishMessage)(RedisModuleCtx *ctx, RedisModuleString *channel, RedisModuleString *message) REDISMODULE_ATTR;
|
REDISMODULE_API int (*RedisModule_PublishMessage)(RedisModuleCtx *ctx, RedisModuleString *channel, RedisModuleString *message) REDISMODULE_ATTR;
|
||||||
REDISMODULE_API int (*RedisModule_GetContextFlags)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
|
REDISMODULE_API int (*RedisModule_GetContextFlags)(RedisModuleCtx *ctx) REDISMODULE_ATTR;
|
||||||
@ -936,6 +937,7 @@ static int RedisModule_Init(RedisModuleCtx *ctx, const char *name, int ver, int
|
|||||||
REDISMODULE_GET_API(IsKeysPositionRequest);
|
REDISMODULE_GET_API(IsKeysPositionRequest);
|
||||||
REDISMODULE_GET_API(KeyAtPos);
|
REDISMODULE_GET_API(KeyAtPos);
|
||||||
REDISMODULE_GET_API(GetClientId);
|
REDISMODULE_GET_API(GetClientId);
|
||||||
|
REDISMODULE_GET_API(GetClientUserNameById);
|
||||||
REDISMODULE_GET_API(GetContextFlags);
|
REDISMODULE_GET_API(GetContextFlags);
|
||||||
REDISMODULE_GET_API(AvoidReplicaTraffic);
|
REDISMODULE_GET_API(AvoidReplicaTraffic);
|
||||||
REDISMODULE_GET_API(PoolAlloc);
|
REDISMODULE_GET_API(PoolAlloc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user