This repository has been archived by the owner on Jun 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into FACT-2542
- Loading branch information
Showing
17 changed files
with
454 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
module Facter | ||
class OsHierarchy | ||
def initialize | ||
@log = Log.new(self) | ||
json_file = Util::FileHelper.safe_read('os_hierarchy.json') | ||
|
||
begin | ||
@json_os_hierarchy = JSON.parse(json_file) | ||
rescue JSON::ParserError => _e | ||
@log.error('Could not parse os_hierarchy json') | ||
end | ||
end | ||
|
||
def construct_hierarchy(searched_os) | ||
return [] if searched_os.nil? | ||
|
||
searched_os = searched_os.to_s.capitalize | ||
if @json_os_hierarchy.nil? | ||
@log.debug("There is no os_hierarchy, will fall back to: #{searched_os}") | ||
return [searched_os] | ||
end | ||
|
||
@searched_path = [] | ||
search(@json_os_hierarchy, searched_os, []) | ||
|
||
@searched_path.map { |os_name| os_name.to_s.capitalize } | ||
end | ||
|
||
private | ||
|
||
def search(json_data, searched_element, path) | ||
# we hit a dead end, the os was not found on this branch | ||
# and we cannot go deeper | ||
return unless json_data | ||
|
||
json_data.each do |tree_node| | ||
# we found the searched OS, so save the path from the tree | ||
@searched_path = path.dup << tree_node if tree_node == searched_element | ||
|
||
next unless tree_node.is_a?(Hash) | ||
|
||
tree_node.each do |k, v| | ||
return @searched_path = path.dup << k if k == searched_element | ||
|
||
search(v, searched_element, path << k) | ||
path.pop | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[ | ||
{ | ||
"Linux": [ | ||
{ | ||
"Debian": [ | ||
"Elementary", | ||
"Ubuntu", | ||
"Raspbian" | ||
] | ||
}, | ||
{ | ||
"El": [ | ||
"Fedora", | ||
"Amzn", | ||
"Centos" | ||
] | ||
}, | ||
{ | ||
"Sles": [ | ||
"Opensuse" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"Solaris": [ | ||
"Bsd" | ||
] | ||
}, | ||
"Macosx", | ||
"Windows", | ||
"Aix" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[ | ||
{ | ||
"Linux": [ | ||
"Debian": [ | ||
"Elementary", | ||
"Ubuntu", | ||
"Raspbian" | ||
] | ||
}, | ||
{ | ||
"El": [ | ||
"Fedora", | ||
"Amzn", | ||
"Centos" | ||
] | ||
}, | ||
{ | ||
"Sles": [ | ||
"Opensuse" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"Solaris": [ | ||
"Bsd" | ||
] | ||
}, | ||
"Macosx", | ||
"Windows", | ||
"Aix" | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
[ | ||
{ | ||
"Linux": [ | ||
{ | ||
"Debian": [ | ||
"Elementary", | ||
"Ubuntu", | ||
"Raspbian" | ||
] | ||
}, | ||
{ | ||
"El": [ | ||
"Fedora", | ||
"Amzn", | ||
"Centos" | ||
] | ||
}, | ||
{ | ||
"Sles": [ | ||
"Opensuse" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"Solaris": [ | ||
"Bsd" | ||
] | ||
}, | ||
"Macosx", | ||
"Windows", | ||
"Aix" | ||
] |
Oops, something went wrong.