fauxhai-chef 9.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +2 -0
  3. data/LICENSE +22 -0
  4. data/bin/fauxhai +23 -0
  5. data/fauxhai-chef.gemspec +28 -0
  6. data/lib/fauxhai/exception.rb +6 -0
  7. data/lib/fauxhai/fetcher.rb +80 -0
  8. data/lib/fauxhai/keys/id_dsa +12 -0
  9. data/lib/fauxhai/keys/id_dsa.pub +1 -0
  10. data/lib/fauxhai/keys/id_rsa +27 -0
  11. data/lib/fauxhai/keys/id_rsa.pub +1 -0
  12. data/lib/fauxhai/mocker.rb +143 -0
  13. data/lib/fauxhai/platforms/aix/7.1.json +1889 -0
  14. data/lib/fauxhai/platforms/aix/7.2.json +5289 -0
  15. data/lib/fauxhai/platforms/almalinux/8.json +5754 -0
  16. data/lib/fauxhai/platforms/amazon/2.json +4697 -0
  17. data/lib/fauxhai/platforms/amazon/2018.03.json +3525 -0
  18. data/lib/fauxhai/platforms/arch/4.10.13-1-ARCH.json +1669 -0
  19. data/lib/fauxhai/platforms/centos/6.10.json +2691 -0
  20. data/lib/fauxhai/platforms/centos/7.7.1908.json +3855 -0
  21. data/lib/fauxhai/platforms/centos/7.8.2003.json +3803 -0
  22. data/lib/fauxhai/platforms/centos/8.json +4715 -0
  23. data/lib/fauxhai/platforms/chefspec/0.6.1.json +20 -0
  24. data/lib/fauxhai/platforms/clearos/7.4.json +6130 -0
  25. data/lib/fauxhai/platforms/debian/10.json +2928 -0
  26. data/lib/fauxhai/platforms/debian/11.json +2744 -0
  27. data/lib/fauxhai/platforms/debian/9.11.json +2943 -0
  28. data/lib/fauxhai/platforms/debian/9.12.json +2942 -0
  29. data/lib/fauxhai/platforms/debian/9.13.json +2959 -0
  30. data/lib/fauxhai/platforms/dragonfly4/4.8-RELEASE.json +392 -0
  31. data/lib/fauxhai/platforms/fedora/31.json +3994 -0
  32. data/lib/fauxhai/platforms/fedora/32.json +3554 -0
  33. data/lib/fauxhai/platforms/freebsd/11.2.json +427 -0
  34. data/lib/fauxhai/platforms/freebsd/12.1.json +913 -0
  35. data/lib/fauxhai/platforms/gentoo/4.9.95-gentoo.json +989 -0
  36. data/lib/fauxhai/platforms/linuxmint/19.0.json +9649 -0
  37. data/lib/fauxhai/platforms/mac_os_x/10.14.json +1350 -0
  38. data/lib/fauxhai/platforms/mac_os_x/10.15.json +1510 -0
  39. data/lib/fauxhai/platforms/mac_os_x/11.0.json +2821 -0
  40. data/lib/fauxhai/platforms/mac_os_x/11.json +3356 -0
  41. data/lib/fauxhai/platforms/mac_os_x/12.json +3546 -0
  42. data/lib/fauxhai/platforms/openbsd/6.2.json +295 -0
  43. data/lib/fauxhai/platforms/opensuse/15.2.json +5967 -0
  44. data/lib/fauxhai/platforms/oracle/6.10.json +4349 -0
  45. data/lib/fauxhai/platforms/oracle/7.5.json +6576 -0
  46. data/lib/fauxhai/platforms/oracle/7.6.json +6591 -0
  47. data/lib/fauxhai/platforms/raspbian/10.json +3664 -0
  48. data/lib/fauxhai/platforms/redhat/6.10.json +5822 -0
  49. data/lib/fauxhai/platforms/redhat/7.7.json +3969 -0
  50. data/lib/fauxhai/platforms/redhat/7.8.json +3958 -0
  51. data/lib/fauxhai/platforms/redhat/7.9.json +3959 -0
  52. data/lib/fauxhai/platforms/redhat/8.json +4547 -0
  53. data/lib/fauxhai/platforms/rocky/8.json +5768 -0
  54. data/lib/fauxhai/platforms/smartos/5.11.json +1680 -0
  55. data/lib/fauxhai/platforms/solaris2/5.11.json +10290 -0
  56. data/lib/fauxhai/platforms/suse/12.4.json +5875 -0
  57. data/lib/fauxhai/platforms/suse/12.5.json +5012 -0
  58. data/lib/fauxhai/platforms/suse/15.json +6096 -0
  59. data/lib/fauxhai/platforms/ubuntu/16.04.json +3885 -0
  60. data/lib/fauxhai/platforms/ubuntu/18.04.json +4042 -0
  61. data/lib/fauxhai/platforms/ubuntu/20.04.json +4613 -0
  62. data/lib/fauxhai/platforms/windows/10.json +431 -0
  63. data/lib/fauxhai/platforms/windows/2012.json +404 -0
  64. data/lib/fauxhai/platforms/windows/2012R2.json +406 -0
  65. data/lib/fauxhai/platforms/windows/2016.json +408 -0
  66. data/lib/fauxhai/platforms/windows/2019.json +408 -0
  67. data/lib/fauxhai/platforms/windows/8.1.json +416 -0
  68. data/lib/fauxhai/runner/default.rb +284 -0
  69. data/lib/fauxhai/runner/windows.rb +101 -0
  70. data/lib/fauxhai/runner.rb +45 -0
  71. data/lib/fauxhai/version.rb +3 -0
  72. data/lib/fauxhai.rb +18 -0
  73. metadata +202 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 896ab0477428745f79a22d289f737627005f135db4ba96f3a6a76d0cfc35ae9f
4
+ data.tar.gz: b871054d36602a4ac4f0b13f719bd7fedd2386524ca957622fa38d57e188494f
5
+ SHA512:
6
+ metadata.gz: bacb0390cf12ecb08c65229817560e2fa36dd89827f0db65b9df01649d827a5f9932f8db925f4f5108fdeb890a8f1accf3bc156af62944f4d125a5022cf33942
7
+ data.tar.gz: 2b6764d05de53b65393c387165cf48d43e23fed98f75ba605c8720f4aad23e49de14f991689159a6e7366ee2c38132855dc472d4f3d230f89095c6505d8390b2
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Seth Vargo and CustomInk, LCC
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/fauxhai ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path(File.dirname(__FILE__) + "../../lib")
4
+ $LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
5
+
6
+ args = ARGV.dup
7
+ ARGV.clear
8
+
9
+ unless (args & ["-v", "--version"]).empty?
10
+ require "fauxhai/version"
11
+ puts Fauxhai::VERSION
12
+ exit(0)
13
+ end
14
+
15
+ unless (args & ["-h", "--help"]).empty?
16
+ puts "Usage: fauxhai"
17
+ puts "(There are no flags or options)"
18
+ exit(0)
19
+ end
20
+
21
+ require "fauxhai"
22
+ require "fauxhai/runner"
23
+ Fauxhai::Runner.new(args)
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $:.unshift(lib) unless $:.include?(lib)
3
+ require "fauxhai/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "fauxhai-chef"
7
+ spec.version = Fauxhai::VERSION
8
+ spec.authors = ["Seth Vargo", "Tim Smith"]
9
+ spec.email = ["sethvargo@gmail.com", "tsmith84@gmail.com"]
10
+ spec.description = "Easily mock out ohai data"
11
+ spec.summary = "Fauxhai provides an easy way to mock out your ohai data for testing with chefspec!"
12
+ spec.homepage = "https://github.com/chef/fauxhai"
13
+ spec.license = "MIT"
14
+
15
+ spec.required_ruby_version = ">= 2.7"
16
+
17
+ spec.files = %w{LICENSE Gemfile fauxhai-chef.gemspec} + Dir.glob("{lib,bin}/**/*", File::FNM_DOTMATCH).reject { |f| File.directory?(f) }
18
+ spec.executables = "fauxhai"
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "net-ssh"
22
+
23
+ spec.add_development_dependency "chef", ">= 13.0"
24
+ spec.add_development_dependency "ohai", ">= 13.0"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec", "~> 3.7"
27
+ spec.add_development_dependency "rspec-its", "~> 1.2"
28
+ end
@@ -0,0 +1,6 @@
1
+ module Fauxhai
2
+ module Exception
3
+ class InvalidPlatform < ArgumentError; end
4
+ class InvalidVersion < ArgumentError; end
5
+ end
6
+ end
@@ -0,0 +1,80 @@
1
+ require "digest/sha1"
2
+ require "json" unless defined?(JSON)
3
+
4
+ module Fauxhai
5
+ class Fetcher
6
+ def initialize(options = {}, &override_attributes)
7
+ @options = options
8
+
9
+ if !force_cache_miss? && cached?
10
+ @data = cache
11
+ else
12
+ require "net/ssh" unless defined?(Net::SSH)
13
+ Net::SSH.start(host, user, @options) do |ssh|
14
+ @data = JSON.parse(ssh.exec!("ohai"))
15
+ end
16
+
17
+ # cache this data so we do not have to SSH again
18
+ File.open(cache_file, "w+") { |f| f.write(@data.to_json) }
19
+ end
20
+
21
+ yield(@data) if block_given?
22
+
23
+ if defined?(ChefSpec)
24
+ data = @data
25
+ ::ChefSpec::Runner.send :define_method, :fake_ohai do |ohai|
26
+ data.each_pair do |attribute, value|
27
+ ohai[attribute] = value
28
+ end
29
+ end
30
+ end
31
+
32
+ @data
33
+ end
34
+
35
+ def cache
36
+ @cache ||= JSON.parse(File.read(cache_file))
37
+ end
38
+
39
+ def cached?
40
+ File.exist?(cache_file)
41
+ end
42
+
43
+ def cache_key
44
+ Digest::SHA2.hexdigest("#{user}@#{host}")
45
+ end
46
+
47
+ def cache_file
48
+ File.expand_path(File.join(Fauxhai.root, "tmp", cache_key))
49
+ end
50
+
51
+ def force_cache_miss?
52
+ @force_cache_miss ||= @options.delete(:force_cache_miss) || false
53
+ end
54
+
55
+ # Return the given `@data` attribute as a Ruby hash instead of a JSON object
56
+ #
57
+ # @return [Hash] the `@data` represented as a Ruby hash
58
+ def to_hash(*args)
59
+ @data.to_hash(*args)
60
+ end
61
+
62
+ def to_s
63
+ "#<Fauxhai::Fetcher @host=#{host}, @options=#{@options}>"
64
+ end
65
+
66
+ private
67
+
68
+ def host
69
+ @host ||= begin
70
+ raise ArgumentError, ":host is a required option for Fauxhai.fetch" unless @options[:host]
71
+
72
+ @options.delete(:host)
73
+ end
74
+ end
75
+
76
+ def user
77
+ @user ||= (@options.delete(:user) || ENV["USER"] || ENV["USERNAME"]).chomp
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,12 @@
1
+ -----BEGIN DSA PRIVATE KEY-----
2
+ MIIBvAIBAAKBgQCRaPQSwMOFihLOYYIqZOZuNtxcwbA1wmUjHAvXGv6Jv9VWMzKi
3
+ JosRnt7iAg8zRVFsRaCyU0ADnHMs6OjF2YkKsFiQyxYuajkq+sNl3DMhPs3eMDsj
4
+ KA4lTOX4s5hvCtxc66rxo8AXB3AXTkJ2r0oo6I9/AzduSfc4a4neQWOFpQIVAPFe
5
+ sLIbnZcLOfcVXh6PfzAkGSiZAoGAaLxjyeJj9j+gSvJR5dDz25LcEG1paSdd6M+k
6
+ RCRQ1XFIu71dum1/wY0F/qIc2UM5Y3c9UqVGz3P/J7gOHWq2JFYfdXgYt9OxDfCH
7
+ cUR49ngYKf2RuMrISHmxt1h68CQ/8VI42dTEX8g09Xq5lYuC744z4Fg8S2Zz6TGk
8
+ ektZ84ECgYEAj0Vd6DCWslvlsZ8+N53HWsqPi3gnx35JoLPz9Z2epkKIKqmEHav+
9
+ 93G3hdfztVa4I4t3phoPniQchYryF5+RNg8hqxKzjNtrIqUYCeuf2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+ ijEsdBpk/wOw3PzhygVaTzJry/MYjk7xUzcOIRFr0dHfvrD5/tGecUfBt0gNaHTV
23
+ DUtyPItif+eIIkYySwdPGAZVLxaV3r2aQSrbl13hRoq3Ak09fyZpHMH/nMTYRWYU
24
+ 56GngscCgYB3/vF1j+fxoqjhecMuhxNB3KDxuj3kW6ZBFC1yI3tsiHU+cTDBzdlG
25
+ fANBAUvFxMyd7FV8DxRKsfv+YX4U3oET2SB5xxVyZZ5km+X4nWdzJdEXl2JNiBCr
26
+ yDsMDWkmavqDJTZkngJnQ43pwdEOZlv8ePLj453YcVGACziizDlsyw==
27
+ -----END RSA PRIVATE KEY-----
@@ -0,0 +1 @@
1
+ ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCtLCeqtqr/HbnORckw1ukdLhpfGoOPFi5/esKEokzTqq1gsgQ2V8emmyjfq1i6XXfRtSBxkdlHv/GWdP5wBTuE2G85MzBkVSQPvmwQN8lX/JMPEEtKXkeOo0o92/PiSmvY4eRsdF0mw40Uvg7jtE3f3fxj497kzh5fKtkrHnF4x9gXCbVdr3FqXJfggR5IJwAxToerbK7x/uRS+7YuZI9Pip3tt14nv9ezwXcuGb/tvjWOZINiFl8izVIFKi7sxfTX09p4NgamxRS7TD2Yd0jT8nEoF9UZTsgXcJ1kDSx7N7NxFfNfP6rCdOGRRz4gUhXtsUjG/XkxPeCwZ7A9VnOD fauxhai.local
@@ -0,0 +1,143 @@
1
+ require "json" unless defined?(JSON)
2
+ require "pathname" unless defined?(Pathname)
3
+
4
+ module Fauxhai
5
+ class Mocker
6
+ # The base URL for the GitHub project (raw)
7
+ RAW_BASE = "https://raw.githubusercontent.com/chefspec/fauxhai/master".freeze
8
+
9
+ # A message about where to find a list of platforms
10
+ PLATFORM_LIST_MESSAGE = "A list of available platforms is available at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md".freeze
11
+
12
+ # Create a new Ohai Mock with fauxhai.
13
+ #
14
+ # @param [Hash] options
15
+ # the options for the mocker
16
+ # @option options [String] :platform
17
+ # the platform to mock
18
+ # @option options [String] :version
19
+ # the version of the platform to mock
20
+ # @option options [String] :path
21
+ # the path to a local JSON file
22
+ # @option options [Bool] :github_fetching
23
+ # whether to try loading from Github
24
+ def initialize(options = {}, &override_attributes)
25
+ @options = { github_fetching: true }.merge(options)
26
+
27
+ yield(data) if block_given?
28
+ end
29
+
30
+ def data
31
+ @fauxhai_data ||= lambda do
32
+ # If a path option was specified, use it
33
+ if @options[:path]
34
+ filepath = File.expand_path(@options[:path])
35
+
36
+ unless File.exist?(filepath)
37
+ raise Fauxhai::Exception::InvalidPlatform.new("You specified a path to a JSON file on the local system that does not exist: '#{filepath}'")
38
+ end
39
+ else
40
+ filepath = File.join(platform_path, "#{version}.json")
41
+ end
42
+
43
+ if File.exist?(filepath)
44
+ parse_and_validate(File.read(filepath))
45
+ elsif @options[:github_fetching]
46
+ # Try loading from github (in case someone submitted a PR with a new file, but we haven't
47
+ # yet updated the gem version). Cache the response locally so it's faster next time.
48
+ require "open-uri" unless defined?(OpenURI)
49
+ begin
50
+ response = URI.open("#{RAW_BASE}/lib/fauxhai/platforms/#{platform}/#{version}.json")
51
+ rescue OpenURI::HTTPError
52
+ raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and an HTTP error was encountered when fetching from Github. #{PLATFORM_LIST_MESSAGE}")
53
+ end
54
+
55
+ if response.status.first.to_i == 200
56
+ response_body = response.read
57
+ path = Pathname.new(filepath)
58
+ FileUtils.mkdir_p(path.dirname)
59
+
60
+ begin
61
+ File.open(filepath, "w") { |f| f.write(response_body) }
62
+ rescue Errno::EACCES # a pretty common problem in CI systems
63
+ puts "Fetched '#{platform}/#{version}' from GitHub, but could not write to the local path: #{filepath}. Fix the local file permissions to avoid downloading this file every run."
64
+ end
65
+ return parse_and_validate(response_body)
66
+ else
67
+ raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and an Github fetching returned http error code #{response.status.first.to_i}! #{PLATFORM_LIST_MESSAGE}")
68
+ end
69
+ else
70
+ raise Fauxhai::Exception::InvalidPlatform.new("Could not find platform '#{platform}/#{version}' on the local disk and Github fetching is disabled! #{PLATFORM_LIST_MESSAGE}")
71
+ end
72
+ end.call
73
+ end
74
+
75
+ private
76
+
77
+ # As major releases of Ohai ship it's difficult and sometimes impossible
78
+ # to regenerate all fauxhai data. This allows us to deprecate old releases
79
+ # and eventually remove them while giving end users ample warning.
80
+ def parse_and_validate(unparsed_data)
81
+ parsed_data = JSON.parse(unparsed_data)
82
+ if parsed_data["deprecated"]
83
+ STDERR.puts "WARNING: Fauxhai platform data for #{parsed_data["platform"]} #{parsed_data["platform_version"]} is deprecated and will be removed in the 10.0 release 3/2022. #{PLATFORM_LIST_MESSAGE}"
84
+ end
85
+ parsed_data
86
+ end
87
+
88
+ def platform
89
+ @options[:platform] ||= begin
90
+ STDERR.puts "WARNING: you must specify a 'platform' and optionally a 'version' for your ChefSpec Runner and/or Fauxhai constructor, in the future omitting the platform will become a hard error. #{PLATFORM_LIST_MESSAGE}"
91
+ "chefspec"
92
+ end
93
+ end
94
+
95
+ def platform_path
96
+ File.join(Fauxhai.root, "lib", "fauxhai", "platforms", platform)
97
+ end
98
+
99
+ def version
100
+ @version ||= begin
101
+ if File.exist?("#{platform_path}/#{@options[:version]}.json")
102
+ # Whole version, use it as-is.
103
+ @options[:version]
104
+ else
105
+ # Check if it's a prefix of an existing version.
106
+ versions = Dir["#{platform_path}/*.json"].map { |path| File.basename(path, ".json") }
107
+ unless @options[:version].to_s == ""
108
+ # If the provided version is nil or '', that means take anything,
109
+ # otherwise run the prefix match with an extra \D to avoid the
110
+ # case where "7.1" matches "7.10.0".
111
+ prefix_re = /^#{Regexp.escape(@options[:version])}\D/
112
+ versions.select! { |ver| ver =~ prefix_re }
113
+ end
114
+
115
+ if versions.empty?
116
+ # No versions available, either an unknown platform or nothing matched
117
+ # the prefix check. Pass through the option as given so we can try
118
+ # github fetching.
119
+ @options[:version]
120
+ else
121
+ # Take the highest version available, trying to use rules that should
122
+ # probably mostly work on all OSes. Famous last words. The idea of
123
+ # the regex is to split on any punctuation (the common case) and
124
+ # also any single letter with digit on either side (2012r2). This
125
+ # leaves any long runs of letters intact (4.2-RELEASE). Then convert
126
+ # any run of digits to an integer to get version-ish comparison.
127
+ # This is basically a more flexible version of Gem::Version.
128
+ versions.max_by do |ver|
129
+ ver.split(/[^a-z0-9]|(?<=\d)[a-z](?=\d)/i).map do |part|
130
+ if part =~ /^\d+$/
131
+ part.to_i
132
+ else
133
+ part
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
140
+ end
141
+
142
+ end
143
+ end