-
Notifications
You must be signed in to change notification settings - Fork 90
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
Modify checksum logic to use system binaries #251
Conversation
6d61432
to
7dc6fa1
Compare
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.
I like the improvements,since it saves a lot of time to transfer data, but we need to think about worst cases, where those commands are not available.
lib/train/file.rb
Outdated
'digest -a md5' | ||
else | ||
'md5sum' | ||
end |
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.
I think we need to think about the case where those commands are not available. In those case I would like to fall back to the old methods
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.
Sounds good, added in last commit. Let me know what you think @chris-rock.
e8024d3
to
37b6108
Compare
We are getting closer @jerryaldrichiii !!! I am going to request one other round for improvement. At this point we are detecting platforms and available commands again and again. Why not keep our decision for one connection. Therefore we have many implementations of the hash generation eg.:
|
Sure does @chris-rock. Let me know if the recent commits achieve what you're looking for. |
8547322
to
0dcac56
Compare
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.
Awesome work @jerryaldrichiii I added some style comments, nothing major. 👍
lib/train/file.rb
Outdated
|
||
private | ||
|
||
def perform_checksum(method) |
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.
lets call this perform_checksum_cmd
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.
Technically you can call this method without setting the command before. I think we should either move the command detection into this method or assume it as an argument to minimize function side-effects.
lib/train/file.rb
Outdated
# This pulls the content of the file to the machine running Train and uses | ||
# Digest to perform the checksum. This is less efficient than using remote | ||
# system binaries and can lead to incorrect results due to encoding. | ||
def perform_ruby_checksum(method) |
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 this be called perform_checksum_ruby
to keep names aligned?
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.
Yup, I think that is fine. I've done a search and replace.
lib/train/file.rb
Outdated
res = @backend.run_command(cmd) | ||
return res.stdout.split(' ').first if res.exit_status == 0 | ||
|
||
perform_ruby_checksum(method) |
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.
I would return an error for that method instead of calling perform_ruby_checksum
here
lib/train/file.rb
Outdated
res = @backend.run_command(cmd) | ||
return res.stdout.split("\r\n")[1].tr(' ', '') if res.exit_status == 0 | ||
|
||
perform_ruby_checksum(method) |
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.
As above, I would not perform the ruby checksum here, but return an error
lib/train/file.rb
Outdated
end | ||
|
||
def sha256sum | ||
return perform_ruby_checksum(method) if defined?(@use_ruby_checksum) |
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.
I think method needs to be defined here
lib/train/file.rb
Outdated
@@ -147,5 +129,85 @@ def mounted? | |||
|
|||
!mounted.nil? && !mounted.stdout.nil? && !mounted.stdout.empty? | |||
end | |||
|
|||
def md5sum | |||
return perform_ruby_checksum(method) if defined?(@use_ruby_checksum) |
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 this be perform_checksum_ruby(:md5)
?
lib/train/file.rb
Outdated
|
||
return perform_checksum(:md5) unless @backend.os.family == 'windows' | ||
|
||
perform_checksum_windows(:md5) |
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.
I think this can be a bit more simple, something like:
method = :md5
if @hash_ruby_fallback
hash, err = perform_checksum_windows(method) if os.family == 'windows'
hash, err = perform_checksum_cmd(method) if os.family != 'windows'
if err == nil
return hash
end
end
@hash_ruby_fallback = true
return perform_checksum_ruby(method)
I took a different approach @chris-rock but the feedback was super valuable. Let me know if it is too divergent from what you had in mind. |
I fixed the merge conflicts via the GUI. No sure how I feel, but hey we squash any way. |
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.
Great improvement @jerryaldrichiii
lib/train/file.rb
Outdated
'sha256sum' | ||
end | ||
|
||
perform_checksum_linux(@sha256_command) |
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 this be perform_checksum_unix
?
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.
Can't see why not. I've fixed it.
…. mocking tests to match Signed-off-by: Vern Burton <[email protected]>
Signed-off-by: Vern Burton <[email protected]>
Signed-off-by: Jerry Aldrich <[email protected]>
This removes the tests related to using `md5sum` or `sha356sum` on a FIFO file. These tests were not working previously and I was unable to make them work after my changes. I suspect that it is not possible since a FIFO file must be open at both ends simultaneously before you can do any I/O operations on it. See: https://linux.die.net/man/3/mkfifo Signed-off-by: Jerry Aldrich <[email protected]>
Signed-off-by: Jerry Aldrich <[email protected]>
Signed-off-by: Jerry Aldrich <[email protected]>
Signed-off-by: Jerry Aldrich <[email protected]>
Signed-off-by: Jerry Aldrich <[email protected]>
Signed-off-by: Jerry Aldrich <[email protected]>
Signed-off-by: Jerry Aldrich <[email protected]>
Signed-off-by: Jerry Aldrich <[email protected]>
ec2620f
to
c5987b2
Compare
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.
Thanks @jerryaldrichiii
This is great. Thanks! |
This modifies
md5sum
/sha256sum
to use binaries on the target system vs Ruby on the machine running InSpec.This fixes #235
This closes #236
Many thanks to @tarcinil for the initial work on this! It is greatly appreciated!