-
Notifications
You must be signed in to change notification settings - Fork 63
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
Gracefully fall back to other strategies when MAC address cannot be determined #55
base: main
Are you sure you want to change the base?
Conversation
@@ -213,7 +213,8 @@ def pending_if_root_required | |||
:openbsd => openbsd_sample, | |||
:linux => linux_sample, | |||
:linux2 => linux_sample_2, | |||
:linuxip => linux_ip_sample | |||
:linuxip => linux_ip_sample, | |||
:docker => nil |
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.
Style/HashSyntax: Use the new Ruby 1.9 hash syntax.
@@ -213,7 +213,8 @@ def pending_if_root_required | |||
:openbsd => openbsd_sample, | |||
:linux => linux_sample, | |||
:linux2 => linux_sample_2, | |||
:linuxip => linux_ip_sample | |||
:linuxip => linux_ip_sample, |
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.
Style/HashSyntax: Use the new Ruby 1.9 hash syntax.
@@mac_address = UUID.first_mac(UUID.ifconfig(:all)) | ||
elsif ifconfig_output=UUID.ifconfig(:all) | ||
# linux, bsd, macos, solaris | ||
@@mac_address = UUID.first_mac ifconfig_output |
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.
Style/ClassVars: Replace class var @@mac_address with a class instance var.
@@ -688,8 +686,9 @@ def self.mac_address | |||
@@mac_address = UUID.first_mac `ipconfig /all` | |||
rescue | |||
end | |||
else # linux, bsd, macos, solaris | |||
@@mac_address = UUID.first_mac(UUID.ifconfig(:all)) | |||
elsif ifconfig_output=UUID.ifconfig(:all) |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator =.
@@ -679,6 +676,7 @@ def self.first_mac(instring) | |||
# Returns nil if a MAC address could not be found. | |||
def self.mac_address | |||
if !defined?(@@mac_address) | |||
@@mac_address = nil |
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.
Style/ClassVars: Replace class var @@mac_address with a class instance var.
command = | ||
if ifconfig_path=UUID.ifconfig_path | ||
"#{ifconfig_path}#{all ? " -a" : ""}" | ||
elsif ip_path=UUID.ip_path |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator =.
return `#{ifconfig_path} #{all_switch}` if not ifconfig_path == nil | ||
command = | ||
if ifconfig_path=UUID.ifconfig_path | ||
"#{ifconfig_path}#{all ? " -a" : ""}" |
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.
Style/StringLiteralsInInterpolation: Prefer single-quoted strings inside interpolations.
all_switch = all == nil ? "" : "-a" | ||
return `#{ifconfig_path} #{all_switch}` if not ifconfig_path == nil | ||
command = | ||
if ifconfig_path=UUID.ifconfig_path |
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.
Layout/SpaceAroundOperators: Surrounding space missing for operator =.
Often in containerized *nix environments, neither
ip
norifconfig
will be present, which means that in these environments, the MAC address cannot be determined. In such a scenario, certain strategies would fail to generate a UUID.This change makes the code fall back to other strategies without raising errors when the MAC address cannot be determined.
Fixes #53