-
Notifications
You must be signed in to change notification settings - Fork 218
perf: ssh command acl accept #1952
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
Conversation
| } | ||
| } | ||
|
|
||
| host, _, _ := net.SplitHostPort(sess.RemoteAddr().String()) |
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.
The code seems to be free from any major issues. However, there is an opportunity for further optimization in function name "proxyAssetCommand". This command appears unrelated with other commands like assetCommandForTokenInfo that follow this method's signature.
Additionally:
- The current version uses a loop and comparison to decide whether an ACL matches based on the Action field of a TokenInfo object. As such, it could be more efficient/performant if the matching logic was moved into a function where input data can be passed as a reference instead. For example:
var match = func(ti *model.TokenInfos) bool {
return ti.FilterACLs[ac] // Use slice indexing here
}
This will also improve readability due to clear implementation details when calling it inside another function.
Here are some brief points:
1. Naming convention should be followed (lowercase).
2. Consider move the conditional statement out of loop so efficiency improves.
3. Add appropriate comments around functions and sections, especially those parts needing extra explanation which might be difficult to understand otherwise.
Please let me know if you need help with anything else!
1984bcc to
674669a
Compare
| } | ||
| } | ||
|
|
||
| host, _, _ := net.SplitHostPort(sess.RemoteAddr().String()) |
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.
There are no immediate issues with this code snippet; it currently appears free of syntax, spelling, or formatting errors. However, one could consider improving the readability:
func proxyAssetCommand(sess ssh.Session, sshClient *srvconn.SSHClient, rawStr string) error {
// todo: support ACL command filter
// parse raw string to action (execute/rollback)
var action, err = ParseAction(rawStr)
if err != nil {
return err
}
// validate input data
if !IsValidAction(action) {
return fmt.Errorf("action must be 'execute' or 'rollback'")
}
// handle different actions based on action type
switch action {
case "execute":
// implement execution logic here
default:
break
}
return nil
}This modification enhances the readability of the function by using variables named action and err, which helps in identifying parts of the code that can potentially lead to runtime exceptions when parsing the raw string.
For future enhancement, consider adding docstrings around more complex sections of the functions like handling different types of acls.
+ "model.CommandACLs(acls)",And document variable names appropriately.
Note that these modifications assume basic understanding of Go programming principles such as best practices for naming variables and avoiding unnecessary complexity within conditional blocks.
The code is mostly correct until line 415 where there would need additional documentation explaining parse raw string to action. After reading through the rest of your code I didn't find other major discrepancies, so the current implementation does not appear flawed per se but if you have specific areas of concern please clarify them further.
|



perf: ssh command acl accept