Skip to content

Commit a88175a

Browse files
committed
add full option for acl whoami
1 parent 2c9db1a commit a88175a

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

src/acl.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -2910,9 +2910,18 @@ void aclCommand(client *c) {
29102910
}
29112911
}
29122912
raxStop(&ri);
2913-
} else if (!strcasecmp(sub, "whoami") && c->argc == 2) {
2913+
} else if (!strcasecmp(sub, "whoami") && (c->argc == 2 || c->argc == 3)) {
29142914
if (c->user != NULL) {
2915-
addReplyBulkCBuffer(c, c->user->name, sdslen(c->user->name));
2915+
if (c->argc == 3) {
2916+
sds config = sdsnew(c->user->name);
2917+
config = sdscatlen(config, " ", 1);
2918+
robj *descr = ACLDescribeUser(c->user);
2919+
config = sdscatsds(config, descr->ptr);
2920+
decrRefCount(descr);
2921+
addReplyBulkSds(c, config);
2922+
} else {
2923+
addReplyBulkCBuffer(c, c->user->name, sdslen(c->user->name));
2924+
}
29162925
} else {
29172926
addReplyNull(c);
29182927
}

src/commands.def

+9-2
Original file line numberDiff line numberDiff line change
@@ -6380,7 +6380,9 @@ struct COMMAND_ARG ACL_SETUSER_Args[] = {
63806380

63816381
#ifndef SKIP_CMD_HISTORY_TABLE
63826382
/* ACL WHOAMI history */
6383-
#define ACL_WHOAMI_History NULL
6383+
commandHistory ACL_WHOAMI_History[] = {
6384+
{"9.0.0","Added the `FULL` option."},
6385+
};
63846386
#endif
63856387

63866388
#ifndef SKIP_CMD_TIPS_TABLE
@@ -6393,6 +6395,11 @@ struct COMMAND_ARG ACL_SETUSER_Args[] = {
63936395
#define ACL_WHOAMI_Keyspecs NULL
63946396
#endif
63956397

6398+
/* ACL WHOAMI argument table */
6399+
struct COMMAND_ARG ACL_WHOAMI_Args[] = {
6400+
{MAKE_ARG("full",ARG_TYPE_PURE_TOKEN,-1,"FULL",NULL,"9.0.0",CMD_ARG_OPTIONAL,0,NULL)},
6401+
};
6402+
63966403
/* ACL command table */
63976404
struct COMMAND_STRUCT ACL_Subcommands[] = {
63986405
{MAKE_CMD("cat","Lists the ACL categories, or the commands inside a category.","O(1) since the categories and commands are a fixed set.","6.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,ACL_CAT_History,0,ACL_CAT_Tips,0,aclCommand,-2,CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_SENTINEL,0,ACL_CAT_Keyspecs,0,NULL,1),.args=ACL_CAT_Args},
@@ -6407,7 +6414,7 @@ struct COMMAND_STRUCT ACL_Subcommands[] = {
64076414
{MAKE_CMD("save","Saves the effective ACL rules in the configured ACL file.","O(N). Where N is the number of configured users.","6.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,ACL_SAVE_History,0,ACL_SAVE_Tips,2,aclCommand,2,CMD_ADMIN|CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_SENTINEL,0,ACL_SAVE_Keyspecs,0,NULL,0)},
64086415
{MAKE_CMD("setuser","Creates and modifies an ACL user and its rules.","O(N). Where N is the number of rules provided.","6.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,ACL_SETUSER_History,2,ACL_SETUSER_Tips,2,aclCommand,-3,CMD_ADMIN|CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_SENTINEL,0,ACL_SETUSER_Keyspecs,0,NULL,2),.args=ACL_SETUSER_Args},
64096416
{MAKE_CMD("users","Lists all ACL users.","O(N). Where N is the number of configured users.","6.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,ACL_USERS_History,0,ACL_USERS_Tips,0,aclCommand,2,CMD_ADMIN|CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_SENTINEL,0,ACL_USERS_Keyspecs,0,NULL,0)},
6410-
{MAKE_CMD("whoami","Returns the authenticated username of the current connection.","O(1)","6.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,ACL_WHOAMI_History,0,ACL_WHOAMI_Tips,0,aclCommand,2,CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_SENTINEL,0,ACL_WHOAMI_Keyspecs,0,NULL,0)},
6417+
{MAKE_CMD("whoami","Returns the authenticated username of the current connection or its effective rules in ACL file format.","O(1)","6.0.0",CMD_DOC_NONE,NULL,NULL,"server",COMMAND_GROUP_SERVER,ACL_WHOAMI_History,1,ACL_WHOAMI_Tips,0,aclCommand,-2,CMD_NOSCRIPT|CMD_LOADING|CMD_STALE|CMD_SENTINEL,0,ACL_WHOAMI_Keyspecs,0,NULL,1),.args=ACL_WHOAMI_Args},
64116418
{0}
64126419
};
64136420

src/commands/acl-whoami.json

+19-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
{
22
"WHOAMI": {
3-
"summary": "Returns the authenticated username of the current connection.",
3+
"summary": "Returns the authenticated username of the current connection or its effective rules in ACL file format.",
44
"complexity": "O(1)",
55
"group": "server",
66
"since": "6.0.0",
7-
"arity": 2,
7+
"arity": -2,
88
"container": "ACL",
99
"function": "aclCommand",
10+
"history": [
11+
[
12+
"9.0.0",
13+
"Added the `FULL` option."
14+
]
15+
],
1016
"command_flags": [
1117
"NOSCRIPT",
1218
"LOADING",
@@ -16,6 +22,16 @@
1622
"reply_schema": {
1723
"type": "string",
1824
"description": "The username of the current connection."
19-
}
25+
},
26+
"arguments": [
27+
{
28+
"name": "full",
29+
"type": "pure-token",
30+
"token": "FULL",
31+
"optional": true,
32+
"since": "9.0.0"
33+
}
34+
]
35+
2036
}
2137
}

tests/unit/acl.tcl

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ start_server {tags {"acl external:skip"}} {
33
r ACL WHOAMI
44
} {default}
55

6+
test {Connections with the effective ACL rules of the default user} {
7+
r ACL WHOAMI FULL
8+
} {*default on nopass*}
9+
610
test {It is possible to create new users} {
711
r ACL setuser newuser
812
}

0 commit comments

Comments
 (0)