Skip to content

Commit

Permalink
Merge pull request #2697 from jonathannewman/maint/main/fix-nil-defer…
Browse files Browse the repository at this point in the history
…ences

(bug) ensure avoid nil dereference
  • Loading branch information
joshcooper authored Apr 1, 2024
2 parents 7bfd75b + bc7a09e commit 8b77e6f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/facter/facts/linux/cloud/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ class Provider
def call_the_resolver
provider = case Facter::Util::Facts::Posix::VirtualDetector.platform
when 'hyperv'
'azure' unless Facter::Resolvers::Az.resolve(:metadata).empty?
metadata = Facter::Resolvers::Az.resolve(:metadata)
'azure' unless metadata.nil? || metadata.empty?
when 'kvm', 'xen'
'aws' unless Facter::Resolvers::Ec2.resolve(:metadata).empty?
metadata = Facter::Resolvers::Ec2.resolve(:metadata)
'aws' unless metadata.nil? || metadata.empty?
when 'gce'
'gce' unless Facter::Resolvers::Gce.resolve(:metadata).empty?
metadata = Facter::Resolvers::Gce.resolve(:metadata)
'gce' unless metadata.nil? || metadata.empty?
end

Facter::ResolvedFact.new(FACT_NAME, provider)
Expand Down
9 changes: 6 additions & 3 deletions lib/facter/facts/windows/cloud/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ def call_the_resolver
virtual = Facter::Resolvers::Windows::Virtualization.resolve(:virtual)
provider = case virtual
when 'hyperv'
'azure' unless Facter::Resolvers::Az.resolve(:metadata).empty?
metadata = Facter::Resolvers::Az.resolve(:metadata)
'azure' unless metadata.nil? || metadata.empty?
when 'kvm', 'xen'
'aws' unless Facter::Resolvers::Ec2.resolve(:metadata).empty?
metadata = Facter::Resolvers::Ec2.resolve(:metadata)
'aws' unless metadata.nil? || metadata.empty?
when 'gce'
'gce' unless Facter::Resolvers::Gce.resolve(:metadata).empty?
metadata = Facter::Resolvers::Gce.resolve(:metadata)
'gce' unless metadata.nil? || metadata.empty?
end

Facter::ResolvedFact.new(FACT_NAME, provider)
Expand Down

0 comments on commit 8b77e6f

Please sign in to comment.