-
Notifications
You must be signed in to change notification settings - Fork 0
[mita2-general-log-filter] supported Change user command #5
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ def main(self): | |
| if query != "": | ||
| output = True | ||
|
|
||
| if '--user' in opts.keys() and not session_user[session_id] == opts['--user']: | ||
| if '--user' in opts.keys() and (session_id not in session_user or not session_user[session_id] == opts['--user']): | ||
| output = False | ||
|
|
||
| if '--command' in opts.keys() and cmd != opts['--command']: | ||
|
|
@@ -67,7 +67,7 @@ def main(self): | |
| else: | ||
| raise Exception('Unkown format %s' % line) | ||
|
|
||
| match = re.match(r' *([0-9]+) (\w+)', session_cmd) | ||
| match = re.match(r' *([0-9]+) (.+)$', session_cmd) | ||
| session_id = match.group(1) | ||
| cmd = match.group(2) | ||
|
|
||
|
|
@@ -76,6 +76,11 @@ def main(self): | |
| user = match.group(1) | ||
| session_user[session_id] = user | ||
|
|
||
| if cmd == 'Change user': | ||
| match = re.match(r'([^@]+)@[^@]+ on .+', query) | ||
| user = match.group(1) | ||
| session_user[session_id] = user | ||
|
Comment on lines
+79
to
+82
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. This block of code is nearly identical to the logic for the 'Connect' command on lines 74-77. This duplication can make the code harder to maintain. Furthermore, both this block and the 'Connect' block are susceptible to a crash. I recommend refactoring to remove the duplication and add the necessary safety check. Here's how you could combine and fix lines 74-82: if (cmd == 'Connect' and not re.match(r'Access denied for user', query)) or (cmd == 'Change user'):
match = re.match(r'([^@]+)@[^@]+ on .+', query)
if match:
user = match.group(1)
session_user[session_id] = user |
||
|
|
||
| else: | ||
| query = query + ' ' + line | ||
|
|
||
|
|
||
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.
While this change correctly fixes a potential
KeyError, the condition is a bit verbose. You can make this check more concise and Pythonic by usingdict.get().