From c0c61070067e5c7425e12b7f3942e9818295b48d Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Wed, 15 Jan 2025 17:01:11 +0000 Subject: [PATCH 1/3] DOC-4439 auth command examples --- doctests/cmds_cnxmgmt_test.go | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 doctests/cmds_cnxmgmt_test.go diff --git a/doctests/cmds_cnxmgmt_test.go b/doctests/cmds_cnxmgmt_test.go new file mode 100644 index 000000000..06c480f2b --- /dev/null +++ b/doctests/cmds_cnxmgmt_test.go @@ -0,0 +1,67 @@ +// EXAMPLE: cmds_cnxmgmt +// HIDE_START +package example_commands_test + +import ( + "context" + "fmt" + + "github.com/redis/go-redis/v9" +) + +// HIDE_END + +func ExampleClient_cmd_auth() { + ctx := context.Background() + + rdb := redis.NewClient(&redis.Options{ + Addr: "localhost:6379", + Password: "", // no password docs + DB: 0, // use default DB + }) + // REMOVE_START + + // REMOVE_END + // STEP_START auth1 + // REMOVE_START + rdb.ConfigSet(ctx, "requirepass", "temp_pass") + // REMOVE_END + authResult1, err := rdb.Conn().Auth(ctx, "temp_pass").Result() + + if err != nil { + panic(err) + } + + fmt.Println(authResult1) // >>> OK + + authResult2, err := rdb.Conn().AuthACL( + ctx, "default", "temp_pass", + ).Result() + + if err != nil { + panic(err) + } + + fmt.Println(authResult2) // >>> OK + // REMOVE_START + rdb.ConfigSet(ctx, "require_pass", "") + // REMOVE_END + // STEP_END + + // STEP_START auth2 + authResult3, err := rdb.Conn().AuthACL(ctx, + "test_user", "strong_password", + ).Result() + + if err != nil { + fmt.Println(err) + } + + fmt.Println(authResult3) // >>> OK + // STEP_END + + // Output: + // OK + // OK + // WRONGPASS invalid username-password pair or user is disabled. +} From 52278ecb6be7bc413f66f1c45ffb22db2a8a367d Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 7 Feb 2025 11:24:06 +0000 Subject: [PATCH 2/3] DOC-4439 tried ACL set/del commands --- doctests/cmds_cnxmgmt_test.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/doctests/cmds_cnxmgmt_test.go b/doctests/cmds_cnxmgmt_test.go index 06c480f2b..b5cdcb153 100644 --- a/doctests/cmds_cnxmgmt_test.go +++ b/doctests/cmds_cnxmgmt_test.go @@ -44,24 +44,32 @@ func ExampleClient_cmd_auth() { fmt.Println(authResult2) // >>> OK // REMOVE_START - rdb.ConfigSet(ctx, "require_pass", "") + confRes, err := rdb.ConfigSet(ctx, "requirepass", "").Result() + fmt.Println(confRes) // REMOVE_END // STEP_END // STEP_START auth2 + // REMOVE_START + res, err := rdb.ACLSetUser(ctx, "test-user", "on", ">strong_password", "+acl").Result() + fmt.Println(res) + // REMOVE_END authResult3, err := rdb.Conn().AuthACL(ctx, "test_user", "strong_password", ).Result() if err != nil { - fmt.Println(err) + panic(err) } fmt.Println(authResult3) // >>> OK + // REMOVE_START + rdb.ACLDelUser(ctx, "test-user") + // REMOVE_END // STEP_END // Output: // OK // OK - // WRONGPASS invalid username-password pair or user is disabled. + // OK } From 0e9b5dcdacc7b45decc3cf1e6323e74f1c90010d Mon Sep 17 00:00:00 2001 From: Andy Stark Date: Fri, 7 Feb 2025 11:35:56 +0000 Subject: [PATCH 3/3] DOC-4439 fixed password --- doctests/cmds_cnxmgmt_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doctests/cmds_cnxmgmt_test.go b/doctests/cmds_cnxmgmt_test.go index b5cdcb153..7e8facb82 100644 --- a/doctests/cmds_cnxmgmt_test.go +++ b/doctests/cmds_cnxmgmt_test.go @@ -55,7 +55,7 @@ func ExampleClient_cmd_auth() { fmt.Println(res) // REMOVE_END authResult3, err := rdb.Conn().AuthACL(ctx, - "test_user", "strong_password", + "test-user", "strong_password", ).Result() if err != nil {