-
Notifications
You must be signed in to change notification settings - Fork 409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat auth supported for clients #111
Open
gutan
wants to merge
3
commits into
bilibili:master
Choose a base branch
from
gutan:feat_auth_supported_for_clients
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
[[clusters]] | ||
# This be used to specify the name of cache cluster. | ||
name = "test-redis" | ||
# The name of the hash function. Possible values are: sha1. | ||
hash_method = "fnv1a_64" | ||
# The key distribution mode. Possible values are: ketama. | ||
hash_distribution = "ketama" | ||
# A two character string that specifies the part of the key used for hashing. Eg "{}". | ||
hash_tag = "" | ||
# cache type: memcache | memcache_binary | redis | redis_cluster | ||
cache_type = "redis" | ||
# proxy listen proto: tcp | unix | ||
listen_proto = "tcp" | ||
# proxy listen addr: tcp addr | unix sock path | ||
listen_addr = "0.0.0.0:26379" | ||
# Authenticate to the Redis server on connect. | ||
redis_auth = "" | ||
# The dial timeout value in msec that we wait for to establish a connection to the server. By default, we wait indefinitely. | ||
dial_timeout = 1000 | ||
# The read timeout value in msec that we wait for to receive a response from a server. By default, we wait indefinitely. | ||
read_timeout = 1000 | ||
# The write timeout value in msec that we wait for to write a response to a server. By default, we wait indefinitely. | ||
write_timeout = 1000 | ||
# The number of connections that can be opened to each server. By default, we open at most 1 server connection. | ||
node_connections = 2 | ||
# The number of consecutive failures on a server that would lead to it being temporarily ejected when auto_eject is set to true. Defaults to 3. | ||
ping_fail_limit = 3 | ||
# A boolean value that controls if server should be ejected temporarily when it fails consecutively ping_fail_limit times. | ||
ping_auto_eject = false | ||
|
||
slowlog_slower_than = 10 | ||
# A list of server address, port and weight (name:port:weight or ip:port:weight) for this server pool. Also you can use alias name like: ip:port:weight alias. | ||
servers = [ | ||
"127.0.0.1:6379:1 redis1", | ||
] | ||
# Clients need to AUTH <PASSWORD> before processing any other commands. | ||
password = "111" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ var ( | |
cmdEvalBytes = []byte("4\r\nEVAL") | ||
cmdQuitBytes = []byte("4\r\nQUIT") | ||
cmdPingBytes = []byte("4\r\nPING") | ||
cmdAuthBytes = []byte("4\r\nAUTH") | ||
cmdMSetBytes = []byte("4\r\nMSET") | ||
cmdMGetBytes = []byte("4\r\nMGET") | ||
cmdGetBytes = []byte("3\r\nGET") | ||
|
@@ -168,6 +169,13 @@ func (r *Request) IsSupport() bool { | |
return ok | ||
} | ||
|
||
func (r *Request) IsAuth() bool { | ||
if r.IsCtl() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return bytes.Equal(r.resp.array[0].data, cmdAuthBytes) | ||
} | ||
return false | ||
} | ||
|
||
// IsCtl is control command. | ||
// | ||
// NOTE: use string([]byte) as a map key, it is very specific!!! | ||
|
@@ -307,13 +315,13 @@ var ( | |
"5\r\nPFADD", | ||
"7\r\nPFMERGE", | ||
"4\r\nEVAL", | ||
"11\r\nSUNIONSTORE", | ||
"11\r\nZUNIONSTORE", | ||
} | ||
notSupportCmds = []string{ | ||
"6\r\nMSETNX", | ||
"10\r\nSDIFFSTORE", | ||
"11\r\nSINTERSTORE", | ||
"11\r\nSUNIONSTORE", | ||
"11\r\nZUNIONSTORE", | ||
"5\r\nBLPOP", | ||
"5\r\nBRPOP", | ||
"10\r\nBRPOPLPUSH", | ||
|
@@ -328,7 +336,6 @@ var ( | |
"4\r\nWAIT", | ||
"5\r\nBITOP", | ||
"7\r\nEVALSHA", | ||
"4\r\nAUTH", | ||
"4\r\nECHO", | ||
"4\r\nINFO", | ||
"5\r\nPROXY", | ||
|
@@ -341,5 +348,6 @@ var ( | |
controlCmds = []string{ | ||
"4\r\nQUIT", | ||
"4\r\nPING", | ||
"4\r\nAUTH", | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not forward any command when
pc.authorized
is false. And so that authorized should be atomic flag or guard by mutex (be used by encoder/decoder together).