dependency_checker 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6bed901c0dbb70764fd47f539afa0b03fd21d5699bf11bc9908237c5a54f0fe
4
- data.tar.gz: 4aa912822c6b2c9dd93e6f3030dfd742bf855c72d4965c013a8783db51b67af9
3
+ metadata.gz: ac8695cea83068ecec8de3b97952c34c2ee44adbd1a93ccfaea2d7435162dca6
4
+ data.tar.gz: c55c5de0e6737e3a16d3d458887653b8a421fb55b17c41decce893868ebe3e71
5
5
  SHA512:
6
- metadata.gz: 48781c78bd1a5c026932cf9ae19aa94648192913d78af50c54662f6e8df8d54ec88d4822a2dffcdab198c0b46b19058a1cb4471cd5a62726cac593fb201c1ae9
7
- data.tar.gz: 95675980e3ebe444b10059a95003903be9e76fbe605cbfd7d79d3482ff3c35354234f5d3102220f55c8503c100d8d87377daedc377385dae4acbead80fa2d8a5
6
+ metadata.gz: 11591af11e78c61a130e204a1f60267f62f115d14dbbf9c75a204cb4340fd149d97d87f54577e8805f7077c343b3fe8a62dab0f11cdbd3e471f73b8fab69ef93
7
+ data.tar.gz: 3cddb912ed15ade3b7a74befb00d444e95802d0048613c0ea9c6e1283ccf82a9844039634ddf7a035d06b5ea05b3f3abcc04ca78583b432ab5cb37aef72a4aa6
@@ -6,7 +6,7 @@ require 'dependency_checker'
6
6
  require 'json'
7
7
 
8
8
  options = {}
9
- OptionParser.new { |opts|
9
+ OptionParser.new do |opts|
10
10
  opts.on('-o module,version', '--override module,version', Array, 'Forge name of module and semantic version to override') do |override|
11
11
  options[:override] = override
12
12
  end
@@ -61,12 +61,10 @@ OptionParser.new { |opts|
61
61
  puts opts
62
62
  exit
63
63
  end
64
- }.parse!
64
+ end.parse!
65
65
 
66
66
  # Raise error if both :override and :current_override are specified
67
- if options[:override] && options[:current_override]
68
- raise OptionParser::InvalidOption, 'You can not select both override and current override options'
69
- end
67
+ raise OptionParser::InvalidOption, 'You can not select both override and current override options' if options[:override] && options[:current_override]
70
68
 
71
69
  # If :current_override is specified, retrieve name and version of module in current working directory
72
70
  if options[:current_override]
@@ -4,78 +4,78 @@ require 'puppet_forge'
4
4
  require 'semantic_puppet'
5
5
 
6
6
  # Helper class for fetching data from the Forge and perform some basic operations
7
- class DependencyChecker::ForgeHelper
8
- def initialize(cache = {}, forge_hostname = nil, forge_token = nil)
9
- @cache = cache
10
- PuppetForge.host = forge_hostname unless forge_hostname.nil?
11
- PuppetForge::Connection.authorization = forge_token unless forge_token.nil?
12
- end
7
+ module DependencyChecker
8
+ class ForgeHelper
9
+ def initialize(cache = {}, forge_hostname = nil, forge_token = nil)
10
+ @cache = cache
11
+ PuppetForge.host = forge_hostname unless forge_hostname.nil?
12
+ PuppetForge::Connection.authorization = forge_token unless forge_token.nil?
13
+ end
13
14
 
14
- # Retrieve current version of module
15
- # @return [SemanticPuppet::Version]
16
- def get_current_version(module_name)
17
- module_name = module_name.sub('/', '-')
18
- version = nil
19
- version = get_version(@cache[module_name]) if @cache.key?(module_name)
15
+ # Retrieve current version of module
16
+ # @return [SemanticPuppet::Version]
17
+ def get_current_version(module_name)
18
+ module_name = module_name.sub('/', '-')
19
+ version = nil
20
+ version = get_version(@cache[module_name]) if @cache.key?(module_name)
20
21
 
21
- if !version && check_module_exists(module_name)
22
- version = get_version(get_module_data(module_name))
22
+ version = get_version(get_module_data(module_name)) if !version && check_module_exists(module_name)
23
+
24
+ version
23
25
  end
24
26
 
25
- version
26
- end
27
+ # Retrieve module data from Forge
28
+ # @return [Hash] Hash containing JSON response from Forge
29
+ def get_module_data(module_name)
30
+ module_name = module_name.sub('/', '-')
31
+ module_data = @cache[module_name]
32
+ begin
33
+ @cache[module_name] = module_data = PuppetForge::Module.find(module_name) unless module_data
34
+ rescue Faraday::ClientError
35
+ return nil
36
+ end
27
37
 
28
- # Retrieve module data from Forge
29
- # @return [Hash] Hash containing JSON response from Forge
30
- def get_module_data(module_name)
31
- module_name = module_name.sub('/', '-')
32
- module_data = @cache[module_name]
33
- begin
34
- @cache[module_name] = module_data = PuppetForge::Module.find(module_name) unless module_data
35
- rescue Faraday::ClientError
36
- return nil
38
+ module_data
37
39
  end
38
40
 
39
- module_data
40
- end
41
-
42
- # Retrieve module from Forge
43
- # @return [PuppetForge::Module]
44
- def check_module_exists(module_name)
45
- !get_module_data(module_name).nil?
46
- end
41
+ # Retrieve module from Forge
42
+ # @return [PuppetForge::Module]
43
+ def check_module_exists(module_name)
44
+ !get_module_data(module_name).nil?
45
+ end
47
46
 
48
- # Check if a module is deprecated from data fetched from the Forge
49
- # @return [Boolean] boolean result stating whether module is deprecated
50
- def check_module_deprecated(module_name)
51
- module_name = module_name.sub('/', '-')
52
- module_data = get_module_data(module_name)
53
- version = get_current_version(module_name)
54
- version.to_s.eql?('999.999.999') || version.to_s.eql?('99.99.99') || !module_data.attribute('deprecated_at').nil?
55
- end
47
+ # Check if a module is deprecated from data fetched from the Forge
48
+ # @return [Boolean] boolean result stating whether module is deprecated
49
+ def check_module_deprecated(module_name)
50
+ module_name = module_name.sub('/', '-')
51
+ module_data = get_module_data(module_name)
52
+ version = get_current_version(module_name)
53
+ version.to_s.eql?('999.999.999') || version.to_s.eql?('99.99.99') || !module_data.attribute('deprecated_at').nil?
54
+ end
56
55
 
57
- # Gets a list of all modules in a namespace, optionally filtered by endorsement.
58
- # @param [String] namespace The namespace to search
59
- # @param [String] endorsement to filter by (supported/approved/partner)
60
- # @return [Array] list of modules
61
- def modules_in_namespace(namespace, endorsement = nil)
62
- modules = PuppetForge::Module.where(
63
- :owner => namespace, # rubocop:disable Layout/FirstArgumentIndentation
64
- :hide_deprecated => true,
65
- :module_groups => 'base pe_only',
66
- :endorsements => endorsement,
67
- )
56
+ # Gets a list of all modules in a namespace, optionally filtered by endorsement.
57
+ # @param [String] namespace The namespace to search
58
+ # @param [String] endorsement to filter by (supported/approved/partner)
59
+ # @return [Array] list of modules
60
+ def modules_in_namespace(namespace, endorsement = nil)
61
+ modules = PuppetForge::Module.where(
62
+ owner: namespace, # rubocop:disable Layout/FirstArgumentIndentation
63
+ hide_deprecated: true,
64
+ module_groups: 'base pe_only',
65
+ endorsements: endorsement
66
+ )
68
67
 
69
- raise "No modules found for #{namespace}." if modules.total.zero?
68
+ raise "No modules found for #{namespace}." if modules.total.zero?
70
69
 
71
- modules.unpaginated.map { |m| m.slug }
72
- end
70
+ modules.unpaginated.map(&:slug)
71
+ end
73
72
 
74
- private
73
+ private
75
74
 
76
- def get_version(module_data)
77
- return SemanticPuppet::Version.parse('999.999.999') unless module_data.current_release
75
+ def get_version(module_data)
76
+ return SemanticPuppet::Version.parse('999.999.999') unless module_data.current_release
78
77
 
79
- SemanticPuppet::Version.parse(module_data.current_release.version)
78
+ SemanticPuppet::Version.parse(module_data.current_release.version)
79
+ end
80
80
  end
81
81
  end
@@ -3,35 +3,37 @@
3
3
  require 'semantic_puppet'
4
4
 
5
5
  # Checks dependencies of passed in metadata and performs checks to verify constraints
6
- class DependencyChecker::MetadataChecker
7
- def initialize(metadata, forge, updated_module, updated_module_version)
8
- @metadata = metadata
9
- @forge = forge
10
- @updated_module = updated_module.sub('-', '/') if updated_module
11
- @updated_module_version = updated_module_version if updated_module_version
12
- end
6
+ module DependencyChecker
7
+ class MetadataChecker
8
+ def initialize(metadata, forge, updated_module, updated_module_version)
9
+ @metadata = metadata
10
+ @forge = forge
11
+ @updated_module = updated_module.sub('-', '/') if updated_module
12
+ @updated_module_version = updated_module_version if updated_module_version
13
+ end
13
14
 
14
- # Perform constraint comparisons of dependencies based on their latest version, and also
15
- # override any occurance of @updated_module with @updated_module_version
16
- # @return [Map] a map of dependencies along with their constraint, current version and whether they satisfy the constraint
17
- def check_dependencies
18
- fetch_module_dependencies.map do |dependency, constraint|
19
- dependency = dependency.sub('-', '/')
20
- current = (dependency == @updated_module) ? SemanticPuppet::Version.parse(@updated_module_version) : @forge.get_current_version(dependency)
21
- [dependency, constraint, current, constraint.include?(current)]
15
+ # Perform constraint comparisons of dependencies based on their latest version, and also
16
+ # override any occurance of @updated_module with @updated_module_version
17
+ # @return [Map] a map of dependencies along with their constraint, current version and whether they satisfy the constraint
18
+ def check_dependencies
19
+ fetch_module_dependencies.map do |dependency, constraint|
20
+ dependency = dependency.sub('-', '/')
21
+ current = dependency == @updated_module ? SemanticPuppet::Version.parse(@updated_module_version) : @forge.get_current_version(dependency)
22
+ [dependency, constraint, current, constraint.include?(current)]
23
+ end
22
24
  end
23
- end
24
25
 
25
- private
26
+ private
26
27
 
27
- # Retrieve dependencies from @metedata
28
- # @return [Map] a map with the name of the dependency and its constraint
29
- def fetch_module_dependencies
30
- return [] unless @metadata[:dependencies]
28
+ # Retrieve dependencies from @metedata
29
+ # @return [Map] a map with the name of the dependency and its constraint
30
+ def fetch_module_dependencies
31
+ return [] unless @metadata[:dependencies]
31
32
 
32
- @metadata[:dependencies].map do |dep|
33
- constraint = dep[:version_requirement] || '>= 0'
34
- [dep[:name], SemanticPuppet::VersionRange.parse(constraint)]
33
+ @metadata[:dependencies].map do |dep|
34
+ constraint = dep[:version_requirement] || '>= 0'
35
+ [dep[:name], SemanticPuppet::VersionRange.parse(constraint)]
36
+ end
35
37
  end
36
38
  end
37
39
  end
@@ -7,191 +7,193 @@ require 'logger'
7
7
  require 'parallel'
8
8
 
9
9
  # Main runner for DependencyChecker
10
- class DependencyChecker::Runner
11
- attr_reader :problems
10
+ module DependencyChecker
11
+ class Runner
12
+ attr_reader :problems
12
13
 
13
- def initialize(verbose = false, forge_hostname = nil, forge_token = nil)
14
- @forge = DependencyChecker::ForgeHelper.new({}, forge_hostname, forge_token)
15
- @verbose = verbose
16
- end
14
+ def initialize(verbose = false, forge_hostname = nil, forge_token = nil)
15
+ @forge = DependencyChecker::ForgeHelper.new({}, forge_hostname, forge_token)
16
+ @verbose = verbose
17
+ end
17
18
 
18
- def resolve_from_namespace(namespace, endorsement)
19
- @modules = @forge.modules_in_namespace(namespace, endorsement)
20
- end
19
+ def resolve_from_namespace(namespace, endorsement)
20
+ @modules = @forge.modules_in_namespace(namespace, endorsement)
21
+ end
21
22
 
22
- def resolve_from_path(path)
23
- @modules = return_modules(path)
24
- end
23
+ def resolve_from_path(path)
24
+ @modules = return_modules(path)
25
+ end
25
26
 
26
- def resolve_from_files(metadata_files)
27
- @use_local_files = true
28
- @modules = Array(metadata_files) # should already be an array, but just in case
29
- end
27
+ def resolve_from_files(metadata_files)
28
+ @use_local_files = true
29
+ @modules = Array(metadata_files) # should already be an array, but just in case
30
+ end
30
31
 
31
- def override=(override)
32
- return unless override.is_a? Array
32
+ def override=(override)
33
+ return unless override.is_a? Array
33
34
 
34
- @updated_module, @updated_module_version = override
35
+ @updated_module, @updated_module_version = override
35
36
 
36
- raise '*Error:* Pass an override in the form `--override module,version`' unless override.size == 2
37
- raise "*Error:* Could not find *#{@updated_module}* on Puppet Forge! Ensure updated_module argument is valid." unless check_module_exists(@updated_module)
38
- raise "*Error:* Verify semantic versioning syntax *#{@updated_module_version}* of updated_module_version argument." unless SemanticPuppet::Version.valid?(@updated_module_version)
37
+ raise '*Error:* Pass an override in the form `--override module,version`' unless override.size == 2
38
+ raise "*Error:* Could not find *#{@updated_module}* on Puppet Forge! Ensure updated_module argument is valid." unless check_module_exists(@updated_module)
39
+ unless SemanticPuppet::Version.valid?(@updated_module_version)
40
+ raise "*Error:* Verify semantic versioning syntax *#{@updated_module_version}* of updated_module_version argument."
41
+ end
39
42
 
40
- puts "Overriding *#{@updated_module}* version with *#{@updated_module_version}*\n\n"
41
- puts "The module you are comparing against *#{@updated_module}* is *deprecated*.\n\n" if @forge.check_module_deprecated(@updated_module)
42
- end
43
+ puts "Overriding *#{@updated_module}* version with *#{@updated_module_version}*\n\n"
44
+ puts "The module you are comparing against *#{@updated_module}* is *deprecated*.\n\n" if @forge.check_module_deprecated(@updated_module)
45
+ end
43
46
 
44
- def run
45
- puts "_*Starting dependency checks...*_\n\n"
47
+ def run
48
+ puts "_*Starting dependency checks...*_\n\n"
46
49
 
47
- # Post results of dependency checks
48
- message = run_dependency_checks
49
- @problems = message.size
50
- message = 'All modules have valid dependencies.' if message.empty?
50
+ # Post results of dependency checks
51
+ message = run_dependency_checks
52
+ @problems = message.size
53
+ message = 'All modules have valid dependencies.' if message.empty?
51
54
 
52
- post(message)
53
- end
55
+ post(message)
56
+ end
54
57
 
55
- # Check with forge if a specified module exists
56
- # @param module_name [String]
57
- # @return [Boolean] boolean based on whether the module exists or not
58
- def check_module_exists(module_name)
59
- @forge.check_module_exists(module_name)
60
- end
58
+ # Check with forge if a specified module exists
59
+ # @param module_name [String]
60
+ # @return [Boolean] boolean based on whether the module exists or not
61
+ def check_module_exists(module_name)
62
+ @forge.check_module_exists(module_name)
63
+ end
61
64
 
62
- # Perform dependency checks on modules supplied by @modules
63
- def run_dependency_checks
64
- # Cross reference dependencies from managed_modules file with @updated_module and @updated_module_version
65
- messages = Parallel.map(@modules) do |module_path|
66
- module_name = @use_local_files ? get_name_from_metadata(module_path) : module_path
67
- mod_message = "Checking *#{module_path}* dependencies.\n"
68
- exists_on_forge = true
69
-
70
- # Check module_path is valid
71
- unless check_module_exists(module_name)
72
- if @use_local_files
73
- exists_on_forge = false
74
- else
75
- mod_message += "\t*Error:* Could not find *#{module_name}* on Puppet Forge! Ensure the module exists.\n\n"
76
- next mod_message
65
+ # Perform dependency checks on modules supplied by @modules
66
+ def run_dependency_checks
67
+ # Cross reference dependencies from managed_modules file with @updated_module and @updated_module_version
68
+ messages = Parallel.map(@modules) do |module_path|
69
+ module_name = @use_local_files ? get_name_from_metadata(module_path) : module_path
70
+ mod_message = "Checking *#{module_path}* dependencies.\n"
71
+ exists_on_forge = true
72
+
73
+ # Check module_path is valid
74
+ unless check_module_exists(module_name)
75
+ if @use_local_files
76
+ exists_on_forge = false
77
+ else
78
+ mod_message += "\t*Error:* Could not find *#{module_name}* on Puppet Forge! Ensure the module exists.\n\n"
79
+ next mod_message
80
+ end
77
81
  end
78
- end
79
-
80
- # Fetch module dependencies
81
82
 
82
- dependencies = @use_local_files ? get_dependencies_from_path(module_path) : get_dependencies(module_name)
83
+ # Fetch module dependencies
83
84
 
84
- # Post warning if module_path is deprecated
85
- mod_deprecated = exists_on_forge ? @forge.check_module_deprecated(module_name) : false
86
- mod_message += "\t*Warning:* *#{module_name}* is *deprecated*.\n" if mod_deprecated
85
+ dependencies = @use_local_files ? get_dependencies_from_path(module_path) : get_dependencies(module_name)
87
86
 
88
- if dependencies.empty?
89
- mod_message += "\tNo dependencies listed\n\n"
90
- next mod_message if @verbose && !mod_deprecated
91
- end
87
+ # Post warning if module_path is deprecated
88
+ mod_deprecated = exists_on_forge ? @forge.check_module_deprecated(module_name) : false
89
+ mod_message += "\t*Warning:* *#{module_name}* is *deprecated*.\n" if mod_deprecated
92
90
 
93
- # Check each dependency to see if the latest version matchs the current modules' dependency constraints
94
- all_match = true
95
- dependencies.each do |dependency, constraint, current, satisfied|
96
- if satisfied && @verbose
97
- mod_message += "\t#{dependency} (#{constraint}) *matches* #{current}\n"
98
- elsif !satisfied
99
- all_match = false
100
- mod_message += "\t#{dependency} (#{constraint}) *doesn't match* #{current}\n"
91
+ if dependencies.empty?
92
+ mod_message += "\tNo dependencies listed\n\n"
93
+ next mod_message if @verbose && !mod_deprecated
101
94
  end
102
95
 
103
- if @forge.check_module_deprecated(dependency)
104
- all_match = false
105
- mod_message += "\t\t*Warning:* *#{dependency}* is *deprecated*.\n"
96
+ # Check each dependency to see if the latest version matchs the current modules' dependency constraints
97
+ all_match = true
98
+ dependencies.each do |dependency, constraint, current, satisfied|
99
+ if satisfied && @verbose
100
+ mod_message += "\t#{dependency} (#{constraint}) *matches* #{current}\n"
101
+ elsif !satisfied
102
+ all_match = false
103
+ mod_message += "\t#{dependency} (#{constraint}) *doesn't match* #{current}\n"
104
+ end
105
+
106
+ if @forge.check_module_deprecated(dependency)
107
+ all_match = false
108
+ mod_message += "\t\t*Warning:* *#{dependency}* is *deprecated*.\n"
109
+ end
110
+
111
+ found_deprecation = true if @forge.check_module_deprecated(dependency)
112
+
113
+ # Post warning if dependency is deprecated
114
+ mod_message += "\tThe dependency module *#{dependency}* is *deprecated*.\n" if found_deprecation
106
115
  end
107
116
 
108
- found_deprecation = true if @forge.check_module_deprecated(dependency)
117
+ mod_message += "\tAll dependencies match\n" if all_match
118
+ mod_message += "\n"
109
119
 
110
- # Post warning if dependency is deprecated
111
- mod_message += "\tThe dependency module *#{dependency}* is *deprecated*.\n" if found_deprecation
120
+ # If @verbose is true, always post message
121
+ # If @verbose is false, only post if all dependencies don't match and/or if a dependency is deprecated
122
+ all_match && !@verbose ? '' : mod_message
112
123
  end
113
124
 
114
- mod_message += "\tAll dependencies match\n" if all_match
115
- mod_message += "\n"
125
+ message = ''
126
+ messages.each do |result|
127
+ message += result
128
+ end
116
129
 
117
- # If @verbose is true, always post message
118
- # If @verbose is false, only post if all dependencies don't match and/or if a dependency is deprecated
119
- (all_match && !@verbose) ? '' : mod_message
130
+ message
120
131
  end
121
132
 
122
- message = ''
123
- messages.each do |result|
124
- message += result
133
+ # Get dependencies of a supplied module name to verify if the depedencies are satisfied
134
+ # @param module_name [String] name of module
135
+ # @return [Map] a map of dependencies along with their constraint, current version and whether they satisfy the constraint
136
+ def get_dependencies(module_name)
137
+ module_data = @forge.get_module_data(module_name)
138
+ metadata = module_data.current_release.metadata
139
+ get_dependencies_from_metadata(metadata)
125
140
  end
126
141
 
127
- message
128
- end
142
+ # Get dependencies of a supplied module from a metadata.json file to verify if the depedencies are satisfied
143
+ # @param metadata_path [String] path to metadata.json
144
+ # @return [Map] a map of dependencies along with their constraint, current version and whether they satisfy the constraint
145
+ def get_dependencies_from_path(metadata_path)
146
+ metadata = JSON.parse(File.read(metadata_path), symbolize_names: true)
147
+ get_dependencies_from_metadata(metadata)
148
+ end
129
149
 
130
- # Get dependencies of a supplied module name to verify if the depedencies are satisfied
131
- # @param module_name [String] name of module
132
- # @return [Map] a map of dependencies along with their constraint, current version and whether they satisfy the constraint
133
- def get_dependencies(module_name)
134
- module_data = @forge.get_module_data(module_name)
135
- metadata = module_data.current_release.metadata
136
- get_dependencies_from_metadata(metadata)
137
- end
150
+ # Get dependencies of supplied module metadata. Takes module ovveride into account.
151
+ # @param metadata [Hash] module metadata
152
+ # @return [Map] a map of dependencies along with their constraint, current version and whether they satisfy the constraint
153
+ def get_dependencies_from_metadata(metadata)
154
+ checker = DependencyChecker::MetadataChecker.new(metadata, @forge, @updated_module, @updated_module_version)
155
+ checker.check_dependencies
156
+ end
138
157
 
139
- # Get dependencies of a supplied module from a metadata.json file to verify if the depedencies are satisfied
140
- # @param metadata_path [String] path to metadata.json
141
- # @return [Map] a map of dependencies along with their constraint, current version and whether they satisfy the constraint
142
- def get_dependencies_from_path(metadata_path)
143
- metadata = JSON.parse(File.read(metadata_path), symbolize_names: true)
144
- get_dependencies_from_metadata(metadata)
145
- end
158
+ # Get dependencies of a supplied module from a metadata.json file to verify if the depedencies are satisfied
159
+ # @param metadata_path [String] path to metadata.json
160
+ # @return [Map] a map of dependencies along with their constraint, current version and whether they satisfy the constraint
161
+ def get_name_from_metadata(metadata_path)
162
+ metadata = JSON.parse(File.read(metadata_path), symbolize_names: true)
163
+ metadata[:name]
164
+ end
146
165
 
147
- # Get dependencies of supplied module metadata. Takes module ovveride into account.
148
- # @param metadata [Hash] module metadata
149
- # @return [Map] a map of dependencies along with their constraint, current version and whether they satisfy the constraint
150
- def get_dependencies_from_metadata(metadata)
151
- checker = DependencyChecker::MetadataChecker.new(metadata, @forge, @updated_module, @updated_module_version)
152
- checker.check_dependencies
153
- end
166
+ # Retrieve the array of module names from the supplied filename/URL
167
+ # @return [Array] an array of module names
168
+ def return_modules(path)
169
+ begin
170
+ # We use URI#open because it can handle file or URI paths.
171
+ # This usage does not expose a security risk
172
+ contents = URI.open(path).read # rubocop:disable Security/Open
173
+ rescue Errno::ENOENT, SocketError
174
+ raise "*Error:* Ensure *#{path}* is a valid file path or URL"
175
+ end
154
176
 
155
- # Get dependencies of a supplied module from a metadata.json file to verify if the depedencies are satisfied
156
- # @param metadata_path [String] path to metadata.json
157
- # @return [Map] a map of dependencies along with their constraint, current version and whether they satisfy the constraint
158
- def get_name_from_metadata(metadata_path)
159
- metadata = JSON.parse(File.read(metadata_path), symbolize_names: true)
160
- metadata[:name]
161
- end
177
+ begin
178
+ modules = if path.end_with? '.json'
179
+ JSON.parse(contents)
180
+ else
181
+ YAML.safe_load(contents)
182
+ end
183
+ rescue StandardError
184
+ raise "*Error:* Ensure syntax of #{path} file is valid YAML or JSON"
185
+ end
162
186
 
163
- # Retrieve the array of module names from the supplied filename/URL
164
- # @return [Array] an array of module names
165
- def return_modules(path)
166
- begin
167
- # We use Kernel#open because it can handle file or URI paths.
168
- # This usage does not expose a security risk
169
- contents = open(path).read # rubocop:disable Security/Open
170
- rescue Errno::ENOENT, SocketError
171
- raise "*Error:* Ensure *#{path}* is a valid file path or URL"
172
- end
187
+ # transform from IAC supported module hash to simple list
188
+ modules = modules.filter_map { |_key, val| val['puppet_module'] } if modules.is_a? Hash
173
189
 
174
- begin
175
- if path.end_with? '.json'
176
- modules = JSON.parse(contents)
177
- else
178
- modules = YAML.safe_load(contents)
179
- end
180
- rescue StandardError
181
- raise "*Error:* Ensure syntax of #{path} file is valid YAML or JSON"
190
+ modules
182
191
  end
183
192
 
184
- # transform from IAC supported module hash to simple list
185
- if modules.is_a? Hash
186
- modules = modules.map { |_key, val| val['puppet_module'] }.compact
193
+ # Post message to terminal
194
+ # @param message [String]
195
+ def post(message)
196
+ puts message
187
197
  end
188
-
189
- modules
190
- end
191
-
192
- # Post message to terminal
193
- # @param message [String]
194
- def post(message)
195
- puts message
196
198
  end
197
199
  end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module DependencyChecker
4
+ VERSION = '1.0.0'
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependency_checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ewoud Kohl van Wijngaarden
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-12-15 00:00:00.000000000 Z
12
+ date: 2023-04-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: parallel
@@ -73,90 +73,6 @@ dependencies:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.0'
76
- - !ruby/object:Gem::Dependency
77
- name: codecov
78
- requirement: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- type: :development
84
- prerelease: false
85
- version_requirements: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- - !ruby/object:Gem::Dependency
91
- name: github_changelog_generator
92
- requirement: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.15'
97
- type: :development
98
- prerelease: false
99
- version_requirements: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '1.15'
104
- - !ruby/object:Gem::Dependency
105
- name: rspec
106
- requirement: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '3.9'
111
- type: :development
112
- prerelease: false
113
- version_requirements: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '3.9'
118
- - !ruby/object:Gem::Dependency
119
- name: rubocop
120
- requirement: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- type: :development
126
- prerelease: false
127
- version_requirements: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - ">="
130
- - !ruby/object:Gem::Version
131
- version: '0'
132
- - !ruby/object:Gem::Dependency
133
- name: simplecov-console
134
- requirement: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - ">="
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- type: :development
140
- prerelease: false
141
- version_requirements: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- - !ruby/object:Gem::Dependency
147
- name: simplecov
148
- requirement: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- type: :development
154
- prerelease: false
155
- version_requirements: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
76
  description: |2
161
77
  Verify all your dependencies allow the latest versions on Puppet Forge.
162
78
  Based on https://github.com/ekohl/metadata_json_deps
@@ -174,6 +90,7 @@ files:
174
90
  - lib/dependency_checker/forge_helper.rb
175
91
  - lib/dependency_checker/metadata_checker.rb
176
92
  - lib/dependency_checker/runner.rb
93
+ - lib/dependency_checker/version.rb
177
94
  homepage: https://github.com/puppetlabs/dependency_checker
178
95
  licenses:
179
96
  - MIT
@@ -187,14 +104,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
187
104
  requirements:
188
105
  - - ">="
189
106
  - !ruby/object:Gem::Version
190
- version: 2.4.0
107
+ version: 2.7.0
191
108
  required_rubygems_version: !ruby/object:Gem::Requirement
192
109
  requirements:
193
110
  - - ">="
194
111
  - !ruby/object:Gem::Version
195
112
  version: '0'
196
113
  requirements: []
197
- rubygems_version: 3.0.3
114
+ rubygems_version: 3.1.6
198
115
  signing_key:
199
116
  specification_version: 4
200
117
  summary: Check your Puppet metadata dependencies